mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 12:37:49 +00:00
bumping test coverage, adding more tests.
Signed-off-by: Dave Shanley <dave@quobix.com>
This commit is contained in:
@@ -57,3 +57,42 @@ url: https://pb33f.io/not-real
|
|||||||
assert.Equal(t, yml, string(bytes))
|
assert.Equal(t, yml, string(bytes))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLicense_Render_Identifier(t *testing.T) {
|
||||||
|
|
||||||
|
highL := &License{Name: "MIT", Identifier: "MIT"}
|
||||||
|
dat, _ := highL.Render()
|
||||||
|
|
||||||
|
// unmarshal yaml into a *yaml.Node instance
|
||||||
|
var cNode yaml.Node
|
||||||
|
_ = yaml.Unmarshal(dat, &cNode)
|
||||||
|
|
||||||
|
// build low
|
||||||
|
var lowLicense lowbase.License
|
||||||
|
_ = lowmodel.BuildModel(cNode.Content[0], &lowLicense)
|
||||||
|
|
||||||
|
// build high
|
||||||
|
highLicense := NewLicense(&lowLicense)
|
||||||
|
|
||||||
|
assert.Equal(t, "MIT", highLicense.Name)
|
||||||
|
assert.Equal(t, "MIT", highLicense.Identifier)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLicense_Render_IdentifierAndURL_Error(t *testing.T) {
|
||||||
|
|
||||||
|
// this should fail because you can't have both an identifier and a URL
|
||||||
|
highL := &License{Name: "MIT", Identifier: "MIT", URL: "https://pb33f.io"}
|
||||||
|
dat, _ := highL.Render()
|
||||||
|
|
||||||
|
// unmarshal yaml into a *yaml.Node instance
|
||||||
|
var cNode yaml.Node
|
||||||
|
_ = yaml.Unmarshal(dat, &cNode)
|
||||||
|
|
||||||
|
// build low
|
||||||
|
var lowLicense lowbase.License
|
||||||
|
_ = lowmodel.BuildModel(cNode.Content[0], &lowLicense)
|
||||||
|
err := lowLicense.Build(cNode.Content[0], nil)
|
||||||
|
|
||||||
|
assert.Error(t, err)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1597,6 +1597,9 @@ func TestSchema_UnevaluatedPropertiesAsBool_DefinedAsTrue(t *testing.T) {
|
|||||||
assert.True(t, res.Value.Schema().UnevaluatedProperties.Value.IsB())
|
assert.True(t, res.Value.Schema().UnevaluatedProperties.Value.IsB())
|
||||||
assert.True(t, *res.Value.Schema().UnevaluatedProperties.Value.B)
|
assert.True(t, *res.Value.Schema().UnevaluatedProperties.Value.B)
|
||||||
|
|
||||||
|
assert.Equal(t, "571bd1853c22393131e2dcadce86894da714ec14968895c8b7ed18154b2be8cd",
|
||||||
|
low.GenerateHashString(res.Value.Schema().UnevaluatedProperties.Value))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSchema_UnevaluatedPropertiesAsBool_DefinedAsFalse(t *testing.T) {
|
func TestSchema_UnevaluatedPropertiesAsBool_DefinedAsFalse(t *testing.T) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package low
|
|||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -685,5 +686,9 @@ func GenerateHashString(v any) string {
|
|||||||
return fmt.Sprintf(HASH, h.Hash())
|
return fmt.Sprintf(HASH, h.Hash())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// if we get here, we're a primitive, check if we're a pointer and de-point
|
||||||
|
if reflect.TypeOf(v).Kind() == reflect.Ptr {
|
||||||
|
v = reflect.ValueOf(v).Elem().Interface()
|
||||||
|
}
|
||||||
return fmt.Sprintf(HASH, sha256.Sum256([]byte(fmt.Sprint(v))))
|
return fmt.Sprintf(HASH, sha256.Sum256([]byte(fmt.Sprint(v))))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/pb33f/libopenapi/index"
|
"github.com/pb33f/libopenapi/index"
|
||||||
@@ -1616,10 +1617,18 @@ x-tacos: [1,2,3]`
|
|||||||
|
|
||||||
type test_fresh struct {
|
type test_fresh struct {
|
||||||
val string
|
val string
|
||||||
|
thang *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f test_fresh) Hash() [32]byte {
|
func (f test_fresh) Hash() [32]byte {
|
||||||
return sha256.Sum256([]byte(f.val))
|
var data []string
|
||||||
|
if f.val != "" {
|
||||||
|
data = append(data, f.val)
|
||||||
|
}
|
||||||
|
if f.thang != nil {
|
||||||
|
data = append(data, fmt.Sprintf("%v", *f.thang))
|
||||||
|
}
|
||||||
|
return sha256.Sum256([]byte(strings.Join(data, "|")))
|
||||||
}
|
}
|
||||||
func TestAreEqual(t *testing.T) {
|
func TestAreEqual(t *testing.T) {
|
||||||
assert.True(t, AreEqual(test_fresh{val: "hello"}, test_fresh{val: "hello"}))
|
assert.True(t, AreEqual(test_fresh{val: "hello"}, test_fresh{val: "hello"}))
|
||||||
@@ -1637,6 +1646,17 @@ func TestGenerateHashString(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGenerateHashString_Pointer(t *testing.T) {
|
||||||
|
|
||||||
|
val := true
|
||||||
|
assert.Equal(t, "b5bea41b6c623f7c09f1bf24dcae58ebab3c0cdd90ad966bc43a45b44867e12b",
|
||||||
|
GenerateHashString(test_fresh{thang: &val}))
|
||||||
|
|
||||||
|
assert.Equal(t, "b5bea41b6c623f7c09f1bf24dcae58ebab3c0cdd90ad966bc43a45b44867e12b",
|
||||||
|
GenerateHashString(&val))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestSetReference(t *testing.T) {
|
func TestSetReference(t *testing.T) {
|
||||||
|
|
||||||
type testObj struct {
|
type testObj struct {
|
||||||
|
|||||||
@@ -797,3 +797,9 @@ func TestCheckEnumForDuplicates_FailMultiple(t *testing.T) {
|
|||||||
yaml.Unmarshal([]byte(yml), &rootNode)
|
yaml.Unmarshal([]byte(yml), &rootNode)
|
||||||
assert.Len(t, CheckEnumForDuplicates(rootNode.Content[0].Content), 3)
|
assert.Len(t, CheckEnumForDuplicates(rootNode.Content[0].Content), 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConvertComponentIdIntoFriendlyPathSearch_Brackets(t *testing.T) {
|
||||||
|
segment, path := ConvertComponentIdIntoFriendlyPathSearch("#/components/schemas/OhNoWhy[HaveYouDoneThis]")
|
||||||
|
assert.Equal(t, "$.components.schemas['OhNoWhy[HaveYouDoneThis]']", path)
|
||||||
|
assert.Equal(t, "OhNoWhy[HaveYouDoneThis]", segment)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user