@@ -17,7 +17,7 @@ func TestCORS(t *testing.T) {
17
17
req .Header .Set ("Access-Control-Request-Method" , "GET" )
18
18
req .Header .Set ("Access-Control-Request-Headers" , "Content-Type" )
19
19
t .Run ("enabled" , func (t * testing.T ) {
20
- rsp := do (t , & Options { EnableCORS : true }, "" , "/" , nil , req )
20
+ rsp := do (t , [] Option { OptEnableCORS }, "" , "/" , nil , req )
21
21
assert .Equal (t , http .StatusOK , rsp .Code )
22
22
})
23
23
t .Run ("disabled" , func (t * testing.T ) {
@@ -45,17 +45,20 @@ func TestHealthEndpoint(t *testing.T) {
45
45
require .NoError (t , err )
46
46
47
47
scenarios := map [string ]struct {
48
- opts * Options
48
+ opts [] Option
49
49
code int
50
50
}{
51
- "disabled" : {& Options { HealthCheckPath : "" }, http .StatusNotFound },
52
- "default" : {& Options { HealthCheckPath : "/health" }, http .StatusOK },
53
- "custom" : {& Options {
54
- HealthCheckPath : "/health" ,
55
- HealthChecker : func (_ http.ResponseWriter , r * http.Request ) * HTTPError {
51
+ "disabled" : {[] Option { OptHealthCheck ( "" , nil ) }, http .StatusNotFound },
52
+ "default" : {[] Option { OptHealthCheck ( "/health" , nil ) }, http .StatusOK },
53
+ "custom" : {[] Option { OptHealthCheck (
54
+ "/health" ,
55
+ func (_ http.ResponseWriter , r * http.Request ) * HTTPError {
56
56
return UnauthorizedError ("" )
57
- }}, http .StatusUnauthorized },
57
+ })},
58
+ http .StatusUnauthorized },
58
59
}
60
+
61
+
59
62
for name , scene := range scenarios {
60
63
t .Run (name , func (t * testing.T ) {
61
64
rsp := do (t , scene .opts , "" , "/" , nil , req )
@@ -79,20 +82,18 @@ func TestVersionHeader(t *testing.T) {
79
82
for name , scene := range scenes {
80
83
81
84
t .Run (name , func (t * testing.T ) {
82
- opts := & Options {
83
- Version : scene .version ,
84
- }
85
+ opts := []Option {OptVersionHeader (scene .svc , scene .version )}
85
86
rsp := do (t , opts , scene .svc , "/" , nil , req )
86
87
assert .Equal (t , scene .expected , rsp .Header ().Get (scene .header ), t .Name ())
87
88
})
88
89
}
89
90
}
90
91
91
- func do (t * testing.T , opts * Options , svcName , path string , handler APIHandler , req * http.Request ) * httptest.ResponseRecorder {
92
+ func do (t * testing.T , opts [] Option , svcName , path string , handler APIHandler , req * http.Request ) * httptest.ResponseRecorder {
92
93
if opts == nil {
93
- opts = new ( Options )
94
+ opts = [] Option {}
94
95
}
95
- r := New (svcName , logrus .WithField ("test" , t .Name ()), * opts )
96
+ r := New (logrus .WithField ("test" , t .Name ()), opts ... )
96
97
97
98
if handler == nil {
98
99
handler = func (w http.ResponseWriter , r * http.Request ) * HTTPError {
0 commit comments