mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 20:47:44 +00:00
chore: add more test coverage
This commit is contained in:
@@ -24,22 +24,22 @@ const (
|
||||
)
|
||||
|
||||
func TestSpecInfo_GetJSONParsingChannel(t *testing.T) {
|
||||
|
||||
// dumb, but we need to ensure coverage is as high as we can make it.
|
||||
bchan := make(chan bool)
|
||||
si := &SpecInfo{JsonParsingChannel: bchan}
|
||||
assert.Equal(t, si.GetJSONParsingChannel(), bchan)
|
||||
|
||||
}
|
||||
|
||||
var goodJSON = `{"name":"kitty", "noises":["meow","purrrr","gggrrraaaaaooooww"]}`
|
||||
var badJSON = `{"name":"kitty, "noises":[{"meow","purrrr","gggrrraaaaaooooww"]}}`
|
||||
var goodYAML = `name: kitty
|
||||
var (
|
||||
goodJSON = `{"name":"kitty", "noises":["meow","purrrr","gggrrraaaaaooooww"]}`
|
||||
badJSON = `{"name":"kitty, "noises":[{"meow","purrrr","gggrrraaaaaooooww"]}}`
|
||||
goodYAML = `name: kitty
|
||||
noises:
|
||||
- meow
|
||||
- purrr
|
||||
- gggggrrraaaaaaaaaooooooowwwwwww
|
||||
`
|
||||
)
|
||||
|
||||
var badYAML = `name: kitty
|
||||
noises:
|
||||
@@ -149,7 +149,6 @@ func TestExtractSpecInfo_InvalidOpenAPIVersion(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractSpecInfo_OpenAPI3(t *testing.T) {
|
||||
|
||||
r, e := ExtractSpecInfo([]byte(OpenApi3Spec))
|
||||
<-r.JsonParsingChannel
|
||||
assert.Nil(t, e)
|
||||
@@ -160,7 +159,6 @@ func TestExtractSpecInfo_OpenAPI3(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractSpecInfo_OpenAPIWat(t *testing.T) {
|
||||
|
||||
r, e := ExtractSpecInfo([]byte(OpenApiWat))
|
||||
<-r.JsonParsingChannel
|
||||
assert.Nil(t, e)
|
||||
@@ -169,7 +167,6 @@ func TestExtractSpecInfo_OpenAPIWat(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractSpecInfo_OpenAPI31(t *testing.T) {
|
||||
|
||||
r, e := ExtractSpecInfo([]byte(OpenApi31))
|
||||
<-r.JsonParsingChannel
|
||||
assert.Nil(t, e)
|
||||
@@ -179,7 +176,6 @@ func TestExtractSpecInfo_OpenAPI31(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractSpecInfo_AnyDocument(t *testing.T) {
|
||||
|
||||
random := `something: yeah
|
||||
nothing:
|
||||
- one
|
||||
@@ -195,8 +191,22 @@ why:
|
||||
assert.Len(t, *r.SpecBytes, 55)
|
||||
}
|
||||
|
||||
func TestExtractSpecInfo_AnyDocument_JSON(t *testing.T) {
|
||||
func TestExtractSpecInfo_AnyDocument_Sync(t *testing.T) {
|
||||
random := `something: yeah
|
||||
nothing:
|
||||
- one
|
||||
- two
|
||||
why:
|
||||
yes: no`
|
||||
|
||||
r, e := ExtractSpecInfoWithDocumentCheckSync([]byte(random), true)
|
||||
assert.Nil(t, e)
|
||||
assert.NotNil(t, r.RootNode)
|
||||
assert.Equal(t, "something", r.RootNode.Content[0].Content[0].Value)
|
||||
assert.Len(t, *r.SpecBytes, 55)
|
||||
}
|
||||
|
||||
func TestExtractSpecInfo_AnyDocument_JSON(t *testing.T) {
|
||||
random := `{ "something" : "yeah"}`
|
||||
|
||||
r, e := ExtractSpecInfoWithDocumentCheck([]byte(random), true)
|
||||
@@ -208,7 +218,6 @@ func TestExtractSpecInfo_AnyDocument_JSON(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractSpecInfo_AnyDocumentFromConfig(t *testing.T) {
|
||||
|
||||
random := `something: yeah
|
||||
nothing:
|
||||
- one
|
||||
@@ -227,14 +236,12 @@ why:
|
||||
}
|
||||
|
||||
func TestExtractSpecInfo_OpenAPIFalse(t *testing.T) {
|
||||
|
||||
spec, e := ExtractSpecInfo([]byte(OpenApiFalse))
|
||||
assert.NoError(t, e)
|
||||
assert.Equal(t, "false", spec.Version)
|
||||
}
|
||||
|
||||
func TestExtractSpecInfo_OpenAPI2(t *testing.T) {
|
||||
|
||||
r, e := ExtractSpecInfo([]byte(OpenApi2Spec))
|
||||
<-r.JsonParsingChannel
|
||||
assert.Nil(t, e)
|
||||
@@ -245,7 +252,6 @@ func TestExtractSpecInfo_OpenAPI2(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractSpecInfo_OpenAPI2_OddVersion(t *testing.T) {
|
||||
|
||||
_, e := ExtractSpecInfo([]byte(OpenApi2SpecOdd))
|
||||
assert.NotNil(t, e)
|
||||
assert.Equal(t,
|
||||
@@ -253,7 +259,6 @@ func TestExtractSpecInfo_OpenAPI2_OddVersion(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractSpecInfo_AsyncAPI(t *testing.T) {
|
||||
|
||||
r, e := ExtractSpecInfo([]byte(AsyncAPISpec))
|
||||
<-r.JsonParsingChannel
|
||||
assert.Nil(t, e)
|
||||
@@ -263,7 +268,6 @@ func TestExtractSpecInfo_AsyncAPI(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractSpecInfo_AsyncAPI_OddVersion(t *testing.T) {
|
||||
|
||||
_, e := ExtractSpecInfo([]byte(AsyncAPISpecOdd))
|
||||
assert.NotNil(t, e)
|
||||
assert.Equal(t,
|
||||
@@ -271,7 +275,6 @@ func TestExtractSpecInfo_AsyncAPI_OddVersion(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractSpecInfo_BadVersion_OpenAPI3(t *testing.T) {
|
||||
|
||||
yml := `openapi:
|
||||
should: fail`
|
||||
|
||||
@@ -280,7 +283,6 @@ func TestExtractSpecInfo_BadVersion_OpenAPI3(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractSpecInfo_BadVersion_Swagger(t *testing.T) {
|
||||
|
||||
yml := `swagger:
|
||||
should: fail`
|
||||
|
||||
@@ -289,7 +291,6 @@ func TestExtractSpecInfo_BadVersion_Swagger(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractSpecInfo_BadVersion_AsyncAPI(t *testing.T) {
|
||||
|
||||
yml := `asyncapi:
|
||||
should: fail`
|
||||
|
||||
@@ -298,7 +299,6 @@ func TestExtractSpecInfo_BadVersion_AsyncAPI(t *testing.T) {
|
||||
}
|
||||
|
||||
func ExampleExtractSpecInfo() {
|
||||
|
||||
// load bytes from openapi spec file.
|
||||
bytes, _ := os.ReadFile("../test_specs/petstorev3.json")
|
||||
|
||||
@@ -314,3 +314,10 @@ func ExampleExtractSpecInfo() {
|
||||
|
||||
// Output: the version of the spec is 3.0.2, the format is oas3 and the file type is json
|
||||
}
|
||||
|
||||
func TestExtractSpecInfoSync_Error(t *testing.T) {
|
||||
random := ``
|
||||
|
||||
_, e := ExtractSpecInfoWithDocumentCheckSync([]byte(random), true)
|
||||
assert.Error(t, e)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user