@@ -17,13 +17,15 @@ func TestOptions(t *testing.T) {
17
17
logger := log .New ()
18
18
httpPort := 8080
19
19
grpcPort := 8081
20
+ debugPort := 8082
20
21
timeout := 10 * time .Second
21
22
hostname := "another_hostname"
22
23
registry := prometheus .NewRegistry ()
23
24
health := healthcheck .NewHandler ()
24
25
25
26
var opts = []Option {
26
27
WithHostname (hostname ),
28
+ WithDebugPort (debugPort ),
27
29
WithHTTPPort (httpPort ),
28
30
WithGRPCPort (grpcPort ),
29
31
WithLogger (logger ),
@@ -39,34 +41,62 @@ func TestOptions(t *testing.T) {
39
41
hostname : hostname ,
40
42
grpcPort : grpcPort ,
41
43
httpPort : httpPort ,
44
+ debugPort : debugPort ,
42
45
closeTimeout : timeout ,
43
46
metricsRegistry : registry ,
44
47
healthHandler : health ,
45
48
}, cfg )
46
49
}
47
50
48
- func TestWithTTPPort (t * testing.T ) {
49
- t .Run ("negative" , func (t * testing.T ) {
50
- _ , err := evaluateOptions (defaultConfig (), WithHTTPPort (- 1 ))
51
- require .Error (t , err )
52
- })
53
-
54
- t .Run ("zero" , func (t * testing.T ) {
55
- _ , err := evaluateOptions (defaultConfig (), WithHTTPPort (0 ))
51
+ func TestWithHTTPPort (t * testing.T ) {
52
+ for _ , scenario := range []struct {
53
+ Port int
54
+ Expected int
55
+ }{
56
+ {Port : - 1 , Expected : - 1 },
57
+ {Port : 0 , Expected : 0 },
58
+ {Port : 9000 , Expected : 9000 },
59
+ } {
60
+ cfg , err := evaluateOptions (defaultConfig (), WithHTTPPort (scenario .Port ))
56
61
require .NoError (t , err )
57
- })
62
+ require .Equal (t , scenario .Expected , cfg .httpPort )
63
+ }
58
64
}
59
65
60
66
func TestWithGRPCPort (t * testing.T ) {
61
- t .Run ("negative" , func (t * testing.T ) {
62
- _ , err := evaluateOptions (defaultConfig (), WithGRPCPort (- 1 ))
63
- require .Error (t , err )
64
- })
65
-
66
- t .Run ("zero" , func (t * testing.T ) {
67
- _ , err := evaluateOptions (defaultConfig (), WithGRPCPort (0 ))
67
+ for _ , scenario := range []struct {
68
+ Port int
69
+ Expected int
70
+ }{
71
+ {Port : - 1 , Expected : - 1 },
72
+ {Port : 0 , Expected : 0 },
73
+ {Port : 9000 , Expected : 9000 },
74
+ } {
75
+ cfg , err := evaluateOptions (defaultConfig (), WithGRPCPort (scenario .Port ))
68
76
require .NoError (t , err )
69
- })
77
+ require .Equal (t , scenario .Expected , cfg .grpcPort )
78
+ }
79
+ }
80
+
81
+ func TestWithDebugPort (t * testing.T ) {
82
+ for _ , scenario := range []struct {
83
+ Port int
84
+
85
+ Errors bool
86
+ Expected int
87
+ }{
88
+ {Port : - 1 , Errors : true },
89
+ {Port : 0 , Expected : 0 },
90
+ {Port : 9000 , Expected : 9000 },
91
+ } {
92
+ cfg , err := evaluateOptions (defaultConfig (), WithDebugPort (scenario .Port ))
93
+ if scenario .Errors {
94
+ require .Error (t , err )
95
+ continue
96
+ }
97
+
98
+ require .Equal (t , scenario .Expected , cfg .debugPort )
99
+ }
70
100
}
71
101
72
102
func TestLogger_ErrorsWithNilLogger (t * testing.T ) {
0 commit comments