Bumping coverage

checking all the corners for cobwebs
This commit is contained in:
Dave Shanley
2022-11-20 10:52:09 -05:00
parent 26d3535e75
commit e1e91d0682
4 changed files with 61 additions and 2 deletions

View File

@@ -122,8 +122,6 @@ func (sp *SchemaProxy) Hash() [32]byte {
if !sp.isReference {
return sp.rendered.Hash()
}
// we only hash inline schemas
return sha256.Sum256([]byte(sp.referenceLookup))
} else {
if !sp.isReference {
// only resolve this proxy if it's not a ref.

View File

@@ -50,3 +50,19 @@ func TestSchemaProxy_Build_CheckRef(t *testing.T) {
assert.Equal(t, "f00a787f7492a95e165b470702f4fe9373583fbdc025b2c8bdf0262cc48fcff4",
low.GenerateHashString(&sch))
}
func TestSchemaProxy_Build_HashInline(t *testing.T) {
yml := `type: int`
var sch SchemaProxy
var idxNode yaml.Node
_ = yaml.Unmarshal([]byte(yml), &idxNode)
err := sch.Build(idxNode.Content[0], nil)
assert.NoError(t, err)
assert.False(t, sch.IsSchemaReference())
assert.NotNil(t, sch.Schema())
assert.Equal(t, "6da88c34ba124c41f977db66a4fc5c1a951708d285c81bb0d47c3206f4c27ca8",
low.GenerateHashString(&sch))
}

View File

@@ -1130,6 +1130,36 @@ func TestExtractSchema_DoNothing(t *testing.T) {
}
func TestExtractSchema_AdditionalProperties_Ref(t *testing.T) {
yml := `components:
schemas:
Nothing:
type: int
Something:
additionalProperties:
cake:
$ref: '#/components/schemas/Nothing'`
var iNode yaml.Node
mErr := yaml.Unmarshal([]byte(yml), &iNode)
assert.NoError(t, mErr)
idx := index.NewSpecIndex(&iNode)
yml = `schema:
type: int
additionalProperties:
$ref: '#/components/schemas/Something'`
var idxNode yaml.Node
_ = yaml.Unmarshal([]byte(yml), &idxNode)
res, err := ExtractSchema(idxNode.Content[0], idx)
assert.NotNil(t, res.Value.Schema().AdditionalProperties.Value.(*SchemaProxy).Schema())
assert.Nil(t, err)
}
func TestExtractSchema_OneOfRef(t *testing.T) {
yml := `components:

View File

@@ -41,3 +41,18 @@ func Benchmark_CompareOpenAPIDocuments(b *testing.B) {
CompareOpenAPIDocuments(origDoc, modDoc)
}
}
func Benchmark_CompareOpenAPIDocuments_NoChange(b *testing.B) {
original, _ := ioutil.ReadFile("../test_specs/burgershop.openapi.yaml")
modified, _ := ioutil.ReadFile("../test_specs/burgershop.openapi.yaml")
infoOrig, _ := datamodel.ExtractSpecInfo(original)
infoMod, _ := datamodel.ExtractSpecInfo(modified)
origDoc, _ := v3.CreateDocument(infoOrig)
modDoc, _ := v3.CreateDocument(infoMod)
for i := 0; i < b.N; i++ {
CompareOpenAPIDocuments(origDoc, modDoc)
}
}