Repository navigation
Expand file tree
/
Copy pathinfo_test.go
More file actions
95 lines (80 loc) · 2.31 KB
/
Copy pathinfo_test.go
File metadata and controls
95 lines (80 loc) · 2.31 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package openapi_test
import (
"net/url"
"testing"
"github.com/MarkRosemaker/openapi"
)
func TestInfo_Validate(t *testing.T) {
t.Parallel()
t.Run("empty", func(t *testing.T) {
i := openapi.Info{}
if err := i.Validate(); err == nil {
t.Fatal("expected error")
} else if want := "title is required"; err.Error() != want {
t.Fatalf("got: %v, want: %v", err, want)
}
})
t.Run("no version", func(t *testing.T) {
i := openapi.Info{Title: "Sample Pet Store App"}
if err := i.Validate(); err == nil {
t.Fatal("expected error")
} else if want := "version is required"; err.Error() != want {
t.Fatalf("got: %v, want: %v", err, want)
}
})
t.Run("valid", func(t *testing.T) {
i := openapi.Info{Title: "Sample Pet Store App", Version: "1.0.1"}
if err := i.Validate(); err != nil {
t.Fatal(err)
}
})
t.Run("fix TOS URL", func(t *testing.T) {
i := openapi.Info{
Title: "Sample Pet Store App",
TermsOfService: &url.URL{Host: "example.com"},
Version: "1.0.1",
}
if err := i.Validate(); err != nil {
t.Fatal(err)
}
if want := "https://example.com"; i.TermsOfService.String() != want {
t.Fatalf("url not fixed, want: %q, got: %q", want, i.TermsOfService)
}
})
t.Run("invalid contact", func(t *testing.T) {
i := openapi.Info{
Title: "Sample Pet Store App",
Contact: &openapi.Contact{Email: "foo"},
Version: "1.0.1",
}
if err := i.Validate(); err == nil {
t.Fatal("expected error")
} else if want := `contact.email: invalid email: "foo"`; err.Error() != want {
t.Fatalf("got: %v, want: %v", err, want)
}
})
t.Run("invalid license", func(t *testing.T) {
i := openapi.Info{
Title: "Sample Pet Store App",
License: &openapi.License{},
Version: "1.0.1",
}
if err := i.Validate(); err == nil {
t.Fatal("expected error")
} else if want := `license.name is required`; err.Error() != want {
t.Fatalf("got: %v, want: %v", err, want)
}
})
t.Run("invalid extension", func(t *testing.T) {
i := openapi.Info{
Title: "Sample Pet Store App",
Version: "1.0.1",
Extensions: openapi.Extensions(`{"foo":"bar"}`),
}
if err := i.Validate(); err == nil {
t.Fatal("expected error")
} else if want := `foo: ` + openapi.ErrUnknownField.Error(); err.Error() != want {
t.Fatalf("got: %v, want: %v", err, want)
}
})
}