Skip to content

Commit

Permalink
Add basic tests of json and yaml reading.
Browse files Browse the repository at this point in the history
  • Loading branch information
timburks committed Nov 25, 2016
1 parent 40a69a3 commit f9579e1
Show file tree
Hide file tree
Showing 2 changed files with 267 additions and 0 deletions.
38 changes: 38 additions & 0 deletions compiler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"os/exec"
"testing"
)

func TestPetstoreJSON(t *testing.T) {
var err error
err = exec.Command("rm", "petstore.text").Run()
if err != nil {
panic(err)
}
err = exec.Command("./openapi-compiler", "-input", "examples/petstore.json", "-text").Run()
if err != nil {
panic(err)
}
err = exec.Command("diff", "petstore.text", "test/petstore.text").Run()
if err != nil {
panic(err)
}
}

func TestPetstoreYAML(t *testing.T) {
var err error
err = exec.Command("rm", "petstore.text").Run()
if err != nil {
panic(err)
}
err = exec.Command("./openapi-compiler", "-input", "examples/petstore.yaml", "-text").Run()
if err != nil {
panic(err)
}
err = exec.Command("diff", "petstore.text", "test/petstore.text").Run()
if err != nil {
panic(err)
}
}
229 changes: 229 additions & 0 deletions test/petstore.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
swagger: "2.0"
info: <
title: "Swagger Petstore"
version: "1.0.0"
license: <
name: "MIT"
>
>
host: "petstore.swagger.io"
base_path: "/v1"
schemes: "http"
consumes: "application/json"
produces: "application/json"
paths: <
path: <
name: "/pets"
value: <
get: <
tags: "pets"
summary: "List all pets"
operation_id: "listPets"
parameters: <
parameter: <
non_body_parameter: <
path_parameter_sub_schema: <
in: "query"
description: "How many items to return at one time (max 100)"
name: "limit"
type: "integer"
format: "int32"
>
>
>
>
responses: <
response_code: <
name: "200"
value: <
response: <
description: "An paged array of pets"
schema: <
schema: <
_ref: "#/definitions/Pets"
>
>
headers: <
additional_properties: <
name: "x-next"
value: <
type: "string"
description: "A link to the next page of responses"
>
>
>
>
>
>
response_code: <
name: "default"
value: <
response: <
description: "unexpected error"
schema: <
schema: <
_ref: "#/definitions/Error"
>
>
>
>
>
>
>
post: <
tags: "pets"
summary: "Create a pet"
operation_id: "createPets"
responses: <
response_code: <
name: "201"
value: <
response: <
description: "Null response"
>
>
>
response_code: <
name: "default"
value: <
response: <
description: "unexpected error"
schema: <
schema: <
_ref: "#/definitions/Error"
>
>
>
>
>
>
>
>
>
path: <
name: "/pets/{petId}"
value: <
get: <
tags: "pets"
summary: "Info for a specific pet"
operation_id: "showPetById"
parameters: <
parameter: <
non_body_parameter: <
path_parameter_sub_schema: <
required: true
in: "path"
description: "The id of the pet to retrieve"
name: "petId"
type: "string"
>
>
>
>
responses: <
response_code: <
name: "200"
value: <
response: <
description: "Expected response to a valid request"
schema: <
schema: <
_ref: "#/definitions/Pets"
>
>
>
>
>
response_code: <
name: "default"
value: <
response: <
description: "unexpected error"
schema: <
schema: <
_ref: "#/definitions/Error"
>
>
>
>
>
>
>
>
>
>
definitions: <
additional_properties: <
name: "Pet"
value: <
required: "id"
required: "name"
properties: <
additional_properties: <
name: "id"
value: <
format: "int64"
type: <
value: "integer"
>
>
>
additional_properties: <
name: "name"
value: <
type: <
value: "string"
>
>
>
additional_properties: <
name: "tag"
value: <
type: <
value: "string"
>
>
>
>
>
>
additional_properties: <
name: "Pets"
value: <
type: <
value: "array"
>
items: <
schema: <
_ref: "#/definitions/Pet"
>
>
>
>
additional_properties: <
name: "Error"
value: <
required: "code"
required: "message"
properties: <
additional_properties: <
name: "code"
value: <
format: "int32"
type: <
value: "integer"
>
>
>
additional_properties: <
name: "message"
value: <
type: <
value: "string"
>
>
>
>
>
>
>

0 comments on commit f9579e1

Please sign in to comment.