@@ -13,32 +13,54 @@ import (
13
13
"github.com/abronan/valkeyrie/store/etcd/v3"
14
14
"github.com/containous/traefik/integration/try"
15
15
"github.com/go-check/check"
16
-
17
16
checker "github.com/vdemeester/shakers"
18
17
)
19
18
20
19
const (
21
- // Services IP addresses fixed in the configuration
22
- ipEtcd = "172.18.0.2"
23
- ipWhoami01 = "172.18.0.3"
24
- ipWhoami02 = "172.18.0.4"
25
- ipWhoami03 = "172.18.0.5"
26
- ipWhoami04 = "172.18.0.6"
27
-
28
20
traefikEtcdURL = "http://127.0.0.1:8000/"
29
21
traefikWebEtcdURL = "http://127.0.0.1:8081/"
30
22
)
31
23
24
+ var (
25
+ ipEtcd string
26
+ ipWhoami01 string
27
+ ipWhoami02 string
28
+ ipWhoami03 string
29
+ ipWhoami04 string
30
+ )
31
+
32
32
// Etcd test suites (using libcompose)
33
33
type Etcd3Suite struct {
34
34
BaseSuite
35
35
kv store.Store
36
36
}
37
37
38
- func (s * Etcd3Suite ) SetUpTest (c * check.C ) {
38
+ func (s * Etcd3Suite ) getIPAddress (c * check.C , service , defaultIP string ) string {
39
+ var ip string
40
+ for _ , value := range s .composeProject .Container (c , service ).NetworkSettings .Networks {
41
+ if len (value .IPAddress ) > 0 {
42
+ ip = value .IPAddress
43
+ break
44
+ }
45
+ }
46
+
47
+ if len (ip ) == 0 {
48
+ return defaultIP
49
+ }
50
+
51
+ return ip
52
+ }
53
+
54
+ func (s * Etcd3Suite ) SetUpSuite (c * check.C ) {
39
55
s .createComposeProject (c , "etcd3" )
40
56
s .composeProject .Start (c )
41
57
58
+ ipEtcd = s .getIPAddress (c , "etcd" , "172.18.0.2" )
59
+ ipWhoami01 = s .getIPAddress (c , "whoami1" , "172.18.0.3" )
60
+ ipWhoami02 = s .getIPAddress (c , "whoami2" , "172.18.0.4" )
61
+ ipWhoami03 = s .getIPAddress (c , "whoami3" , "172.18.0.5" )
62
+ ipWhoami04 = s .getIPAddress (c , "whoami4" , "172.18.0.6" )
63
+
42
64
etcdv3 .Register ()
43
65
url := ipEtcd + ":2379"
44
66
kv , err := valkeyrie .NewStore (
@@ -49,7 +71,7 @@ func (s *Etcd3Suite) SetUpTest(c *check.C) {
49
71
},
50
72
)
51
73
if err != nil {
52
- c .Fatal ("Cannot create store etcd" )
74
+ c .Fatalf ("Cannot create store etcd %v" , err )
53
75
}
54
76
s .kv = kv
55
77
@@ -62,21 +84,22 @@ func (s *Etcd3Suite) SetUpTest(c *check.C) {
62
84
}
63
85
64
86
func (s * Etcd3Suite ) TearDownTest (c * check.C ) {
87
+ // Delete all Traefik keys from ETCD
88
+ s .kv .DeleteTree ("/traefik" )
89
+ }
90
+
91
+ func (s * Etcd3Suite ) TearDownSuite (c * check.C ) {
65
92
// shutdown and delete compose project
66
93
if s .composeProject != nil {
67
94
s .composeProject .Stop (c )
68
95
}
69
96
}
70
97
71
- func (s * Etcd3Suite ) TearDownSuite (c * check.C ) {}
72
-
73
98
func (s * Etcd3Suite ) TestSimpleConfiguration (c * check.C ) {
74
99
file := s .adaptFile (c , "fixtures/etcd/simple.toml" , struct {
75
100
EtcdHost string
76
- UseAPIV3 bool
77
101
}{
78
102
ipEtcd ,
79
- true ,
80
103
})
81
104
defer os .Remove (file )
82
105
@@ -95,10 +118,8 @@ func (s *Etcd3Suite) TestSimpleConfiguration(c *check.C) {
95
118
func (s * Etcd3Suite ) TestNominalConfiguration (c * check.C ) {
96
119
file := s .adaptFile (c , "fixtures/etcd/simple.toml" , struct {
97
120
EtcdHost string
98
- UseAPIV3 bool
99
121
}{
100
122
ipEtcd ,
101
- true ,
102
123
})
103
124
defer os .Remove (file )
104
125
@@ -219,8 +240,7 @@ func (s *Etcd3Suite) TestGlobalConfiguration(c *check.C) {
219
240
cmd , display := s .traefikCmd (
220
241
withConfigFile ("fixtures/simple_web.toml" ),
221
242
"--etcd" ,
222
- "--etcd.endpoint=" + ipEtcd + ":4001" ,
223
- "--etcd.useAPIV3=true" )
243
+ "--etcd.endpoint=" + ipEtcd + ":4001" )
224
244
defer display (c )
225
245
err = cmd .Start ()
226
246
c .Assert (err , checker .IsNil )
@@ -294,8 +314,7 @@ func (s *Etcd3Suite) TestCertificatesContentWithSNIConfigHandshake(c *check.C) {
294
314
cmd , display := s .traefikCmd (
295
315
withConfigFile ("fixtures/simple_web.toml" ),
296
316
"--etcd" ,
297
- "--etcd.endpoint=" + ipEtcd + ":4001" ,
298
- "--etcd.useAPIV3=true" )
317
+ "--etcd.endpoint=" + ipEtcd + ":4001" )
299
318
defer display (c )
300
319
301
320
// Copy the contents of the certificate files into ETCD
@@ -397,8 +416,7 @@ func (s *Etcd3Suite) TestCommandStoreConfig(c *check.C) {
397
416
cmd , display := s .traefikCmd (
398
417
"storeconfig" ,
399
418
withConfigFile ("fixtures/simple_web.toml" ),
400
- "--etcd.endpoint=" + ipEtcd + ":4001" ,
401
- "--etcd.useAPIV3=true" )
419
+ "--etcd.endpoint=" + ipEtcd + ":4001" )
402
420
defer display (c )
403
421
err := cmd .Start ()
404
422
c .Assert (err , checker .IsNil )
@@ -433,8 +451,7 @@ func (s *Etcd3Suite) TestSNIDynamicTlsConfig(c *check.C) {
433
451
cmd , display := s .traefikCmd (
434
452
withConfigFile ("fixtures/etcd/simple_https.toml" ),
435
453
"--etcd" ,
436
- "--etcd.endpoint=" + ipEtcd + ":4001" ,
437
- "--etcd.useAPIV3=true" )
454
+ "--etcd.endpoint=" + ipEtcd + ":4001" )
438
455
defer display (c )
439
456
440
457
snitestComCert , err := ioutil .ReadFile ("fixtures/https/snitest.com.cert" )
@@ -571,8 +588,7 @@ func (s *Etcd3Suite) TestDeleteSNIDynamicTlsConfig(c *check.C) {
571
588
cmd , display := s .traefikCmd (
572
589
withConfigFile ("fixtures/etcd/simple_https.toml" ),
573
590
"--etcd" ,
574
- "--etcd.endpoint=" + ipEtcd + ":4001" ,
575
- "--etcd.useAPIV3=true" )
591
+ "--etcd.endpoint=" + ipEtcd + ":4001" )
576
592
defer display (c )
577
593
578
594
// prepare to config
0 commit comments