-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions_test.go
More file actions
96 lines (75 loc) · 1.83 KB
/
options_test.go
File metadata and controls
96 lines (75 loc) · 1.83 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
96
package openapi_validator
import (
"net/http"
"testing"
)
func TestDefaultOptions(t *testing.T) {
// Arrange & Act
opts := DefaultOptions()
// Assert
if !opts.ValidateRequests {
t.Error("expected ValidateRequests to be true")
}
if opts.ValidateResponses {
t.Error("expected ValidateResponses to be false")
}
if opts.SwaggerUIPath != "/docs" {
t.Errorf("expected SwaggerUIPath to be /docs, got %s", opts.SwaggerUIPath)
}
if opts.ErrorEncoder == nil {
t.Error("expected ErrorEncoder to not be nil")
}
}
func TestWithValidateRequests(t *testing.T) {
// Arrange
opts := DefaultOptions()
// Act
WithValidateRequests(false)(opts)
// Assert
if opts.ValidateRequests {
t.Error("expected ValidateRequests to be false")
}
}
func TestWithValidateResponses(t *testing.T) {
// Arrange
opts := DefaultOptions()
// Act
WithValidateResponses(true)(opts)
// Assert
if !opts.ValidateResponses {
t.Error("expected ValidateResponses to be true")
}
}
func TestWithSwaggerUIPath(t *testing.T) {
// Arrange
opts := DefaultOptions()
// Act
WithSwaggerUIPath("/api/docs")(opts)
// Assert
if opts.SwaggerUIPath != "/api/docs" {
t.Errorf("expected SwaggerUIPath to be /api-docs, got %s", opts.SwaggerUIPath)
}
}
func TestWithErrorEncoder(t *testing.T) {
// Arrange
opts := DefaultOptions()
customEncoder := func(w http.ResponseWriter, r *http.Request, err error) {}
// Act
WithErrorEncoder(customEncoder)(opts)
// Assert
if opts.ErrorEncoder == nil {
t.Error("expected ErrorEncoder to not be nil")
}
}
func TestWithRouter(t *testing.T) {
// Arrange
opts := DefaultOptions()
// Act
// routers.Router is an interface, we can use nil for just checking if it's set
// but better to check if it's actually assigned
WithRouter(nil)(opts)
// Assert
if opts.Router != nil {
t.Error("expected Router to be nil")
}
}