fix: continued moving everything to orderedmaps plus cleaned up most the tests

This commit is contained in:
Tristan Cartledge
2023-12-01 17:37:07 +00:00
parent 0f3d0cb28f
commit a4ad09aab3
169 changed files with 3435 additions and 3764 deletions

View File

@@ -6,10 +6,11 @@ package low
import (
"crypto/sha256"
"fmt"
"github.com/pb33f/libopenapi/utils"
"strings"
"testing"
"github.com/pb33f/libopenapi/utils"
"github.com/pb33f/libopenapi/index"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
@@ -99,7 +100,6 @@ func TestKeyReference_GenerateMapKey(t *testing.T) {
}
func TestIsCircular_LookupFromJourney(t *testing.T) {
yml := `components:
schemas:
Something:
@@ -136,7 +136,6 @@ func TestIsCircular_LookupFromJourney(t *testing.T) {
}
func TestIsCircular_LookupFromJourney_Optional(t *testing.T) {
yml := `components:
schemas:
Something:
@@ -237,7 +236,6 @@ func TestIsCircular_LookupFromLoopPoint_Optional(t *testing.T) {
}
func TestIsCircular_FromRefLookup(t *testing.T) {
yml := `components:
schemas:
NotCircle:
@@ -558,21 +556,17 @@ func TestGetCircularReferenceResult_NothingFound(t *testing.T) {
func TestHashToString(t *testing.T) {
assert.Equal(t, "5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5",
HashToString(sha256.Sum256([]byte("12345"))))
}
func TestReference_IsReference(t *testing.T) {
ref := Reference{
Reference: "#/components/schemas/SomeSchema",
}
ref := Reference{}
ref.SetReference("#/components/schemas/SomeSchema", nil)
assert.True(t, ref.IsReference())
}
func TestNodeReference_NodeLineNumber(t *testing.T) {
n := utils.CreateStringNode("pizza")
nr := NodeReference[string]{
nr := &NodeReference[string]{
Value: "pizza",
ValueNode: n,
}
@@ -582,51 +576,36 @@ func TestNodeReference_NodeLineNumber(t *testing.T) {
}
func TestNodeReference_NodeLineNumberEmpty(t *testing.T) {
nr := NodeReference[string]{
nr := &NodeReference[string]{
Value: "pizza",
}
assert.Equal(t, 0, nr.NodeLineNumber())
}
func TestNodeReference_GetReference(t *testing.T) {
nr := NodeReference[string]{
Reference: "#/happy/sunday",
}
nr := &NodeReference[string]{}
nr.SetReference("#/happy/sunday", nil)
assert.Equal(t, "#/happy/sunday", nr.GetReference())
}
func TestNodeReference_SetReference(t *testing.T) {
nr := NodeReference[string]{}
nr.SetReference("#/happy/sunday")
}
func TestNodeReference_IsReference(t *testing.T) {
nr := NodeReference[string]{
ReferenceNode: true,
}
assert.True(t, nr.IsReference())
nr := &NodeReference[string]{}
nr.SetReference("#/happy/sunday", nil)
}
func TestNodeReference_GetKeyNode(t *testing.T) {
nr := NodeReference[string]{
nr := &NodeReference[string]{
KeyNode: utils.CreateStringNode("pizza"),
}
assert.Equal(t, "pizza", nr.GetKeyNode().Value)
}
func TestNodeReference_GetValueUntyped(t *testing.T) {
type anything struct {
thing string
}
nr := NodeReference[any]{
nr := &NodeReference[any]{
Value: anything{thing: "ding"},
}
@@ -634,7 +613,6 @@ func TestNodeReference_GetValueUntyped(t *testing.T) {
}
func TestValueReference_NodeLineNumber(t *testing.T) {
n := utils.CreateStringNode("pizza")
nr := ValueReference[string]{
Value: "pizza",
@@ -646,7 +624,6 @@ func TestValueReference_NodeLineNumber(t *testing.T) {
}
func TestValueReference_NodeLineNumber_Nil(t *testing.T) {
nr := ValueReference[string]{
Value: "pizza",
}
@@ -655,21 +632,12 @@ func TestValueReference_NodeLineNumber_Nil(t *testing.T) {
}
func TestValueReference_GetReference(t *testing.T) {
nr := ValueReference[string]{
Reference: "#/happy/sunday",
}
nr := ValueReference[string]{}
nr.SetReference("#/happy/sunday", nil)
assert.Equal(t, "#/happy/sunday", nr.GetReference())
}
func TestValueReference_SetReference(t *testing.T) {
nr := ValueReference[string]{}
nr.SetReference("#/happy/sunday")
}
func TestValueReference_GetValueUntyped(t *testing.T) {
type anything struct {
thing string
}
@@ -681,28 +649,15 @@ func TestValueReference_GetValueUntyped(t *testing.T) {
assert.Equal(t, "{ding}", fmt.Sprint(nr.GetValueUntyped()))
}
func TestValueReference_IsReference(t *testing.T) {
nr := NodeReference[string]{
ReferenceNode: true,
}
assert.True(t, nr.IsReference())
}
func TestValueReference_MarshalYAML_Ref(t *testing.T) {
nr := ValueReference[string]{
ReferenceNode: true,
Reference: "#/burgers/beer",
}
nr := ValueReference[string]{}
nr.SetReference("#/burgers/beer", nil)
data, _ := yaml.Marshal(nr)
assert.Equal(t, `$ref: '#/burgers/beer'`, strings.TrimSpace(string(data)))
}
func TestValueReference_MarshalYAML(t *testing.T) {
v := map[string]interface{}{
"beer": "burger",
"wine": "cheese",
@@ -725,7 +680,6 @@ wine: cheese`
}
func TestKeyReference_GetValueUntyped(t *testing.T) {
type anything struct {
thing string
}