@@ -230,25 +230,25 @@ func (s HaProxyTestSuite) Test_Provision_ReturnsError_WhenStartFailure() {
230
230
// Reconfigure
231
231
232
232
func (s HaProxyTestSuite ) Test_Reconfigure_ReturnsError_WhenProxyHostIsEmpty () {
233
- err := HaProxy {}.Reconfigure ("" , "" , "" , s .ReconfPort , s .ServiceName , s .Color , s .ServicePath , "" )
233
+ err := HaProxy {}.Reconfigure ("" , "" , "" , s .ReconfPort , s .ServiceName , s .Color , s .ServicePath , "" , "" )
234
234
235
235
s .Error (err )
236
236
}
237
237
238
238
func (s HaProxyTestSuite ) Test_Reconfigure_ReturnsError_WhenProjectIsEmpty () {
239
- err := HaProxy {}.Reconfigure ("" , "" , s .Host , s .ReconfPort , "" , s .Color , s .ServicePath , "" )
239
+ err := HaProxy {}.Reconfigure ("" , "" , s .Host , s .ReconfPort , "" , s .Color , s .ServicePath , "" , "" )
240
240
241
241
s .Error (err )
242
242
}
243
243
244
244
func (s HaProxyTestSuite ) Test_Reconfigure_ReturnsError_WhenServicePathAndConsulTemplatePathAreEmpty () {
245
- err := HaProxy {}.Reconfigure ("" , "" , s .Host , s .ReconfPort , s .ServiceName , s .Color , []string {"" }, "" )
245
+ err := HaProxy {}.Reconfigure ("" , "" , s .Host , s .ReconfPort , s .ServiceName , s .Color , []string {"" }, "" , "" )
246
246
247
247
s .Error (err )
248
248
}
249
249
250
250
func (s HaProxyTestSuite ) Test_Reconfigure_ReturnsError_WhenReconfPortIsEmpty () {
251
- err := HaProxy {}.Reconfigure ("" , "" , s .Host , "" , s .ServiceName , s .Color , s .ServicePath , "" )
251
+ err := HaProxy {}.Reconfigure ("" , "" , s .Host , "" , s .ServiceName , s .Color , s .ServicePath , "" , "" )
252
252
253
253
s .Error (err )
254
254
}
@@ -270,7 +270,7 @@ func (s HaProxyTestSuite) Test_Reconfigure_SendsHttpRequest() {
270
270
return nil , fmt .Errorf ("This is an HTTP error" )
271
271
}
272
272
273
- HaProxy {}.Reconfigure ("" , "" , s .Host , s .ReconfPort , s .ServiceName , s .Color , s .ServicePath , "" )
273
+ HaProxy {}.Reconfigure ("" , "" , s .Host , s .ReconfPort , s .ServiceName , s .Color , s .ServicePath , "" , "" )
274
274
275
275
s .Equal (expected , actual )
276
276
}
@@ -291,7 +291,7 @@ func (s HaProxyTestSuite) Test_Reconfigure_SendsHttpRequestWithOutColor_WhenNotB
291
291
return nil , fmt .Errorf ("This is an HTTP error" )
292
292
}
293
293
294
- HaProxy {}.Reconfigure ("" , "" , s .Host , s .ReconfPort , s .ServiceName , "" , s .ServicePath , "" )
294
+ HaProxy {}.Reconfigure ("" , "" , s .Host , s .ReconfPort , s .ServiceName , "" , s .ServicePath , "" , "" )
295
295
296
296
s .Equal (expected , actual )
297
297
}
@@ -312,7 +312,7 @@ func (s HaProxyTestSuite) Test_Reconfigure_SendsHttpRequestWithPrependedHttp() {
312
312
return nil , fmt .Errorf ("This is an HTTP error" )
313
313
}
314
314
315
- HaProxy {}.Reconfigure ("" , "" , "my-docker-proxy-host.com" , s .ReconfPort , s .ServiceName , "" , s .ServicePath , "" )
315
+ HaProxy {}.Reconfigure ("" , "" , "my-docker-proxy-host.com" , s .ReconfPort , s .ServiceName , "" , s .ServicePath , "" , "" )
316
316
317
317
s .Equal (expected , actual )
318
318
}
@@ -324,7 +324,7 @@ func (s HaProxyTestSuite) Test_Reconfigure_ReturnsError_WhenRequestFails() {
324
324
return nil , fmt .Errorf ("This is an HTTP error" )
325
325
}
326
326
327
- err := HaProxy {}.Reconfigure ("" , "" , s .Host , s .ReconfPort , s .ServiceName , s .Color , s .ServicePath , "" )
327
+ err := HaProxy {}.Reconfigure ("" , "" , s .Host , s .ReconfPort , s .ServiceName , s .Color , s .ServicePath , "" , "" )
328
328
329
329
s .Error (err )
330
330
}
@@ -334,15 +334,15 @@ func (s HaProxyTestSuite) Test_Reconfigure_ReturnsError_WhenResponseCodeIsNot2xx
334
334
w .WriteHeader (http .StatusBadRequest )
335
335
}))
336
336
337
- err := HaProxy {}.Reconfigure ("" , "" , server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "" )
337
+ err := HaProxy {}.Reconfigure ("" , "" , server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "" , "" )
338
338
339
339
s .Error (err )
340
340
}
341
341
342
342
func (s HaProxyTestSuite ) Test_Reconfigure_SetsDockerHost_WhenConsulTemplatePathIsPresent () {
343
343
os .Unsetenv ("DOCKER_HOST" )
344
344
345
- err := HaProxy {}.Reconfigure (s .DockerHost , s .DockerCertPath , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "/path/to/consul/template" )
345
+ err := HaProxy {}.Reconfigure (s .DockerHost , s .DockerCertPath , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "/path/to/consul/fe/template" , "/path/to/consul/be/ template" )
346
346
347
347
s .NoError (err )
348
348
s .Equal (s .DockerHost , os .Getenv ("DOCKER_HOST" ))
@@ -357,7 +357,7 @@ func (s HaProxyTestSuite) Test_Reconfigure_CreatesConsulTemplatesDirectory_WhenC
357
357
return nil
358
358
}
359
359
360
- HaProxy {}.Reconfigure ("" , "" , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "/path/to/consul/template" )
360
+ HaProxy {}.Reconfigure ("" , "" , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "/path/to/consul/fe/template" , "/path/to/consul/be/ template" )
361
361
362
362
s .Equal (expected , actual )
363
363
}
@@ -369,30 +369,38 @@ func (s HaProxyTestSuite) Test_Reconfigure_ReturnsError_WhenDirectoryCreationFai
369
369
return fmt .Errorf ("This is an docker exec error" )
370
370
}
371
371
372
- actual := HaProxy {}.Reconfigure ("" , "" , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "/path/to/consul/template" )
372
+ actual := HaProxy {}.Reconfigure ("" , "" , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "/path/to/consul/fe/template" , "/path/to/consul/be/ template" )
373
373
374
374
s .Error (actual )
375
375
}
376
376
377
- func (s HaProxyTestSuite ) Test_Reconfigure_CopiesTemplate_WhenConsulTemplatePathIsPresent () {
378
- consulTemplatePath := "/path/to/consul/template"
379
- var actual []string
380
- expected := []string {
377
+ func (s HaProxyTestSuite ) Test_Reconfigure_CopiesTemplates_WhenConsulTemplatePathIsPresent () {
378
+ fePath := "/path/to/consul/fe/template"
379
+ bePath := "/path/to/consul/be/template"
380
+ var actual [][]string
381
+ feExpected := []string {
382
+ "docker" ,
383
+ "cp" ,
384
+ fmt .Sprintf ("%s.tmp" , fePath ),
385
+ fmt .Sprintf ("docker-flow-proxy:/consul_templates/%s-fe.tmpl" , s .ServiceName ),
386
+ }
387
+ beExpected := []string {
381
388
"docker" ,
382
389
"cp" ,
383
- fmt .Sprintf ("%s.tmp" , consulTemplatePath ),
384
- fmt .Sprintf ("docker-flow-proxy:/consul_templates/%s.tmpl" , s .ServiceName ),
390
+ fmt .Sprintf ("%s.tmp" , bePath ),
391
+ fmt .Sprintf ("docker-flow-proxy:/consul_templates/%s-be .tmpl" , s .ServiceName ),
385
392
}
386
393
runHaProxyCpCmdOrig := runHaProxyCpCmd
387
394
defer func () { runHaProxyCpCmd = runHaProxyCpCmdOrig }()
388
395
runHaProxyCpCmd = func (cmd * exec.Cmd ) error {
389
- actual = cmd .Args
396
+ actual = append ( actual , cmd .Args )
390
397
return nil
391
398
}
392
399
393
- HaProxy {}.Reconfigure ("" , "" , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "/path/to/consul/template" )
400
+ HaProxy {}.Reconfigure ("" , "" , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , fePath , bePath )
394
401
395
- s .Equal (expected , actual )
402
+ s .Equal (feExpected , actual [0 ])
403
+ s .Equal (beExpected , actual [1 ])
396
404
}
397
405
398
406
func (s HaProxyTestSuite ) Test_Reconfigure_ReturnsError_WhenTemplateCopyFails () {
@@ -402,7 +410,7 @@ func (s HaProxyTestSuite) Test_Reconfigure_ReturnsError_WhenTemplateCopyFails()
402
410
return fmt .Errorf ("This is an docker cp error" )
403
411
}
404
412
405
- actual := HaProxy {}.Reconfigure ("" , "" , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "/path/to/consul/template" )
413
+ actual := HaProxy {}.Reconfigure ("" , "" , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "/path/to/consul/fe/template" , "/path/to/consul/be/ template" )
406
414
407
415
s .Error (actual )
408
416
}
@@ -413,25 +421,28 @@ func (s HaProxyTestSuite) Test_Reconfigure_SendsHttpRequestWithConsulTemplatePat
413
421
actual = fmt .Sprintf ("%s?%s" , r .URL .Path , r .URL .RawQuery )
414
422
}))
415
423
expected := fmt .Sprintf (
416
- "/v1/docker-flow-proxy/reconfigure?serviceName=%s&consulTemplatePath=/consul_templates/%s.tmpl" ,
424
+ "/v1/docker-flow-proxy/reconfigure?serviceName=%s&consulTemplateFePath=/consul_templates/%s-fe.tmpl&consulTemplateBePath=/consul_templates/%s-be.tmpl" ,
425
+ s .ServiceName ,
417
426
s .ServiceName ,
418
427
s .ServiceName ,
419
428
)
420
429
421
- HaProxy {}.Reconfigure ("" , "" , server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "/path/to/consul/template" )
430
+ HaProxy {}.Reconfigure ("" , "" , server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "/path/to/consul/fe/template" , "/path/to/consul/be/ template" )
422
431
423
432
s .Equal (expected , actual )
424
433
}
425
434
426
435
func (s HaProxyTestSuite ) Test_Reconfigure_CreatesTempTemplateFile () {
427
- actualFilename := ""
436
+ fePath := "/path/to/consul/fe/template"
437
+ bePath := "/path/to/consul/be/template"
438
+ var actualFilenames []string
428
439
actualData := ""
429
440
data := "This is a %s template"
430
441
expectedData := fmt .Sprintf (data , s .ServiceName + "-" + s .Color )
431
442
writeFileOrig := writeFile
432
443
defer func () { writeFile = writeFileOrig }()
433
444
writeFile = func (filename string , data []byte , perm os.FileMode ) error {
434
- actualFilename = filename
445
+ actualFilenames = append ( actualFilenames , filename )
435
446
actualData = string (data )
436
447
return nil
437
448
}
@@ -441,9 +452,10 @@ func (s HaProxyTestSuite) Test_Reconfigure_CreatesTempTemplateFile() {
441
452
return []byte (fmt .Sprintf (data , "SERVICE_NAME" )), nil
442
453
}
443
454
444
- HaProxy {}.Reconfigure ("" , "" , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "/path/to/consul/template" )
455
+ HaProxy {}.Reconfigure ("" , "" , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , fePath , bePath )
445
456
446
- s .Equal ("/path/to/consul/template.tmp" , actualFilename )
457
+ s .Equal (fePath + ".tmp" , actualFilenames [0 ])
458
+ s .Equal (bePath + ".tmp" , actualFilenames [1 ])
447
459
s .Equal (expectedData , actualData )
448
460
}
449
461
@@ -454,7 +466,7 @@ func (s HaProxyTestSuite) Test_Reconfigure_ReturnsError_WhenTemplateFileReadFail
454
466
return []byte ("" ), fmt .Errorf ("This is an read file error" )
455
467
}
456
468
457
- err := HaProxy {}.Reconfigure ("" , "" , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "/path/to/consul/template" )
469
+ err := HaProxy {}.Reconfigure ("" , "" , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "/path/to/consul/fe/template" , "/path/to/consul/be/ template" )
458
470
459
471
s .Error (err )
460
472
}
@@ -466,23 +478,27 @@ func (s HaProxyTestSuite) Test_Reconfigure_ReturnsError_WhenTempTemplateFileCrea
466
478
return fmt .Errorf ("This is an write file error" )
467
479
}
468
480
469
- err := HaProxy {}.Reconfigure ("" , "" , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "/path/to/consul/template" )
481
+ err := HaProxy {}.Reconfigure ("" , "" , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "/path/to/consul/fe/template" , "/path/to/consul/be/ template" )
470
482
471
483
s .Error (err )
472
484
}
473
485
474
486
func (s HaProxyTestSuite ) Test_Reconfigure_RemovesTempTemplateFile () {
475
- path := "/path/to/consul/template"
476
- expected := fmt .Sprintf ("%s.tmp" , path )
477
- actual := ""
487
+ fePath := "/path/to/consul/fe/template"
488
+ bePath := "/path/to/consul/be/template"
489
+ expected := []string {
490
+ fmt .Sprintf ("%s.tmp" , fePath ),
491
+ fmt .Sprintf ("%s.tmp" , bePath ),
492
+ }
493
+ var actual []string
478
494
removeFileOrig := removeFile
479
495
defer func () { removeFile = removeFileOrig }()
480
496
removeFile = func (name string ) error {
481
- actual = name
497
+ actual = append ( actual , name )
482
498
return nil
483
499
}
484
500
485
- HaProxy {}.Reconfigure ("" , "" , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , "/path/to/consul/template" )
501
+ HaProxy {}.Reconfigure ("" , "" , s .Server .URL , "" , s .ServiceName , s .Color , s .ServicePath , fePath , bePath )
486
502
487
503
s .Equal (expected , actual )
488
504
}
0 commit comments