Use of Viper and cobra

This commit is contained in:
emile 2016-01-13 22:46:44 +01:00
parent a0b15a0efd
commit 35070f7c1c
No known key found for this signature in database
GPG key ID: D808B4C167352E59
32 changed files with 414 additions and 143 deletions

View file

@ -1,11 +1,11 @@
package main
import (
"fmt"
"net/http"
"os/exec"
"time"
"fmt"
checker "github.com/vdemeester/shakers"
check "gopkg.in/check.v1"
)
@ -18,10 +18,10 @@ func (s *SimpleSuite) TestNoOrInexistentConfigShouldFail(c *check.C) {
output, err := cmd.CombinedOutput()
c.Assert(err, checker.NotNil)
c.Assert(string(output), checker.Contains, "Error reading file: open traefik.toml: no such file or directory")
c.Assert(string(output), checker.Contains, "Error reading file: open : no such file or directory")
nonExistentFile := "non/existent/file.toml"
cmd = exec.Command(traefikBinary, nonExistentFile)
cmd = exec.Command(traefikBinary, "--configFile="+nonExistentFile)
output, err = cmd.CombinedOutput()
c.Assert(err, checker.NotNil)
@ -29,30 +29,30 @@ func (s *SimpleSuite) TestNoOrInexistentConfigShouldFail(c *check.C) {
}
func (s *SimpleSuite) TestInvalidConfigShouldFail(c *check.C) {
cmd := exec.Command(traefikBinary, "fixtures/invalid_configuration.toml")
cmd := exec.Command(traefikBinary, "--configFile=fixtures/invalid_configuration.toml")
output, err := cmd.CombinedOutput()
c.Assert(err, checker.NotNil)
c.Assert(string(output), checker.Contains, "Error reading file: Near line 1")
c.Assert(string(output), checker.Contains, "Error reading file: While parsing config: Near line 1")
}
func (s *SimpleSuite) TestSimpleDefaultConfig(c *check.C) {
cmd := exec.Command(traefikBinary, "fixtures/simple_default.toml")
cmd := exec.Command(traefikBinary, "--configFile=fixtures/simple_default.toml")
err := cmd.Start()
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()
time.Sleep(500 * time.Millisecond)
// TODO validate : run on 80
resp, err := http.Get("http://127.0.0.1/")
resp, err := http.Get("http://127.0.0.1:8000/")
// Expected a 404 as we did not comfigure anything
// Expected a 404 as we did not configure anything
c.Assert(err, checker.IsNil)
c.Assert(resp.StatusCode, checker.Equals, 404)
}
func (s *SimpleSuite) TestWithWebConfig(c *check.C) {
cmd := exec.Command(traefikBinary, "fixtures/simple_web.toml")
cmd := exec.Command(traefikBinary, "--configFile=fixtures/simple_web.toml")
err := cmd.Start()
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()

View file

@ -10,14 +10,14 @@ import (
)
func (s *ConsulSuite) TestSimpleConfiguration(c *check.C) {
cmd := exec.Command(traefikBinary, "fixtures/consul/simple.toml")
cmd := exec.Command(traefikBinary, "--configFile=fixtures/consul/simple.toml")
err := cmd.Start()
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()
time.Sleep(500 * time.Millisecond)
// TODO validate : run on 80
resp, err := http.Get("http://127.0.0.1/")
resp, err := http.Get("http://127.0.0.1:8000/")
// Expected a 404 as we did not comfigure anything
c.Assert(err, checker.IsNil)

View file

@ -139,14 +139,14 @@ func (s *DockerSuite) TestSimpleConfiguration(c *check.C) {
file := s.adaptFileForHost(c, "fixtures/docker/simple.toml")
defer os.Remove(file)
cmd := exec.Command(traefikBinary, file)
cmd := exec.Command(traefikBinary, "--configFile="+file)
err := cmd.Start()
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()
time.Sleep(500 * time.Millisecond)
// TODO validate : run on 80
resp, err := http.Get("http://127.0.0.1/")
resp, err := http.Get("http://127.0.0.1:8000/")
c.Assert(err, checker.IsNil)
// Expected a 404 as we did not comfigure anything
@ -159,7 +159,7 @@ func (s *DockerSuite) TestDefaultDockerContainers(c *check.C) {
name := s.startContainer(c, "swarm:1.0.0", "manage", "token://blablabla")
// Start traefik
cmd := exec.Command(traefikBinary, file)
cmd := exec.Command(traefikBinary, "--configFile="+file)
err := cmd.Start()
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()
@ -168,7 +168,7 @@ func (s *DockerSuite) TestDefaultDockerContainers(c *check.C) {
time.Sleep(1500 * time.Millisecond)
client := &http.Client{}
req, err := http.NewRequest("GET", "http://127.0.0.1/version", nil)
req, err := http.NewRequest("GET", "http://127.0.0.1:8000/version", nil)
c.Assert(err, checker.IsNil)
req.Host = fmt.Sprintf("%s.docker.localhost", name)
resp, err := client.Do(req)
@ -196,7 +196,7 @@ func (s *DockerSuite) TestDockerContainersWithLabels(c *check.C) {
s.startContainerWithLabels(c, "swarm:1.0.0", labels, "manage", "token://blabla")
// Start traefik
cmd := exec.Command(traefikBinary, file)
cmd := exec.Command(traefikBinary, "--configFile="+file)
err := cmd.Start()
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()
@ -205,7 +205,7 @@ func (s *DockerSuite) TestDockerContainersWithLabels(c *check.C) {
time.Sleep(1500 * time.Millisecond)
client := &http.Client{}
req, err := http.NewRequest("GET", "http://127.0.0.1/version", nil)
req, err := http.NewRequest("GET", "http://127.0.0.1:8000/version", nil)
c.Assert(err, checker.IsNil)
req.Host = fmt.Sprintf("my.super.host")
resp, err := client.Do(req)
@ -232,7 +232,7 @@ func (s *DockerSuite) TestDockerContainersWithOneMissingLabels(c *check.C) {
s.startContainerWithLabels(c, "swarm:1.0.0", labels, "manage", "token://blabla")
// Start traefik
cmd := exec.Command(traefikBinary, file)
cmd := exec.Command(traefikBinary, "--configFile="+file)
err := cmd.Start()
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()
@ -241,7 +241,7 @@ func (s *DockerSuite) TestDockerContainersWithOneMissingLabels(c *check.C) {
time.Sleep(1500 * time.Millisecond)
client := &http.Client{}
req, err := http.NewRequest("GET", "http://127.0.0.1/version", nil)
req, err := http.NewRequest("GET", "http://127.0.0.1:8000/version", nil)
c.Assert(err, checker.IsNil)
req.Host = fmt.Sprintf("my.super.host")
resp, err := client.Do(req)

View file

@ -10,13 +10,13 @@ import (
)
func (s *FileSuite) TestSimpleConfiguration(c *check.C) {
cmd := exec.Command(traefikBinary, "fixtures/file/simple.toml")
cmd := exec.Command(traefikBinary, "--configFile=fixtures/file/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/")
resp, err := http.Get("http://127.0.0.1:8000/")
// Expected a 404 as we did not configure anything
c.Assert(err, checker.IsNil)
@ -25,13 +25,13 @@ func (s *FileSuite) TestSimpleConfiguration(c *check.C) {
// #56 regression test, make sure it does not fail
func (s *FileSuite) TestSimpleConfigurationNoPanic(c *check.C) {
cmd := exec.Command(traefikBinary, "fixtures/file/56-simple-panic.toml")
cmd := exec.Command(traefikBinary, "--configFile=fixtures/file/56-simple-panic.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/")
resp, err := http.Get("http://127.0.0.1:8000/")
// Expected a 404 as we did not configure anything
c.Assert(err, checker.IsNil)

View file

@ -4,6 +4,7 @@
# Default: ":80"
#
# port = ":80"
port = ":8000"
#
# LogLevel
logLevel = "DEBUG"

View file

@ -4,6 +4,7 @@
# Default: ":80"
#
# port = ":80"
port = ":8000"
#
# LogLevel
logLevel = "DEBUG"

View file

@ -4,6 +4,7 @@
# Default: ":80"
#
# port = ":80"
port = ":8000"
#
# LogLevel
logLevel = "DEBUG"

View file

@ -4,6 +4,7 @@
# Default: ":80"
#
# port = ":80"
port = ":8000"
#
# LogLevel
logLevel = "DEBUG"

View file

@ -1,4 +1,4 @@
port = ":443"
port = ":4443"
logLevel = "DEBUG"
[[certificates]]

View file

@ -4,6 +4,7 @@
# Default: ":80"
#
# port = ":80"
port = ":8000"
#
# LogLevel
logLevel = "DEBUG"

View file

@ -3,7 +3,7 @@
# Optional
# Default: ":80"
#
# port = ":80"
port = ":8000"
#
# LogLevel
logLevel = "DEBUG"

View file

@ -1,3 +1,4 @@
port = ":8000"
logLevel = "DEBUG"
[web]

View file

@ -19,7 +19,7 @@ type HTTPSSuite struct{ BaseSuite }
// "snitest.com", which happens to match the CN of 'snitest.com.crt'. The test
// verifies that traefik presents the correct certificate.
func (s *HTTPSSuite) TestWithSNIConfigHandshake(c *check.C) {
cmd := exec.Command(traefikBinary, "fixtures/https/https_sni.toml")
cmd := exec.Command(traefikBinary, "--configFile=fixtures/https/https_sni.toml")
err := cmd.Start()
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()
@ -30,7 +30,7 @@ func (s *HTTPSSuite) TestWithSNIConfigHandshake(c *check.C) {
InsecureSkipVerify: true,
ServerName: "snitest.com",
}
conn, err := tls.Dial("tcp", "127.0.0.1:443", tlsConfig)
conn, err := tls.Dial("tcp", "127.0.0.1:4443", tlsConfig)
c.Assert(err, checker.IsNil, check.Commentf("failed to connect to server"))
defer conn.Close()
@ -46,7 +46,7 @@ func (s *HTTPSSuite) TestWithSNIConfigHandshake(c *check.C) {
// SNI hostnames of "snitest.org" and "snitest.com". The test verifies
// that traefik routes the requests to the expected backends.
func (s *HTTPSSuite) TestWithSNIConfigRoute(c *check.C) {
cmd := exec.Command(traefikBinary, "fixtures/https/https_sni.toml")
cmd := exec.Command(traefikBinary, "--configFile=fixtures/https/https_sni.toml")
err := cmd.Start()
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()
@ -72,7 +72,7 @@ func (s *HTTPSSuite) TestWithSNIConfigRoute(c *check.C) {
}
client := &http.Client{Transport: tr1}
req, _ := http.NewRequest("GET", "https://127.0.0.1/", nil)
req, _ := http.NewRequest("GET", "https://127.0.0.1:4443/", nil)
req.Host = "snitest.com"
req.Header.Set("Host", "snitest.com")
req.Header.Set("Accept", "*/*")
@ -82,7 +82,7 @@ func (s *HTTPSSuite) TestWithSNIConfigRoute(c *check.C) {
c.Assert(resp.StatusCode, checker.Equals, 204)
client = &http.Client{Transport: tr2}
req, _ = http.NewRequest("GET", "https://127.0.0.1/", nil)
req, _ = http.NewRequest("GET", "https://127.0.0.1:4443/", nil)
req.Host = "snitest.org"
req.Header.Set("Host", "snitest.org")
req.Header.Set("Accept", "*/*")

View file

@ -10,14 +10,14 @@ import (
)
func (s *MarathonSuite) TestSimpleConfiguration(c *check.C) {
cmd := exec.Command(traefikBinary, "fixtures/marathon/simple.toml")
cmd := exec.Command(traefikBinary, "--configFile=fixtures/marathon/simple.toml")
err := cmd.Start()
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()
time.Sleep(500 * time.Millisecond)
// TODO validate : run on 80
resp, err := http.Get("http://127.0.0.1/")
resp, err := http.Get("http://127.0.0.1:8000/")
// Expected a 404 as we did not configure anything
c.Assert(err, checker.IsNil)