Skip to content

Commit

Permalink
pkg/validation: remove yaml dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
sttts committed Nov 5, 2020
1 parent 27616ca commit 98df15e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 25 deletions.
3 changes: 0 additions & 3 deletions pkg/validation/spec/external_docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ import (

func TestIntegrationExternalDocs(t *testing.T) {
var extDocs = ExternalDocumentation{Description: "the name", URL: "the url"}
const extDocsYAML = "description: the name\nurl: the url\n"
const extDocsJSON = `{"description":"the name","url":"the url"}`
assertSerializeJSON(t, extDocs, extDocsJSON)
assertSerializeYAML(t, extDocs, extDocsYAML)
assertParsesJSON(t, extDocsJSON, extDocs)
assertParsesYAML(t, extDocsYAML, extDocs)
}
22 changes: 0 additions & 22 deletions pkg/validation/spec/structs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
)

func assertSerializeJSON(t testing.TB, actual interface{}, expected string) bool {
Expand All @@ -31,14 +30,6 @@ func assertSerializeJSON(t testing.TB, actual interface{}, expected string) bool
return assert.Equal(t, string(ser), expected)
}

func assertSerializeYAML(t testing.TB, actual interface{}, expected string) bool {
ser, err := yaml.Marshal(actual)
if err != nil {
return assert.Fail(t, "unable to marshal to yaml (%s): %#v", err, actual)
}
return assert.Equal(t, string(ser), expected)
}

func derefTypeOf(expected interface{}) (tpe reflect.Type) {
tpe = reflect.TypeOf(expected)
if tpe.Kind() == reflect.Ptr {
Expand Down Expand Up @@ -68,19 +59,6 @@ func assertParsesJSON(t testing.TB, actual string, expected interface{}) bool {
return assert.Equal(t, act, expected)
}

func assertParsesYAML(t testing.TB, actual string, expected interface{}) bool {
parsed := reflect.New(derefTypeOf(expected))
err := yaml.Unmarshal([]byte(actual), parsed.Interface())
if err != nil {
return assert.Fail(t, "unable to unmarshal from yaml (%s): %s", err, actual)
}
act := parsed.Interface()
if !isPointed(expected) {
act = reflect.Indirect(parsed).Interface()
}
return assert.EqualValues(t, act, expected)
}

func TestSerialization_SerializeJSON(t *testing.T) {
assertSerializeJSON(t, []string{"hello"}, "[\"hello\"]")
assertSerializeJSON(t, []string{"hello", "world", "and", "stuff"}, "[\"hello\",\"world\",\"and\",\"stuff\"]")
Expand Down

0 comments on commit 98df15e

Please sign in to comment.