Add Etcd integration tests
Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
parent
61def880db
commit
26774d2317
4 changed files with 155 additions and 35 deletions
|
@ -8,13 +8,43 @@ import (
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
|
|
||||||
checker "github.com/vdemeester/shakers"
|
checker "github.com/vdemeester/shakers"
|
||||||
|
|
||||||
|
"github.com/docker/libkv"
|
||||||
|
"github.com/docker/libkv/store"
|
||||||
|
"github.com/docker/libkv/store/etcd"
|
||||||
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Etcd test suites (using libcompose)
|
// Etcd test suites (using libcompose)
|
||||||
type EtcdSuite struct{ BaseSuite }
|
type EtcdSuite struct {
|
||||||
|
BaseSuite
|
||||||
|
kv store.Store
|
||||||
|
}
|
||||||
|
|
||||||
func (s *EtcdSuite) SetUpSuite(c *check.C) {
|
func (s *EtcdSuite) SetUpSuite(c *check.C) {
|
||||||
s.createComposeProject(c, "etcd")
|
s.createComposeProject(c, "etcd")
|
||||||
|
s.composeProject.Start(c)
|
||||||
|
|
||||||
|
time.Sleep(3000 * time.Millisecond)
|
||||||
|
|
||||||
|
etcd.Register()
|
||||||
|
kv, err := libkv.NewStore(
|
||||||
|
store.ETCD,
|
||||||
|
[]string{"localhost:4001"},
|
||||||
|
&store.Config{
|
||||||
|
ConnectionTimeout: 10 * time.Second,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
c.Fatal("Cannot create store etcd")
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := http.Get("http://127.0.0.1:4001/v2/keys")
|
||||||
|
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(resp.StatusCode, checker.Equals, 200)
|
||||||
|
s.kv = kv
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *EtcdSuite) TestSimpleConfiguration(c *check.C) {
|
func (s *EtcdSuite) TestSimpleConfiguration(c *check.C) {
|
||||||
|
@ -31,3 +61,104 @@ func (s *EtcdSuite) TestSimpleConfiguration(c *check.C) {
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(resp.StatusCode, checker.Equals, 404)
|
c.Assert(resp.StatusCode, checker.Equals, 404)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *EtcdSuite) TestNominalConfiguration(c *check.C) {
|
||||||
|
cmd := exec.Command(traefikBinary, "--configFile=fixtures/etcd/simple.toml")
|
||||||
|
err := cmd.Start()
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
defer cmd.Process.Kill()
|
||||||
|
|
||||||
|
time.Sleep(1000 * time.Millisecond)
|
||||||
|
resp, err := http.Get("http://127.0.0.1:8000/")
|
||||||
|
|
||||||
|
// Expected a 404 as we did not configure anything
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(resp.StatusCode, checker.Equals, 404)
|
||||||
|
|
||||||
|
whoami1 := s.composeProject.Container(c, "whoami1")
|
||||||
|
whoami2 := s.composeProject.Container(c, "whoami2")
|
||||||
|
whoami3 := s.composeProject.Container(c, "whoami3")
|
||||||
|
whoami4 := s.composeProject.Container(c, "whoami4")
|
||||||
|
|
||||||
|
backend1 := map[string]string{
|
||||||
|
"/traefik/backends/backend1/circuitbreaker/expression": "NetworkErrorRatio() > 0.5",
|
||||||
|
"/traefik/backends/backend1/servers/server1/url": "http://" + whoami1.NetworkSettings.IPAddress + ":80",
|
||||||
|
"/traefik/backends/backend1/servers/server1/weight": "10",
|
||||||
|
"/traefik/backends/backend1/servers/server2/url": "http://" + whoami2.NetworkSettings.IPAddress + ":80",
|
||||||
|
"/traefik/backends/backend1/servers/server2/weight": "1",
|
||||||
|
}
|
||||||
|
backend2 := map[string]string{
|
||||||
|
"/traefik/backends/backend2/loadbalancer/method": "drr",
|
||||||
|
"/traefik/backends/backend2/servers/server1/url": "http://" + whoami3.NetworkSettings.IPAddress + ":80",
|
||||||
|
"/traefik/backends/backend2/servers/server1/weight": "1",
|
||||||
|
"/traefik/backends/backend2/servers/server2/url": "http://" + whoami4.NetworkSettings.IPAddress + ":80",
|
||||||
|
"/traefik/backends/backend2/servers/server2/weight": "2",
|
||||||
|
}
|
||||||
|
frontend1 := map[string]string{
|
||||||
|
"/traefik/frontends/frontend1/backend": "backend2",
|
||||||
|
"/traefik/frontends/frontend1/entrypoints": "http",
|
||||||
|
"/traefik/frontends/frontend1/routes/test_1/rule": "Host:test.localhost",
|
||||||
|
}
|
||||||
|
frontend2 := map[string]string{
|
||||||
|
"/traefik/frontends/frontend2/backend": "backend1",
|
||||||
|
"/traefik/frontends/frontend2/entrypoints": "http",
|
||||||
|
"/traefik/frontends/frontend2/routes/test_2/rule": "Path:/test",
|
||||||
|
}
|
||||||
|
for key, value := range backend1 {
|
||||||
|
err := s.kv.Put(key, []byte(value), nil)
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
}
|
||||||
|
for key, value := range backend2 {
|
||||||
|
err := s.kv.Put(key, []byte(value), nil)
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
}
|
||||||
|
for key, value := range frontend1 {
|
||||||
|
err := s.kv.Put(key, []byte(value), nil)
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
}
|
||||||
|
for key, value := range frontend2 {
|
||||||
|
err := s.kv.Put(key, []byte(value), nil)
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(3000 * time.Millisecond)
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
req, err := http.NewRequest("GET", "http://127.0.0.1:8000/", nil)
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
req.Host = "test.localhost"
|
||||||
|
response, err := client.Do(req)
|
||||||
|
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(response.StatusCode, checker.Equals, 200)
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(response.Body)
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
if !strings.Contains(string(body), whoami3.NetworkSettings.IPAddress) &&
|
||||||
|
!strings.Contains(string(body), whoami4.NetworkSettings.IPAddress) {
|
||||||
|
c.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err = http.NewRequest("GET", "http://127.0.0.1:8000/test", nil)
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
response, err = client.Do(req)
|
||||||
|
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(response.StatusCode, checker.Equals, 200)
|
||||||
|
|
||||||
|
body, err = ioutil.ReadAll(response.Body)
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
if !strings.Contains(string(body), whoami1.NetworkSettings.IPAddress) &&
|
||||||
|
!strings.Contains(string(body), whoami2.NetworkSettings.IPAddress) {
|
||||||
|
c.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err = http.NewRequest("GET", "http://127.0.0.1:8000/test2", nil)
|
||||||
|
req.Host = "test2.localhost"
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(resp.StatusCode, checker.Equals, 404)
|
||||||
|
|
||||||
|
req, err = http.NewRequest("GET", "http://127.0.0.1:8000/", nil)
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(resp.StatusCode, checker.Equals, 404)
|
||||||
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
defaultEntryPoints = ["http"]
|
defaultEntryPoints = ["http"]
|
||||||
|
|
||||||
|
logLevel = "DEBUG"
|
||||||
|
|
||||||
[entryPoints]
|
[entryPoints]
|
||||||
[entryPoints.http]
|
[entryPoints.http]
|
||||||
address = ":8000"
|
address = ":8000"
|
||||||
|
|
||||||
logLevel = "DEBUG"
|
|
||||||
|
|
||||||
[docker]
|
[docker]
|
||||||
|
|
||||||
# It's dynamagic !
|
# It's dynamagic !
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
defaultEntryPoints = ["http"]
|
defaultEntryPoints = ["http"]
|
||||||
|
|
||||||
|
logLevel = "DEBUG"
|
||||||
|
|
||||||
[entryPoints]
|
[entryPoints]
|
||||||
[entryPoints.http]
|
[entryPoints.http]
|
||||||
address = ":8000"
|
address = ":8000"
|
||||||
|
|
||||||
logLevel = "DEBUG"
|
|
||||||
|
|
||||||
[etcd]
|
[etcd]
|
||||||
endpoint = "127.0.0.1:4003,127.0.0.1:4002,127.0.0.1:4001"
|
endpoint = "127.0.0.1:4001"
|
||||||
|
prefix = "/traefik"
|
||||||
|
watch = true
|
||||||
|
|
|
@ -1,30 +1,16 @@
|
||||||
etcd1:
|
etcd:
|
||||||
image: quay.io/coreos/etcd:v2.2.0
|
image: gcr.io/google_containers/etcd:2.2.1
|
||||||
net: "host"
|
net: host
|
||||||
command: >
|
command: ['/usr/local/bin/etcd', '--addr=127.0.0.1:4001', '--bind-addr=0.0.0.0:4001', '--data-dir=/var/etcd/data']
|
||||||
--name etcd1
|
|
||||||
--listen-peer-urls http://localhost:7001
|
whoami1:
|
||||||
--listen-client-urls http://localhost:4001
|
image: emilevauge/whoami
|
||||||
--initial-advertise-peer-urls http://localhost:7001
|
|
||||||
--advertise-client-urls http://localhost:4001
|
whoami2:
|
||||||
--initial-cluster etcd1=http://localhost:7001,etcd2=http://localhost:7002,etcd3=http://localhost:7003
|
image: emilevauge/whoami
|
||||||
etcd2:
|
|
||||||
image: quay.io/coreos/etcd:v2.2.0
|
whoami3:
|
||||||
net: "host"
|
image: emilevauge/whoami
|
||||||
command: >
|
|
||||||
--name etcd2
|
whoami4:
|
||||||
--listen-peer-urls http://localhost:7002
|
image: emilevauge/whoami
|
||||||
--listen-client-urls http://localhost:4002
|
|
||||||
--initial-advertise-peer-urls http://localhost:7002
|
|
||||||
--advertise-client-urls http://localhost:4002
|
|
||||||
--initial-cluster etcd1=http://localhost:7001,etcd2=http://localhost:7002,etcd3=http://localhost:7003
|
|
||||||
etcd3:
|
|
||||||
image: quay.io/coreos/etcd:v2.2.0
|
|
||||||
net: "host"
|
|
||||||
command: >
|
|
||||||
--name etcd3
|
|
||||||
--listen-peer-urls http://localhost:7003
|
|
||||||
--listen-client-urls http://localhost:4003
|
|
||||||
--initial-advertise-peer-urls http://localhost:7003
|
|
||||||
--advertise-client-urls http://localhost:4003
|
|
||||||
--initial-cluster etcd1=http://localhost:7001,etcd2=http://localhost:7002,etcd3=http://localhost:7003
|
|
Loading…
Reference in a new issue