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