generated tests fail on empty responses
hanzki opened this issue · 1 comments
hanzki commented
If the test case expects a empty response the parsing seems to fail.
here's a snippet from my swagger file:
swagger: '2.0'
info:
version: "0.0.0"
title: Pets
produces:
- application/json
consumes:
- application/json
paths:
/pets/{id}:
get:
description: get existing `Pet` object
parameters:
-
name: id
in: path
description: pet id
required: true
type: string
format: uuid
responses:
200:
description: Successful response
schema:
$ref: '#/definitions/Pet'
404:
description: Pet not found
definitions:
Pet:
type: object
properties:
id:
type: string
format: uuid
name:
type: string
minLength: 1
required:
- name
here's relevant part of the controller:
val getpetsById = getpetsByIdAction { (id: UUID) =>
// ----- Start of unmanaged code area for action PetYaml.getpetsById
val pets = ...
pets.find(_.id.contains(id)) match {
case Some(p) => GetpetsById200(p)
case None => GetpetsById404()
}
// ----- End of unmanaged code area for action PetYaml.getpetsById
}
Because the generated tests test a random id it always gets the 404 response. If I haven't specified a schema for that response the response parsing fails and so does the test. This can be fixed by defining an object for the 404 response.
running tests produces:
[info] GET /pets/{id}
[info] - should discard invalid data
[info] - should do something with valid data *** FAILED ***
[info] Expected true but got false
[info] Successful
[info] Given response code [404], 'Content-Type' [application/json], 'Accept' header [application/json] and URL: [/pets/824d361c-7bad-494c-9a1b-42df21811fe5] given args: '824d361c-7bad-494c-9a1b-42df21811fe5' did not equal (pet.yaml.scala:571)
I think the generated tests should handle also empty responses gracefully.
slavaschmidt commented
Fixed in 0.2