-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcontact_test.go
47 lines (42 loc) · 1.33 KB
/
contact_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
package openapi_test
import (
"reflect"
"testing"
openapi "github.com/nasa9084/go-openapi"
yaml "gopkg.in/yaml.v2"
)
func TestContact_Validate(t *testing.T) {
urlRequiredError := openapi.ErrRequired{Target: "contact.url"}
candidates := []candidate{
{"empty", openapi.Contact{}, urlRequiredError},
{"withURL", openapi.Contact{URL: exampleCom}, nil},
{"invalidURL", openapi.Contact{URL: "foobar"}, openapi.ErrFormatInvalid{Target: "contact.url", Format: "URL"}},
{"withEmail", openapi.Contact{Email: exampleMail}, urlRequiredError},
{"valid", openapi.Contact{URL: exampleCom, Email: exampleMail}, nil},
{"invalidEmail", openapi.Contact{URL: exampleCom, Email: "foobar"}, openapi.ErrFormatInvalid{Target: "contact.email", Format: "email"}},
}
testValidater(t, candidates)
}
func TestContactByExample(t *testing.T) {
example := `name: API Support
url: http://www.example.com/support
email: [email protected]`
contact := openapi.Contact{}
if err := yaml.Unmarshal([]byte(example), &contact); err != nil {
t.Error(err)
return
}
if err := contact.Validate(); err != nil {
t.Error(err)
return
}
expected := openapi.Contact{
Name: "API Support",
URL: "http://www.example.com/support",
Email: "[email protected]",
}
if !reflect.DeepEqual(contact, expected) {
t.Errorf("%+v != %+v", contact, expected)
return
}
}