-
Notifications
You must be signed in to change notification settings - Fork 59
/
ergo_run_test.go
792 lines (627 loc) · 19.3 KB
/
ergo_run_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
//go:build integration
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
"github.com/cristianoliveira/ergo/commands/setup"
)
var initialSetup interface{}
func ergo(args ...string) *exec.Cmd {
return exec.Command(filepath.Join("..", "bin", "ergo"), args...)
}
type config struct {
filePath string
}
func (c config) clean() error {
return os.Remove(c.filePath)
}
func newConfigFromFile(configFile string) (config, error) {
c := config{}
file, err := ioutil.TempFile(os.TempDir(), "ergoconfig")
if err != nil {
return c, fmt.Errorf("Unable to create tmpfile: %v", err)
}
defer file.Close()
fileContent, err := ioutil.ReadFile(configFile)
if err != nil {
return c, fmt.Errorf("unable to read configuration content: %v", err)
}
_, err = file.Write(fileContent)
if err != nil {
return c, fmt.Errorf("Unable to write configuration content to temp file: %v", err)
}
c.filePath = file.Name()
return c, nil
}
func TestListApps(t *testing.T) {
t.Run("it lists the apps", func(tt *testing.T) {
appsOutput := []string{
"http://foo.dev -> http://localhost:3000",
"http://bla.dev -> http://localhost:5000",
"http://withspaces.dev -> http://localhost:8080",
"http://one.domain.dev -> http://localhost:8081",
"http://two.domain.dev -> http://localhost:8082",
"http://withextraspace.dev -> http://localhost:2222",
"http://redislocal.dev -> redis://localhost:6543",
}
cmd := ergo("list")
bs, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
output := string(bs)
for _, app := range appsOutput {
if !strings.Contains(output, app) {
tt.Errorf("Expected output:\n %s \n got %s", output, app)
}
}
})
}
func TestListAppNames(t *testing.T) {
t.Run("it lists the app names", func(tt *testing.T) {
appsOutput := []string{
"foo -> http://localhost:3000",
"bla -> http://localhost:5000",
"withspaces -> http://localhost:8080",
"one.domain -> http://localhost:8081",
"two.domain -> http://localhost:8082",
"redislocal -> redis://localhost:6543",
}
cmd := ergo("list-names", "foo")
bs, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
output := string(bs)
for _, app := range appsOutput {
if !strings.Contains(output, app) {
tt.Errorf("Expected output:\n %s \n got %s", output, app)
}
}
})
}
func TestShowUrlForName(t *testing.T) {
t.Run("it shows the url for a given name", func(tt *testing.T) {
appsOutput := map[string]string{
"foo": "http://foo.dev",
"bla": "http://bla.dev",
"withspaces": "http://withspaces.dev",
"one.domain": "http://one.domain.dev",
"two.domain": "http://two.domain.dev",
// FIXME URL should be redis://localhost:6543
"redislocal": "http://redislocal.dev",
}
for name, url := range appsOutput {
cmd := ergo("url", name)
bs, err := cmd.Output()
if err != nil {
tt.Fatal(err)
}
output := string(bs)
if strings.Trim(output, " \r\n") != url {
tt.Errorf("Expected output:\n [%s] \n got [%s]", url, strings.Trim(output, " \r\n"))
}
}
})
}
func TestAddService(t *testing.T) {
t.Run("it adds new service if not present", func(tt *testing.T) {
appsOutput := fmt.Sprintf("%s\n", "Service added successfully")
c, err := newConfigFromFile("./.ergo")
if err != nil {
tt.Fatalf("Unable to copy config file: %v", err)
}
defer c.clean()
cmd := ergo("add", "new.service", "http://localhost:8083", "-config", c.filePath)
bs, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
output := string(bs)
if strings.Compare(output, appsOutput) != 0 {
tt.Errorf("Expected output: '%s' \n got '%s'", appsOutput, output)
}
})
t.Run("it prints message for already added service", func(tt *testing.T) {
appsOutput := fmt.Sprintf("%s\n", "Service already present")
cmd := ergo("add", "foo", "http://localhost:3000")
bs, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
output := string(bs)
if strings.Compare(output, appsOutput) != 0 {
tt.Errorf("Expected output:\n '%s' \n got '%s'", appsOutput, output)
}
})
}
// functions needed for setup and run testing
func getOS() *string {
var runOS string
//we setup the right runtime
if runtime.GOOS == "windows" {
runOS = "windows"
} else if runtime.GOOS == "linux" {
//here we only have the tests for gnome
runOS = "linux-gnome"
} else if runtime.GOOS == "darwin" {
runOS = "osx"
}
return &runOS
}
func setupErgoWithTempConfig(configFilePath string) (config, error) {
c, err := newConfigFromFile(configFilePath)
if err != nil {
c.clean()
return c, err
}
err = setupErgo(c.filePath)
return c, err
}
func setupErgo(configFilePath string) error {
var err error
runOS := getOS()
//we need to store the initial values to make sure they are restored
//linux-gnome
if *runOS == "linux-gnome" {
var mode string
var autoconfigURL string
mode, err = getLinuxGnomeProxyMode()
if err != nil {
return err
}
autoconfigURL, err = getLinuxGnomeProxyAutoConfig()
if err != nil {
return err
}
initialSetup = struct {
mode string
autoconfigURL string
}{mode: mode, autoconfigURL: autoconfigURL}
}
//osx
if *runOS == "osx" {
var autoconfigURL string
autoconfigURL, err = getDarwinProxyAutoURL()
if err != nil {
return err
}
initialSetup = struct{ autoconfigURL string }{autoconfigURL: autoconfigURL}
}
//windows
if *runOS == "windows" {
var autoconfigURL string
autoconfigURL, err = getWindowsProxyAutoURL()
if err != nil {
return err
}
initialSetup = struct{ autoconfigURL string }{autoconfigURL: autoconfigURL}
}
if runOS != nil {
log.Println("starting setup " + *runOS)
cmd := ergo("setup", "-config", configFilePath, *runOS)
_, err := cmd.Output()
if err != nil {
return fmt.Errorf("Unable to run ergo setup: %v", err)
}
}
return nil
}
func removeSetupErgo() *exec.Cmd {
runOS := getOS()
if runOS != nil {
return ergo("setup", *runOS, "-remove")
}
return nil
}
func cleanSetup() error {
runOS := getOS()
//if initialSetup is not set, then the initial setup failed and there is no point
//trying to clean after it, anyway we can't since we do not have the initial info
if initialSetup == nil {
return nil
}
//we need to store the initial values to make sure they are restored
//linux-gnome
if *runOS == "linux-gnome" {
s := initialSetup.(struct {
mode string
autoconfigURL string
})
return clearLinuxSetup(s.mode, s.autoconfigURL)
}
//osx
if *runOS == "osx" {
s := initialSetup.(struct{ autoconfigURL string })
return clearDarwinSetup(s.autoconfigURL)
}
//windows
if *runOS == "windows" {
s := initialSetup.(struct{ autoconfigURL string })
err := clearWindowsSetup(s.autoconfigURL)
if err != nil {
return err
}
setup.InetRefresh()
}
return nil
}
func getCommandResult(command string, args ...string) (string, error) {
cmd := exec.Command(command, args...)
rez, err := cmd.Output()
return string(rez), err
}
func getLinuxGnomeProxyMode() (string, error) {
return getCommandResult("gsettings", "get", "org.gnome.system.proxy", "mode")
}
func getLinuxGnomeProxyAutoConfig() (string, error) {
return getCommandResult("gsettings", "get", "org.gnome.system.proxy", "autoconfig-url")
}
func clearLinuxSetup(mode string, autoconfigURL string) error {
_, err := getCommandResult("gsettings", "set", "org.gnome.system.proxy", "mode", "'"+mode+"'")
if err != nil {
if err.Error() != "exit status 1" {
return err
} else {
return nil
}
}
_, err = getCommandResult("gsettings", "set", "org.gnome.system.proxy", "autoconfig-url", "'"+autoconfigURL+"'")
return err
}
func getDarwinProxyAutoURL() (string, error) {
return getCommandResult("sudo", "networksetup", "-getautoproxyurl", "\"Wi-Fi\"")
}
func clearDarwinSetup(autoconfigURL string) error {
_, err := getCommandResult("sudo", "networksetup", "-setautoproxyurl", "\"Wi-Fi\"", "'"+autoconfigURL+"'")
return err
}
func getWindowsProxyAutoURL() (string, error) {
rez, err := getCommandResult("reg", "query", "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "/v", "AutoconfigURL")
//it is nromal to get an exit status 1 if we do not yet have the key in the registry
if err != nil && err.Error() != "exit status 1" {
return "", err
}
return rez, nil
}
func clearWindowsSetup(autoconfigURL string) error {
var err error
if autoconfigURL != "" {
_, err = getCommandResult("reg", "delete", `HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings`, "/v", "AutoConfigURL", "/f")
} else {
_, err = getCommandResult("reg", "add", `HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings`, "/v", "AutoConfigURL", "/t", "REG_SZ", "/d", autoconfigURL, "/f")
}
return err
}
func TestSetupLinuxGnome(t *testing.T) {
t.Skip("Travis CI has blocked access to networking changes and this has been failing since. We going to ignore it for now")
if *getOS() != "linux-gnome" {
t.Skip("Not running linux-gnome setup specific tests")
}
err := setupErgo("./.ergo")
if err != nil {
if err.Error() != "exit status 1" {
t.Fatalf("Could not perform setup for linux-gnome. Got %s", err.Error())
}
t.Skipf("Skipping test as gsettings does not exist on this system.")
}
defer cleanSetup()
ac, err := getLinuxGnomeProxyAutoConfig()
if err != nil {
t.Fatalf("No error expected while getting AutoconfigURL from gsettings. Got: %s, %s\r\n", err.Error(), ac)
}
if !strings.Contains(ac, "http://127.0.0.1:2000/proxy.pac") {
t.Fatalf("Expected to find \"http://127.0.0.1:2000/proxy.pac\" as part of the AutoconfigURL. Got \"%s\"\r\n", ac)
}
mode, err := getLinuxGnomeProxyMode()
if err != nil {
t.Fatalf("No error expected while getting \"mode\" from gsettings. Got: %s, %s\r\n", err.Error(), mode)
}
if strings.Contains(mode, "none") {
t.Fatalf("Expected to find a mode different then \"none\". Got \"%s\"\r\n", mode)
}
}
func TestSetupOSX(t *testing.T) {
if *getOS() != "osx" {
t.Skip("Not running osx setup specific tests")
}
err := setupErgo("./.ergo")
if err != nil {
t.Skipf("Please fix this for osx")
//t.Fatalf("Could not perform setup for osx. Got %s", err.Error())
}
defer cleanSetup()
ac, err := getDarwinProxyAutoURL()
if err != nil {
t.Fatalf("No error expected while getting AutoconfigURL from osx. Got: %s, %s\r\n", err.Error(), ac)
}
if !strings.Contains(ac, "http://127.0.0.1:2000/proxy.pac") {
t.Fatalf("Expected to find \"http://127.0.0.1:2000/proxy.pac\" as part of the AutoconfigURL. Got \"%s\"\r\n", ac)
}
}
func TestSetupWindows(t *testing.T) {
if *getOS() != "windows" {
t.Skip("Not running windows setup specific tests")
}
err := setupErgo("./.ergo")
if err != nil {
t.Fatalf("Could not perform setup for windows. Got %s", err.Error())
}
defer cleanSetup()
rez, err := getWindowsProxyAutoURL()
if err != nil {
t.Fatalf("No error expected while getting AutoconfigURL from registry. Got: %s, %s\r\n", err.Error(), rez)
}
if !strings.Contains(rez, "http://127.0.0.1:2000/proxy.pac") {
t.Fatalf("Expected to find \"http://127.0.0.1:2000/proxy.pac\" as part of the AutoconfigURL. Got \"%s\"\r\n", rez)
}
}
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "ergo test response")
}
//please change the ports if you change .ergo file
//the server will be closed when the test finishes
//not programatically
//Perhaps a programatic approach should be used later
func startTestWebServer() {
http.HandleFunc("/", handler)
go func() {
http.ListenAndServe(":5000", nil)
}()
}
//On windows please open port 9090 for this to work
func startDynamicTestWebServer() {
http.HandleFunc("/dyn", handler)
go func() {
http.ListenAndServe(":9090", nil)
}()
}
//Please be aware that for windows you should have ports
//2000 : ergo proxy
// and
//5000 : test web server
//opened in
//the firewall for this test to work
func TestRunWindows(t *testing.T) {
if *getOS() != "windows" {
t.Skip("Not running windows run specific tests")
}
err := setupErgo("./.ergo")
if err != nil {
t.Fatalf("Could not perform setup for windows. Got %s", err.Error())
}
defer cleanSetup()
startTestWebServer()
cmd := ergo("run")
defer func() {
if cmd != nil && cmd.Process != nil {
cmd.Process.Kill()
}
}()
go func() {
cmd.Run()
}()
time.Sleep(2 * time.Second)
//it would be much easier to use Invoke-WebRequest, but using this makes it compatible with
//powershell 2.0 (windows 7)
rez, err := getCommandResult("powershell", "-c", "$proxy=[System.Net.WebRequest]::GetSystemWebProxy();",
"$webclient=new-object system.net.webclient;", "$webclient.proxy=$proxy;",
"$webclient.DownloadString('http://bla.dev')")
if err != nil {
t.Fatalf("Expected no error while requesting http://bla.dev, Got %s\r\n", err.Error())
}
if strings.Trim(rez, " \r\n") != "ergo test response" {
t.Fatalf("Expected \"ergo test response\" as response and got: %s\r\n", rez)
}
}
func TestRunLinuxGnome(t *testing.T) {
if *getOS() != "linux-gnome" {
t.Skip("Not running linux-gnome run specific tests")
}
err := setupErgo("./.ergo")
//exit status 1 means that gsettings was not found. So if linux is not really gnome, this will fails otherwise
if err != nil && err.Error() != "exit status 1" {
t.Fatalf("Could not perform setup for linux-gnome. Got %s", err.Error())
}
defer cleanSetup()
startTestWebServer()
cmd := ergo("run")
defer func() {
if cmd != nil && cmd.Process != nil {
cmd.Process.Kill()
}
}()
go func() {
cmd.Run()
}()
time.Sleep(2 * time.Second)
//it would be better perhaps to use a brower like chrome-headless
rez, err := getCommandResult("./testCurl.sh")
if err != nil {
t.Fatalf("Expected no error while requesting http://bla.dev, Got %s\r\n", err.Error())
}
if strings.Trim(rez, " \r\n") != "ergo test response" {
t.Fatalf("Expected \"ergo test response\" as response and got: %s\r\n", rez)
}
}
func TestRunOSX(t *testing.T) {
if *getOS() != "osx" {
t.Skip("Not running osx run specific tests")
}
err := setupErgo("./.ergo")
if err != nil {
t.Skip("Please fix this ... mac people")
}
defer cleanSetup()
startTestWebServer()
cmd := ergo("run")
defer func() {
if cmd != nil && cmd.Process != nil {
cmd.Process.Kill()
}
}()
go func() {
cmd.Run()
}()
time.Sleep(2 * time.Second)
//it would be better perhaps to use a brower like chrome-headless
rez, err := getCommandResult("./testCurl.sh")
if err != nil {
t.Fatalf("Expected no error while requesting http://bla.dev, Got %s\r\n", err.Error())
}
if strings.Trim(rez, " \r\n") != "ergo test response" {
t.Fatalf("Expected \"ergo test response\" as response and got: %s\r\n", rez)
}
}
func TestConfigDynamicWindows(t *testing.T) {
if *getOS() != "windows" {
t.Skip("Not running windows run specific tests")
}
c, err := setupErgoWithTempConfig("./.ergo")
if err != nil {
t.Fatalf("Could not perform setup for windows. Got %s", err.Error())
}
defer c.clean()
defer cleanSetup()
//start a web server that will initially have no mapping in our proxy
startDynamicTestWebServer()
cmd := ergo("run", "-config", c.filePath)
defer func() {
if cmd != nil && cmd.Process != nil {
cmd.Process.Kill()
}
}()
go func() {
cmd.Run()
}()
//wait for it to be sure it started
time.Sleep(2 * time.Second)
//we should not have a correct response
rez, err := getCommandResult("powershell", "-c", "$proxy=[System.Net.WebRequest]::GetSystemWebProxy();",
"$webclient=new-object system.net.webclient;", "$webclient.proxy=$proxy;",
"$webclient.DownloadString('http://dynamic.dev')")
//on windows we should get an error here
if err == nil {
t.Fatal("Expected error while requesting http://dynamic.dev, Got nil\r\n")
}
f, err := os.OpenFile(c.filePath, os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
t.Fatal("Could not write on the config file")
}
defer f.Close()
if _, err = f.WriteString("dynamic http://localhost:9090"); err != nil {
panic(err)
}
time.Sleep(1 * time.Second)
rez, err = getCommandResult("powershell", "-c", "$proxy=[System.Net.WebRequest]::GetSystemWebProxy();",
"$webclient=new-object system.net.webclient;", "$webclient.proxy=$proxy;",
"$webclient.DownloadString('http://dynamic.dev')")
if err != nil {
t.Fatalf("Expected no error while asking for an added config. Got %s\r\n", err.Error())
}
if strings.Trim(rez, " \r\n") != "ergo test response" {
t.Fatalf("Expected \"ergo test response\" as response and got: %s\r\n", rez)
}
}
func TestConfigDynamicLinuxGnome(t *testing.T) {
t.Skip("Travis CI has blocked access to networking changes and this has been failing since. We going to ignore it for now")
if *getOS() != "linux-gnome" {
t.Skip("Not running linux-gnome run specific tests")
}
c, err := setupErgoWithTempConfig("./.ergo")
if err != nil && err.Error() != "exit status 1" {
t.Fatalf("Could not perform setup for linux-gnome: %v", err)
}
defer c.clean()
defer cleanSetup()
startDynamicTestWebServer()
cmd := ergo("run", "-config", c.filePath)
defer func() {
if cmd != nil && cmd.Process != nil {
cmd.Process.Kill()
}
}()
go func() {
cmd.Run()
}()
time.Sleep(2 * time.Second)
//it would be better perhaps to use a brower like chrome-headless
rez, err := getCommandResult("./testCurlNotExisting.sh")
if err != nil {
t.Fatalf("Expected no error while requesting http://dynamic.dev, Got %s\r\n", err.Error())
}
if rez == "ergo test response" {
t.Fatalf("Expected different response while asking for http://dynamic.dev, Got %s\r\n", rez)
}
f, err := os.OpenFile(c.filePath, os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
t.Fatal("Could not write on the config file")
}
defer f.Close()
if _, err = f.WriteString("dynamic http://localhost:9090/dyn"); err != nil {
panic(err)
}
time.Sleep(2 * time.Second)
rez, err = getCommandResult("./testCurlNotExisting.sh")
if err != nil {
t.Fatalf("Expected no error while asking for an added config. Got %s\r\n", err.Error())
}
if strings.Trim(rez, " \r\n") != "ergo test response" {
t.Fatalf("Expected \"ergo test response\" as response and got: %s\r\n", rez)
}
}
func TestConfigDynamicOSX(t *testing.T) {
if *getOS() != "osx" {
t.Skip("Not running osx run specific tests")
}
c, err := setupErgoWithTempConfig("./.ergo")
if err != nil {
t.Skip("Please fix this ... mac people")
}
defer c.clean()
defer cleanSetup()
startDynamicTestWebServer()
cmd := ergo("run", "-config", c.filePath)
defer func() {
if cmd != nil && cmd.Process != nil {
cmd.Process.Kill()
}
}()
go func() {
cmd.Run()
}()
time.Sleep(2 * time.Second)
//it would be better perhaps to use a brower like chrome-headless
rez, err := getCommandResult("./testCurl.sh")
if err != nil {
t.Fatalf("Expected no error while requesting http://dynamic.dev, Got %s\r\n", err.Error())
}
if rez == "ergo test response" {
t.Fatalf("Expected different response while asking for http://dynamic.dev, Got %s\r\n", rez)
}
f, err := os.OpenFile(c.filePath, os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
t.Fatal("Could not write on the config file")
}
defer f.Close()
if _, err = f.WriteString("dynamic http://localhost:9090/dyn"); err != nil {
panic(err)
}
time.Sleep(1 * time.Second)
rez, err = getCommandResult("./testCurlNotExisting.sh")
if err != nil {
t.Fatalf("Expected no error while asking for an added config. Got %s\r\n", err.Error())
}
if strings.Trim(rez, " \r\n") != "ergo test response" {
t.Fatalf("Expected \"ergo test response\" as response and got: %s\r\n", rez)
}
}