-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinfo_test.go
71 lines (67 loc) · 1.88 KB
/
info_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package openapi_test
import (
"reflect"
"testing"
openapi "github.com/nasa9084/go-openapi"
yaml "gopkg.in/yaml.v2"
)
func TestInfo_Validate(t *testing.T) {
candidates := []candidate{
{"empty",
openapi.Info{},
openapi.ErrRequired{Target: "info.title"},
},
{"withTitle",
openapi.Info{Title: "foo"},
openapi.ErrRequired{Target: "info.version"},
},
{"withTitleAndVersion",
openapi.Info{Title: "foo", Version: "1.0"},
nil,
},
{"withInvalidToS", openapi.Info{Title: "foo", TermsOfService: "foobar", Version: "1.0"}, openapi.ErrFormatInvalid{Target: "info.termsOfService", Format: "URL"}},
{"withInvalidLicense", openapi.Info{Title: "foo", Version: "1.0", License: &openapi.License{URL: "foobar"}}, openapi.ErrRequired{Target: "license.name"}},
}
testValidater(t, candidates)
}
func TestInfoByExample(t *testing.T) {
example := `title: Sample Pet Store App
description: This is a sample server for a pet store.
termsOfService: http://example.com/terms/
contact:
name: API Support
url: http://www.example.com/support
email: [email protected]
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.1`
info := openapi.Info{}
if err := yaml.Unmarshal([]byte(example), &info); err != nil {
t.Error(err)
return
}
if err := info.Validate(); err != nil {
t.Error(err)
return
}
expected := openapi.Info{
Title: "Sample Pet Store App",
Description: "This is a sample server for a pet store.",
TermsOfService: "http://example.com/terms/",
Contact: &openapi.Contact{
Name: "API Support",
URL: "http://www.example.com/support",
Email: "[email protected]",
},
License: &openapi.License{
Name: "Apache 2.0",
URL: "https://www.apache.org/licenses/LICENSE-2.0.html",
},
Version: "1.0.1",
}
if !reflect.DeepEqual(info, expected) {
t.Errorf("%+v != %+v", info, expected)
return
}
}