@@ -249,6 +249,13 @@ func TestPrintURLsForService(t *testing.T) {
249
249
tmpl : defaultTemplate ,
250
250
expectedOutput : []string {"http://127.0.0.1:1111" , "http://127.0.0.1:2222" },
251
251
},
252
+ {
253
+ description : "should get all node ports with arbitrary format" ,
254
+ serviceName : "mock-dashboard" ,
255
+ namespace : "default" ,
256
+ tmpl : template .Must (template .New ("svc-arbitrary-template" ).Parse ("{{.IP}}:{{.Port}}" )),
257
+ expectedOutput : []string {"127.0.0.1:1111" , "127.0.0.1:2222" },
258
+ },
252
259
{
253
260
description : "empty slice for no node ports" ,
254
261
serviceName : "mock-dashboard-no-ports" ,
@@ -279,6 +286,63 @@ func TestPrintURLsForService(t *testing.T) {
279
286
}
280
287
}
281
288
289
+ func TestOptionallyHttpsFormattedUrlString (t * testing.T ) {
290
+
291
+ var tests = []struct {
292
+ description string
293
+ bareUrlString string
294
+ https bool
295
+ expectedHttpsFormattedUrlString string
296
+ expectedIsHttpSchemedURL bool
297
+ }{
298
+ {
299
+ description : "no https for http schemed with no https option" ,
300
+ bareUrlString : "http://192.168.99.100:30563" ,
301
+ https : false ,
302
+ expectedHttpsFormattedUrlString : "http://192.168.99.100:30563" ,
303
+ expectedIsHttpSchemedURL : true ,
304
+ },
305
+ {
306
+ description : "no https for non-http schemed with no https option" ,
307
+ bareUrlString : "xyz.http.myservice:30563" ,
308
+ https : false ,
309
+ expectedHttpsFormattedUrlString : "xyz.http.myservice:30563" ,
310
+ expectedIsHttpSchemedURL : false ,
311
+ },
312
+ {
313
+ description : "https for http schemed with https option" ,
314
+ bareUrlString : "http://192.168.99.100:30563" ,
315
+ https : true ,
316
+ expectedHttpsFormattedUrlString : "https://192.168.99.100:30563" ,
317
+ expectedIsHttpSchemedURL : true ,
318
+ },
319
+ {
320
+ description : "no https for non-http schemed with https option and http substring" ,
321
+ bareUrlString : "xyz.http.myservice:30563" ,
322
+ https : true ,
323
+ expectedHttpsFormattedUrlString : "xyz.http.myservice:30563" ,
324
+ expectedIsHttpSchemedURL : false ,
325
+ },
326
+ }
327
+
328
+ for _ , test := range tests {
329
+ test := test
330
+ t .Run (test .description , func (t * testing.T ) {
331
+ t .Parallel ()
332
+ httpsFormattedUrlString , isHttpSchemedURL := OptionallyHttpsFormattedUrlString (test .bareUrlString , test .https )
333
+
334
+ if httpsFormattedUrlString != test .expectedHttpsFormattedUrlString {
335
+ t .Errorf ("\n httpsFormattedUrlString, Expected %v \n Actual: %v \n \n " , test .expectedHttpsFormattedUrlString , httpsFormattedUrlString )
336
+ }
337
+
338
+ if isHttpSchemedURL != test .expectedIsHttpSchemedURL {
339
+ t .Errorf ("\n isHttpSchemedURL, Expected %v \n Actual: %v \n \n " ,
340
+ test .expectedHttpsFormattedUrlString , httpsFormattedUrlString )
341
+ }
342
+ })
343
+ }
344
+ }
345
+
282
346
func TestGetServiceURLs (t * testing.T ) {
283
347
defaultAPI := & tests.MockAPI {
284
348
Hosts : map [string ]* host.Host {
0 commit comments