-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedia_type_test.go
41 lines (37 loc) · 1.12 KB
/
media_type_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package openapi_test
import (
"testing"
"github.com/MarkRosemaker/openapi"
"github.com/go-json-experiment/json/jsontext"
)
func TestMediaType_Validate_Error(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
mt openapi.MediaType
err string
}{
{openapi.MediaType{
Example: jsontext.Value("foo"),
Examples: openapi.Examples{},
}, `example and examples are mutually exclusive`},
{openapi.MediaType{
Examples: openapi.Examples{"foo": invalidExample},
}, `examples["foo"]: value and externalValue are mutually exclusive`},
{openapi.MediaType{
Encoding: openapi.Encodings{
"foo": &openapi.Encoding{Style: "bar"},
},
}, `encoding["foo"].style ("bar") is invalid, must be one of: "matrix", "label", "form", "simple", "spaceDelimited", "pipeDelimited", "deepObject"`},
{openapi.MediaType{
Extensions: jsontext.Value(`{"foo":"bar"}`),
}, `foo: ` + openapi.ErrUnknownField.Error()},
} {
t.Run(tc.err, func(t *testing.T) {
if err := tc.mt.Validate(); err == nil {
t.Fatal("expected error")
} else if err.Error() != tc.err {
t.Fatalf("want: %v, got: %v", tc.err, err)
}
})
}
}