mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-11 04:20:24 +00:00
chore: add more test coverage
This commit is contained in:
@@ -5,9 +5,10 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pb33f/libopenapi/utils"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/pb33f/libopenapi/utils"
|
||||||
|
|
||||||
"github.com/pb33f/libopenapi/datamodel"
|
"github.com/pb33f/libopenapi/datamodel"
|
||||||
"github.com/pb33f/libopenapi/datamodel/low"
|
"github.com/pb33f/libopenapi/datamodel/low"
|
||||||
"github.com/pb33f/libopenapi/datamodel/low/base"
|
"github.com/pb33f/libopenapi/datamodel/low/base"
|
||||||
@@ -1250,6 +1251,61 @@ components:
|
|||||||
assert.Equal(t, 1, changes.AdditionalPropertiesChanges.PropertyChanges.TotalChanges())
|
assert.Equal(t, 1, changes.AdditionalPropertiesChanges.PropertyChanges.TotalChanges())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCompareSchemas_AdditionalProperties_Boolean(t *testing.T) {
|
||||||
|
left := `openapi: 3.1
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
OK:
|
||||||
|
additionalProperties: true`
|
||||||
|
|
||||||
|
right := `openapi: 3.1
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
OK:
|
||||||
|
additionalProperties: false`
|
||||||
|
|
||||||
|
leftDoc, rightDoc := test_BuildDoc(left, right)
|
||||||
|
|
||||||
|
// extract left reference schema and non reference schema.
|
||||||
|
lSchemaProxy := leftDoc.Components.Value.FindSchema("OK").Value
|
||||||
|
rSchemaProxy := rightDoc.Components.Value.FindSchema("OK").Value
|
||||||
|
|
||||||
|
changes := CompareSchemas(lSchemaProxy, rSchemaProxy)
|
||||||
|
assert.NotNil(t, changes)
|
||||||
|
assert.Equal(t, 1, changes.TotalChanges())
|
||||||
|
assert.Len(t, changes.GetAllChanges(), 1)
|
||||||
|
assert.Equal(t, 1, changes.TotalBreakingChanges())
|
||||||
|
assert.Equal(t, 1, changes.PropertyChanges.TotalChanges())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCompareSchemas_AdditionalProperties_Boolean_To_Schema(t *testing.T) {
|
||||||
|
left := `openapi: 3.1
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
OK:
|
||||||
|
additionalProperties: true`
|
||||||
|
|
||||||
|
right := `openapi: 3.1
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
OK:
|
||||||
|
additionalProperties:
|
||||||
|
type: int`
|
||||||
|
|
||||||
|
leftDoc, rightDoc := test_BuildDoc(left, right)
|
||||||
|
|
||||||
|
// extract left reference schema and non reference schema.
|
||||||
|
lSchemaProxy := leftDoc.Components.Value.FindSchema("OK").Value
|
||||||
|
rSchemaProxy := rightDoc.Components.Value.FindSchema("OK").Value
|
||||||
|
|
||||||
|
changes := CompareSchemas(lSchemaProxy, rSchemaProxy)
|
||||||
|
assert.NotNil(t, changes)
|
||||||
|
assert.Equal(t, 1, changes.TotalChanges())
|
||||||
|
assert.Len(t, changes.GetAllChanges(), 1)
|
||||||
|
assert.Equal(t, 1, changes.TotalBreakingChanges())
|
||||||
|
assert.Equal(t, 1, changes.PropertyChanges.TotalChanges())
|
||||||
|
}
|
||||||
|
|
||||||
func TestCompareSchemas_AdditionalProperties_Added(t *testing.T) {
|
func TestCompareSchemas_AdditionalProperties_Added(t *testing.T) {
|
||||||
left := `openapi: 3.1
|
left := `openapi: 3.1
|
||||||
components:
|
components:
|
||||||
@@ -2782,3 +2838,13 @@ components:
|
|||||||
assert.Len(t, changes.SchemaPropertyChanges["name"].PropertyChanges.Changes, 2)
|
assert.Len(t, changes.SchemaPropertyChanges["name"].PropertyChanges.Changes, 2)
|
||||||
assert.Len(t, changes.PropertyChanges.Changes, 2)
|
assert.Len(t, changes.PropertyChanges.Changes, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSchemaChanges_TotalChanges_NoNilPanic(t *testing.T) {
|
||||||
|
var changes *SchemaChanges
|
||||||
|
assert.Equal(t, 0, changes.TotalChanges())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSchemaChanges_TotalBreakingChanges_NoNilPanic(t *testing.T) {
|
||||||
|
var changes *SchemaChanges
|
||||||
|
assert.Equal(t, 0, changes.TotalBreakingChanges())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user