mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-07 12:37:48 +00:00
chore: add more test coverage
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/pb33f/libopenapi/index"
|
"github.com/pb33f/libopenapi/index"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -700,3 +701,14 @@ func TestKeyReference_GetKeyNode(t *testing.T) {
|
|||||||
assert.Equal(t, 3, nr.GetKeyNode().Line)
|
assert.Equal(t, 3, nr.GetKeyNode().Line)
|
||||||
assert.Equal(t, "pizza", nr.GetKeyNode().Value)
|
assert.Equal(t, "pizza", nr.GetKeyNode().Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestKeyReference_MarshalYAML(t *testing.T) {
|
||||||
|
kn := utils.CreateStringNode("pizza")
|
||||||
|
kr := KeyReference[string]{
|
||||||
|
KeyNode: kn,
|
||||||
|
}
|
||||||
|
|
||||||
|
on, err := kr.MarshalYAML()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, kn, on)
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,10 +4,11 @@
|
|||||||
package index
|
package index
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGenerateCleanSpecConfigBaseURL(t *testing.T) {
|
func TestGenerateCleanSpecConfigBaseURL(t *testing.T) {
|
||||||
@@ -28,7 +29,6 @@ func TestGenerateCleanSpecConfigBaseURL_RelativeDeep(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGenerateCleanSpecConfigBaseURL_NoBaseURL(t *testing.T) {
|
func TestGenerateCleanSpecConfigBaseURL_NoBaseURL(t *testing.T) {
|
||||||
|
|
||||||
u, _ := url.Parse("/things/stuff/jazz/cakes/winter/oil")
|
u, _ := url.Parse("/things/stuff/jazz/cakes/winter/oil")
|
||||||
path := "../../../../foo/bar/baz/crap.yaml#thang"
|
path := "../../../../foo/bar/baz/crap.yaml#thang"
|
||||||
assert.Equal(t, "/things/stuff/foo/bar/baz",
|
assert.Equal(t, "/things/stuff/foo/bar/baz",
|
||||||
@@ -39,7 +39,6 @@ func TestGenerateCleanSpecConfigBaseURL_NoBaseURL(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGenerateCleanSpecConfigBaseURL_HttpStrip(t *testing.T) {
|
func TestGenerateCleanSpecConfigBaseURL_HttpStrip(t *testing.T) {
|
||||||
|
|
||||||
u, _ := url.Parse(".")
|
u, _ := url.Parse(".")
|
||||||
path := "http://thing.com/crap.yaml#thang"
|
path := "http://thing.com/crap.yaml#thang"
|
||||||
assert.Equal(t, "http://thing.com",
|
assert.Equal(t, "http://thing.com",
|
||||||
@@ -50,7 +49,6 @@ func TestGenerateCleanSpecConfigBaseURL_HttpStrip(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_extractRequiredReferenceProperties(t *testing.T) {
|
func Test_extractRequiredReferenceProperties(t *testing.T) {
|
||||||
|
|
||||||
d := `$ref: http://internets/shoes`
|
d := `$ref: http://internets/shoes`
|
||||||
|
|
||||||
var rootNode yaml.Node
|
var rootNode yaml.Node
|
||||||
@@ -64,7 +62,6 @@ func Test_extractRequiredReferenceProperties(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_extractRequiredReferenceProperties_singleFile(t *testing.T) {
|
func Test_extractRequiredReferenceProperties_singleFile(t *testing.T) {
|
||||||
|
|
||||||
d := `$ref: http://cake.yaml/camel.yaml`
|
d := `$ref: http://cake.yaml/camel.yaml`
|
||||||
|
|
||||||
var rootNode yaml.Node
|
var rootNode yaml.Node
|
||||||
@@ -78,7 +75,6 @@ func Test_extractRequiredReferenceProperties_singleFile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_extractRequiredReferenceProperties_http(t *testing.T) {
|
func Test_extractRequiredReferenceProperties_http(t *testing.T) {
|
||||||
|
|
||||||
d := `$ref: http://cake.yaml/camel.yaml`
|
d := `$ref: http://cake.yaml/camel.yaml`
|
||||||
|
|
||||||
var rootNode yaml.Node
|
var rootNode yaml.Node
|
||||||
@@ -92,7 +88,6 @@ func Test_extractRequiredReferenceProperties_http(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_extractRequiredReferenceProperties_abs(t *testing.T) {
|
func Test_extractRequiredReferenceProperties_abs(t *testing.T) {
|
||||||
|
|
||||||
d := `$ref: http://cake.yaml/camel.yaml`
|
d := `$ref: http://cake.yaml/camel.yaml`
|
||||||
|
|
||||||
var rootNode yaml.Node
|
var rootNode yaml.Node
|
||||||
@@ -106,7 +101,6 @@ func Test_extractRequiredReferenceProperties_abs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_extractRequiredReferenceProperties_abs3(t *testing.T) {
|
func Test_extractRequiredReferenceProperties_abs3(t *testing.T) {
|
||||||
|
|
||||||
d := `$ref: oh/pillow.yaml`
|
d := `$ref: oh/pillow.yaml`
|
||||||
|
|
||||||
var rootNode yaml.Node
|
var rootNode yaml.Node
|
||||||
@@ -121,7 +115,6 @@ func Test_extractRequiredReferenceProperties_abs3(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_extractRequiredReferenceProperties_rel_full(t *testing.T) {
|
func Test_extractRequiredReferenceProperties_rel_full(t *testing.T) {
|
||||||
|
|
||||||
d := `$ref: "#/a/nice/picture/of/cake"`
|
d := `$ref: "#/a/nice/picture/of/cake"`
|
||||||
|
|
||||||
var rootNode yaml.Node
|
var rootNode yaml.Node
|
||||||
@@ -136,7 +129,6 @@ func Test_extractRequiredReferenceProperties_rel_full(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_extractRequiredReferenceProperties_rel(t *testing.T) {
|
func Test_extractRequiredReferenceProperties_rel(t *testing.T) {
|
||||||
|
|
||||||
d := `$ref: oh/camel.yaml#/rum/cake`
|
d := `$ref: oh/camel.yaml#/rum/cake`
|
||||||
|
|
||||||
var rootNode yaml.Node
|
var rootNode yaml.Node
|
||||||
@@ -151,7 +143,6 @@ func Test_extractRequiredReferenceProperties_rel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_extractRequiredReferenceProperties_abs2(t *testing.T) {
|
func Test_extractRequiredReferenceProperties_abs2(t *testing.T) {
|
||||||
|
|
||||||
d := `$ref: /oh/my/camel.yaml#/rum/cake`
|
d := `$ref: /oh/my/camel.yaml#/rum/cake`
|
||||||
|
|
||||||
var rootNode yaml.Node
|
var rootNode yaml.Node
|
||||||
@@ -166,7 +157,6 @@ func Test_extractRequiredReferenceProperties_abs2(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_extractRequiredReferenceProperties_http_rel(t *testing.T) {
|
func Test_extractRequiredReferenceProperties_http_rel(t *testing.T) {
|
||||||
|
|
||||||
d := `$ref: my/wet/camel.yaml#/rum/cake`
|
d := `$ref: my/wet/camel.yaml#/rum/cake`
|
||||||
|
|
||||||
var rootNode yaml.Node
|
var rootNode yaml.Node
|
||||||
@@ -181,7 +171,6 @@ func Test_extractRequiredReferenceProperties_http_rel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_extractRequiredReferenceProperties_http_rel_nocomponent(t *testing.T) {
|
func Test_extractRequiredReferenceProperties_http_rel_nocomponent(t *testing.T) {
|
||||||
|
|
||||||
d := `$ref: my/wet/camel.yaml`
|
d := `$ref: my/wet/camel.yaml`
|
||||||
|
|
||||||
var rootNode yaml.Node
|
var rootNode yaml.Node
|
||||||
@@ -196,7 +185,6 @@ func Test_extractRequiredReferenceProperties_http_rel_nocomponent(t *testing.T)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_extractRequiredReferenceProperties_nocomponent(t *testing.T) {
|
func Test_extractRequiredReferenceProperties_nocomponent(t *testing.T) {
|
||||||
|
|
||||||
d := `$ref: my/wet/camel.yaml`
|
d := `$ref: my/wet/camel.yaml`
|
||||||
|
|
||||||
var rootNode yaml.Node
|
var rootNode yaml.Node
|
||||||
@@ -211,7 +199,6 @@ func Test_extractRequiredReferenceProperties_nocomponent(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_extractRequiredReferenceProperties_component_http(t *testing.T) {
|
func Test_extractRequiredReferenceProperties_component_http(t *testing.T) {
|
||||||
|
|
||||||
d := `$ref: go-to-bed.com/no/more/cake.yaml#/lovely/jam`
|
d := `$ref: go-to-bed.com/no/more/cake.yaml#/lovely/jam`
|
||||||
|
|
||||||
var rootNode yaml.Node
|
var rootNode yaml.Node
|
||||||
@@ -226,7 +213,6 @@ func Test_extractRequiredReferenceProperties_component_http(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_extractRequiredReferenceProperties_nocomponent_http(t *testing.T) {
|
func Test_extractRequiredReferenceProperties_nocomponent_http(t *testing.T) {
|
||||||
|
|
||||||
d := `$ref: go-to-bed.com/no/more/cake.yaml`
|
d := `$ref: go-to-bed.com/no/more/cake.yaml`
|
||||||
|
|
||||||
var rootNode yaml.Node
|
var rootNode yaml.Node
|
||||||
@@ -238,11 +224,9 @@ func Test_extractRequiredReferenceProperties_nocomponent_http(t *testing.T) {
|
|||||||
assert.Len(t, props, 1)
|
assert.Len(t, props, 1)
|
||||||
assert.Equal(t, "cakes", props["http://bunny-bun-bun.com/go-to-bed.com/no/more/cake.yaml"][0])
|
assert.Equal(t, "cakes", props["http://bunny-bun-bun.com/go-to-bed.com/no/more/cake.yaml"][0])
|
||||||
assert.NotNil(t, data)
|
assert.NotNil(t, data)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_extractRequiredReferenceProperties_nocomponent_http2(t *testing.T) {
|
func Test_extractRequiredReferenceProperties_nocomponent_http2(t *testing.T) {
|
||||||
|
|
||||||
d := `$ref: go-to-bed.com/no/more/cake.yaml`
|
d := `$ref: go-to-bed.com/no/more/cake.yaml`
|
||||||
|
|
||||||
var rootNode yaml.Node
|
var rootNode yaml.Node
|
||||||
@@ -259,3 +243,7 @@ func Test_extractRequiredReferenceProperties_nocomponent_http2(t *testing.T) {
|
|||||||
func Test_extractDefinitionRequiredRefProperties_nil(t *testing.T) {
|
func Test_extractDefinitionRequiredRefProperties_nil(t *testing.T) {
|
||||||
assert.Nil(t, extractDefinitionRequiredRefProperties(nil, nil, "", nil))
|
assert.Nil(t, extractDefinitionRequiredRefProperties(nil, nil, "", nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSyncMapToMap_Nil(t *testing.T) {
|
||||||
|
assert.Nil(t, syncMapToMap[string, string](nil))
|
||||||
|
}
|
||||||
|
|||||||
@@ -2848,3 +2848,7 @@ func TestSchemaChanges_TotalBreakingChanges_NoNilPanic(t *testing.T) {
|
|||||||
var changes *SchemaChanges
|
var changes *SchemaChanges
|
||||||
assert.Equal(t, 0, changes.TotalBreakingChanges())
|
assert.Equal(t, 0, changes.TotalBreakingChanges())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCompareSchemas_Nil(t *testing.T) {
|
||||||
|
assert.Nil(t, CompareSchemas(nil, nil))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user