From cf8940e80eb915bfa5bd497d69dd4ac0a32a535b Mon Sep 17 00:00:00 2001 From: Julien Salleyron Date: Sun, 20 Nov 2016 18:24:15 +0100 Subject: [PATCH 1/3] fix(eureka): Wrong host in rule --- templates/eureka.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/eureka.tmpl b/templates/eureka.tmpl index 10ad8e613..a2ffbff2e 100644 --- a/templates/eureka.tmpl +++ b/templates/eureka.tmpl @@ -11,5 +11,5 @@ backend = "backend{{.Name}}" entryPoints = ["http"] [frontends.frontend{{.Name }}.routes.route-host{{.Name}}] - rule = "Host:http://{{ .Name | tolower }}" + rule = "Host:{{ .Name | tolower }}" {{end}} From e1724444acb0d26be6eec08075a913bd97c51dad Mon Sep 17 00:00:00 2001 From: Julien Salleyron Date: Sun, 20 Nov 2016 18:25:13 +0100 Subject: [PATCH 2/3] test(integration-test): Integration test for eureka --- integration/eureka_test.go | 83 +++++++++++++++++++++++- integration/fixtures/eureka/simple.toml | 11 +++- integration/resources/compose/eureka.yml | 7 +- 3 files changed, 93 insertions(+), 8 deletions(-) diff --git a/integration/eureka_test.go b/integration/eureka_test.go index 5ba9d729a..bdd5b7374 100644 --- a/integration/eureka_test.go +++ b/integration/eureka_test.go @@ -1,10 +1,17 @@ package main import ( + "bytes" + "errors" + "io/ioutil" "net/http" + "os" "os/exec" + "strings" + "text/template" "time" + "github.com/containous/traefik/integration/utils" "github.com/go-check/check" checker "github.com/vdemeester/shakers" @@ -16,17 +23,87 @@ type EurekaSuite struct{ BaseSuite } func (s *EurekaSuite) SetUpSuite(c *check.C) { s.createComposeProject(c, "eureka") s.composeProject.Start(c) + } func (s *EurekaSuite) TestSimpleConfiguration(c *check.C) { - cmd := exec.Command(traefikBinary, "--configFile=fixtures/eureka/simple.toml") + + eurekaHost := s.composeProject.Container(c, "eureka").NetworkSettings.IPAddress + whoami1Host := s.composeProject.Container(c, "whoami1").NetworkSettings.IPAddress + + file := s.adaptFile(c, "fixtures/eureka/simple.toml", struct{ EurekaHost string }{eurekaHost}) + defer os.Remove(file) + cmd := exec.Command(traefikBinary, "--configFile="+file) err := cmd.Start() c.Assert(err, checker.IsNil) defer cmd.Process.Kill() - time.Sleep(500 * time.Millisecond) + eurekaUrl := "http://" + eurekaHost + ":8761/eureka/apps" + + // wait for eureka + err = utils.TryRequest(eurekaUrl, 60*time.Second, func(res *http.Response) error { + if err != nil { + return err + } + return nil + }) + c.Assert(err, checker.IsNil) + + eurekaTemplate := ` + { + "instance": { + "hostName": "{{ .IP }}", + "app": "{{ .ID }}", + "ipAddr": "{{ .IP }}", + "status": "UP", + "port": { + "$": {{ .Port }}, + "@enabled": "true" + }, + "dataCenterInfo": { + "name": "MyOwn" + } + } + }` + + tmpl, err := template.New("eurekaTemlate").Parse(eurekaTemplate) + c.Assert(err, checker.IsNil) + buf := new(bytes.Buffer) + templateVars := map[string]string{ + "ID": "tests-integration-traefik", + "IP": whoami1Host, + "Port": "80", + } + // add in eureka + err = tmpl.Execute(buf, templateVars) + resp, err := http.Post(eurekaUrl+"/tests-integration-traefik", "application/json", strings.NewReader(buf.String())) + c.Assert(err, checker.IsNil) + c.Assert(resp.StatusCode, checker.Equals, 204) + + // wait for traefik + err = utils.TryRequest("http://127.0.0.1:8080/api/providers", 60*time.Second, func(res *http.Response) error { + body, err := ioutil.ReadAll(res.Body) + if err != nil { + return err + } + if !strings.Contains(string(body), "Host:tests-integration-traefik") { + return errors.New("Incorrect traefik config") + } + return nil + }) + c.Assert(err, checker.IsNil) + + client := &http.Client{} + req, err := http.NewRequest("GET", "http://127.0.0.1:8000/", nil) + c.Assert(err, checker.IsNil) + req.Host = "tests-integration-traefik" + resp, err = client.Do(req) + + c.Assert(err, checker.IsNil) + c.Assert(resp.StatusCode, checker.Equals, 200) + // TODO validate : run on 80 - resp, err := http.Get("http://127.0.0.1:8000/") + resp, err = http.Get("http://127.0.0.1:8000/") // Expected a 404 as we did not configure anything c.Assert(err, checker.IsNil) diff --git a/integration/fixtures/eureka/simple.toml b/integration/fixtures/eureka/simple.toml index 16ef16d5e..8a9ffd94c 100644 --- a/integration/fixtures/eureka/simple.toml +++ b/integration/fixtures/eureka/simple.toml @@ -1,7 +1,14 @@ defaultEntryPoints = ["http"] + +logLevel = "DEBUG" + [entryPoints] [entryPoints.http] address = ":8000" + + [eureka] -endpoint = "http://127.0.0.1:8761/eureka" -delay = "1m" + endpoint = "http://{{.EurekaHost}}:8761/eureka" + delay = "1s" +[web] + address = ":8080" diff --git a/integration/resources/compose/eureka.yml b/integration/resources/compose/eureka.yml index 0282abb01..590d3e3c8 100644 --- a/integration/resources/compose/eureka.yml +++ b/integration/resources/compose/eureka.yml @@ -1,4 +1,5 @@ eureka: - image: netflixoss/eureka:1.3.1 - ports: - - "8761:8080" + image: springcloud/eureka + +whoami1: + image: emilevauge/whoami From 5b71e3184a0220fc9aeabf70ddcab41a41c996bb Mon Sep 17 00:00:00 2001 From: Julien Salleyron Date: Sun, 20 Nov 2016 18:34:42 +0100 Subject: [PATCH 3/3] fix: lint --- integration/eureka_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integration/eureka_test.go b/integration/eureka_test.go index bdd5b7374..9ae354441 100644 --- a/integration/eureka_test.go +++ b/integration/eureka_test.go @@ -38,10 +38,10 @@ func (s *EurekaSuite) TestSimpleConfiguration(c *check.C) { c.Assert(err, checker.IsNil) defer cmd.Process.Kill() - eurekaUrl := "http://" + eurekaHost + ":8761/eureka/apps" + eurekaURL := "http://" + eurekaHost + ":8761/eureka/apps" // wait for eureka - err = utils.TryRequest(eurekaUrl, 60*time.Second, func(res *http.Response) error { + err = utils.TryRequest(eurekaURL, 60*time.Second, func(res *http.Response) error { if err != nil { return err } @@ -76,7 +76,7 @@ func (s *EurekaSuite) TestSimpleConfiguration(c *check.C) { } // add in eureka err = tmpl.Execute(buf, templateVars) - resp, err := http.Post(eurekaUrl+"/tests-integration-traefik", "application/json", strings.NewReader(buf.String())) + resp, err := http.Post(eurekaURL+"/tests-integration-traefik", "application/json", strings.NewReader(buf.String())) c.Assert(err, checker.IsNil) c.Assert(resp.StatusCode, checker.Equals, 204)