Merge pull request #862 from Juliens/eureka

test-integration(eureka): Add some integration tests
This commit is contained in:
Vincent Demeester 2016-11-29 23:00:50 +01:00 committed by GitHub
commit 82234cbbb2
4 changed files with 94 additions and 9 deletions

View file

@ -1,10 +1,17 @@
package main package main
import ( import (
"bytes"
"errors"
"io/ioutil"
"net/http" "net/http"
"os"
"os/exec" "os/exec"
"strings"
"text/template"
"time" "time"
"github.com/containous/traefik/integration/utils"
"github.com/go-check/check" "github.com/go-check/check"
checker "github.com/vdemeester/shakers" checker "github.com/vdemeester/shakers"
@ -16,17 +23,87 @@ type EurekaSuite struct{ BaseSuite }
func (s *EurekaSuite) SetUpSuite(c *check.C) { func (s *EurekaSuite) SetUpSuite(c *check.C) {
s.createComposeProject(c, "eureka") s.createComposeProject(c, "eureka")
s.composeProject.Start(c) s.composeProject.Start(c)
} }
func (s *EurekaSuite) TestSimpleConfiguration(c *check.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() err := cmd.Start()
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
defer cmd.Process.Kill() 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 // 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 // Expected a 404 as we did not configure anything
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)

View file

@ -1,7 +1,14 @@
defaultEntryPoints = ["http"] defaultEntryPoints = ["http"]
logLevel = "DEBUG"
[entryPoints] [entryPoints]
[entryPoints.http] [entryPoints.http]
address = ":8000" address = ":8000"
[eureka] [eureka]
endpoint = "http://127.0.0.1:8761/eureka" endpoint = "http://{{.EurekaHost}}:8761/eureka"
delay = "1m" delay = "1s"
[web]
address = ":8080"

View file

@ -1,4 +1,5 @@
eureka: eureka:
image: netflixoss/eureka:1.3.1 image: springcloud/eureka
ports:
- "8761:8080" whoami1:
image: emilevauge/whoami

View file

@ -11,5 +11,5 @@
backend = "backend{{.Name}}" backend = "backend{{.Name}}"
entryPoints = ["http"] entryPoints = ["http"]
[frontends.frontend{{.Name }}.routes.route-host{{.Name}}] [frontends.frontend{{.Name }}.routes.route-host{{.Name}}]
rule = "Host:http://{{ .Name | tolower }}" rule = "Host:{{ .Name | tolower }}"
{{end}} {{end}}