-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples_test.go
44 lines (39 loc) · 1.05 KB
/
examples_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
42
43
44
package openapi_test
import (
"testing"
"github.com/MarkRosemaker/openapi"
"github.com/go-json-experiment/json/jsontext"
)
var invalidExample = &openapi.ExampleRef{
Value: &openapi.Example{
Value: jsontext.Value(`"foo"`),
ExternalValue: mustParseURL("https://example.com/examples/foo"),
},
}
func TestExamples_Validate_Error(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
examples openapi.Examples
err string
}{
{
openapi.Examples{"foo": invalidExample},
`["foo"]: value and externalValue are mutually exclusive`,
},
{openapi.Examples{
"foo": &openapi.ExampleRef{
Value: &openapi.Example{
Extensions: jsontext.Value(`{"bar": "buz"}`),
},
},
}, `["foo"].bar: ` + openapi.ErrUnknownField.Error()},
{
openapi.Examples{" ": &openapi.ExampleRef{Value: &openapi.Example{}}},
`[" "] (" ") is invalid: must match the regular expression "^[a-zA-Z0-9\\.\\-_]+$"`,
},
} {
if err := tc.examples.Validate(); err == nil || err.Error() != tc.err {
t.Fatalf("want: %s, got: %s", tc.err, err)
}
}
}