9
9
"net/http"
10
10
"os"
11
11
"path/filepath"
12
+ "runtime"
12
13
"testing"
13
14
"time"
14
15
@@ -18,14 +19,20 @@ import (
18
19
"go.uber.org/zap/zapcore"
19
20
)
20
21
22
+ func simpleError (err string ) func () string {
23
+ return func () string {
24
+ return err
25
+ }
26
+ }
27
+
21
28
func TestValidate (t * testing.T ) {
22
29
tlsConfig := configtls .NewDefaultClientConfig ()
23
30
tlsConfig .InsecureSkipVerify = true
24
31
25
32
testCases := []struct {
26
- name string
27
- config Supervisor
28
- expectedError string
33
+ name string
34
+ config Supervisor
35
+ expectedErrorFunc func () string
29
36
}{
30
37
{
31
38
name : "Valid filled out config" ,
@@ -42,6 +49,7 @@ func TestValidate(t *testing.T) {
42
49
OrphanDetectionInterval : 5 * time .Second ,
43
50
ConfigApplyTimeout : 2 * time .Second ,
44
51
BootstrapTimeout : 5 * time .Second ,
52
+ UseHUPConfigReload : false ,
45
53
},
46
54
Capabilities : Capabilities {
47
55
AcceptsRemoteConfig : true ,
@@ -72,7 +80,7 @@ func TestValidate(t *testing.T) {
72
80
Directory : "/etc/opamp-supervisor/storage" ,
73
81
},
74
82
},
75
- expectedError : "server::endpoint must be specified" ,
83
+ expectedErrorFunc : simpleError ( "server::endpoint must be specified" ) ,
76
84
},
77
85
{
78
86
name : "Invalid URL" ,
@@ -96,7 +104,7 @@ func TestValidate(t *testing.T) {
96
104
Directory : "/etc/opamp-supervisor/storage" ,
97
105
},
98
106
},
99
- expectedError : "invalid URL for server::endpoint:" ,
107
+ expectedErrorFunc : simpleError ( "invalid URL for server::endpoint:" ) ,
100
108
},
101
109
{
102
110
name : "Invalid endpoint scheme" ,
@@ -120,7 +128,7 @@ func TestValidate(t *testing.T) {
120
128
Directory : "/etc/opamp-supervisor/storage" ,
121
129
},
122
130
},
123
- expectedError : `invalid scheme "tcp" for server::endpoint, must be one of "http", "https", "ws", or "wss"` ,
131
+ expectedErrorFunc : simpleError ( `invalid scheme "tcp" for server::endpoint, must be one of "http", "https", "ws", or "wss"` ) ,
124
132
},
125
133
{
126
134
name : "Invalid tls settings" ,
@@ -150,7 +158,7 @@ func TestValidate(t *testing.T) {
150
158
Directory : "/etc/opamp-supervisor/storage" ,
151
159
},
152
160
},
153
- expectedError : "invalid server::tls settings:" ,
161
+ expectedErrorFunc : simpleError ( "invalid server::tls settings:" ) ,
154
162
},
155
163
{
156
164
name : "Empty agent executable path" ,
@@ -175,7 +183,7 @@ func TestValidate(t *testing.T) {
175
183
Directory : "/etc/opamp-supervisor/storage" ,
176
184
},
177
185
},
178
- expectedError : "agent::executable must be specified" ,
186
+ expectedErrorFunc : simpleError ( "agent::executable must be specified" ) ,
179
187
},
180
188
{
181
189
name : "agent executable does not exist" ,
@@ -200,7 +208,7 @@ func TestValidate(t *testing.T) {
200
208
Directory : "/etc/opamp-supervisor/storage" ,
201
209
},
202
210
},
203
- expectedError : "could not stat agent::executable path:" ,
211
+ expectedErrorFunc : simpleError ( "could not stat agent::executable path:" ) ,
204
212
},
205
213
{
206
214
name : "Invalid orphan detection interval" ,
@@ -224,7 +232,7 @@ func TestValidate(t *testing.T) {
224
232
Directory : "/etc/opamp-supervisor/storage" ,
225
233
},
226
234
},
227
- expectedError : "agent::orphan_detection_interval must be positive" ,
235
+ expectedErrorFunc : simpleError ( "agent::orphan_detection_interval must be positive" ) ,
228
236
},
229
237
{
230
238
name : "Zero value health check port number" ,
@@ -297,7 +305,7 @@ func TestValidate(t *testing.T) {
297
305
Directory : "/etc/opamp-supervisor/storage" ,
298
306
},
299
307
},
300
- expectedError : "agent::bootstrap_timeout must be positive" ,
308
+ expectedErrorFunc : simpleError ( "agent::bootstrap_timeout must be positive" ) ,
301
309
},
302
310
{
303
311
name : "Invalid opamp server port number" ,
@@ -322,7 +330,7 @@ func TestValidate(t *testing.T) {
322
330
Directory : "/etc/opamp-supervisor/storage" ,
323
331
},
324
332
},
325
- expectedError : "agent::opamp_server_port must be a valid port number" ,
333
+ expectedErrorFunc : simpleError ( "agent::opamp_server_port must be a valid port number" ) ,
326
334
},
327
335
{
328
336
name : "Zero value opamp server port number" ,
@@ -371,7 +379,38 @@ func TestValidate(t *testing.T) {
371
379
Directory : "/etc/opamp-supervisor/storage" ,
372
380
},
373
381
},
374
- expectedError : "agent::config_apply_timeout must be valid duration" ,
382
+ expectedErrorFunc : simpleError ("agent::config_apply_timeout must be valid duration" ),
383
+ },
384
+ {
385
+ name : "HUP config reload not supported on Windows" ,
386
+ config : Supervisor {
387
+ Server : OpAMPServer {
388
+ Endpoint : "wss://localhost:9090/opamp" ,
389
+ Headers : http.Header {
390
+ "Header1" : []string {"HeaderValue" },
391
+ },
392
+ TLS : tlsConfig ,
393
+ },
394
+ Agent : Agent {
395
+ Executable : "${file_path}" ,
396
+ OrphanDetectionInterval : 5 * time .Second ,
397
+ ConfigApplyTimeout : 2 * time .Second ,
398
+ BootstrapTimeout : 5 * time .Second ,
399
+ UseHUPConfigReload : true ,
400
+ },
401
+ Capabilities : Capabilities {
402
+ AcceptsRemoteConfig : true ,
403
+ },
404
+ Storage : Storage {
405
+ Directory : "/etc/opamp-supervisor/storage" ,
406
+ },
407
+ },
408
+ expectedErrorFunc : func () string {
409
+ if runtime .GOOS != "windows" {
410
+ return ""
411
+ }
412
+ return "agent::use_hup_config_reload is not supported on Windows"
413
+ },
375
414
},
376
415
}
377
416
@@ -394,10 +433,10 @@ func TestValidate(t *testing.T) {
394
433
395
434
err := tc .config .Validate ()
396
435
397
- if tc .expectedError = = "" {
398
- require .NoError (t , err )
436
+ if tc .expectedErrorFunc != nil && tc . expectedErrorFunc () ! = "" {
437
+ require .ErrorContains (t , err , tc . expectedErrorFunc () )
399
438
} else {
400
- require .ErrorContains (t , err , tc . expectedError )
439
+ require .NoError (t , err )
401
440
}
402
441
})
403
442
}
0 commit comments