traefik/integration/k8s_test.go

83 lines
2.3 KiB
Go
Raw Normal View History

2019-03-11 13:54:05 +00:00
package integration
import (
"net/http"
"os"
"path/filepath"
"time"
"github.com/containous/traefik/integration/try"
"github.com/go-check/check"
checker "github.com/vdemeester/shakers"
)
// K8sSuite
type K8sSuite struct{ BaseSuite }
func (s *K8sSuite) SetUpSuite(c *check.C) {
s.createComposeProject(c, "k8s")
s.composeProject.Start(c)
abs, err := filepath.Abs("./fixtures/k8s/kubeconfig.yaml")
2019-03-11 13:54:05 +00:00
c.Assert(err, checker.IsNil)
err = try.Do(60*time.Second, try.DoCondition(func() error {
2019-03-11 13:54:05 +00:00
_, err := os.Stat(abs)
return err
}))
c.Assert(err, checker.IsNil)
err = os.Setenv("KUBECONFIG", abs)
c.Assert(err, checker.IsNil)
}
func (s *K8sSuite) TearDownSuite(c *check.C) {
s.composeProject.Stop(c)
err := os.Remove("./fixtures/k8s/kubeconfig.yaml")
if err != nil {
c.Log(err)
}
err = os.Remove("./fixtures/k8s/coredns.yaml")
if err != nil {
c.Log(err)
}
err = os.Remove("./fixtures/k8s/traefik.yaml")
if err != nil {
c.Log(err)
}
}
2019-03-11 13:54:05 +00:00
func (s *K8sSuite) TestIngressSimple(c *check.C) {
2019-03-11 13:54:05 +00:00
cmd, display := s.traefikCmd(withConfigFile("fixtures/k8s_default.toml"))
defer display(c)
err := cmd.Start()
2019-03-11 13:54:05 +00:00
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()
err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", 60*time.Second, try.StatusCodeIs(http.StatusOK), try.BodyContains("Host(`whoami.test`)"))
2019-03-11 13:54:05 +00:00
c.Assert(err, checker.IsNil)
}
func (s *K8sSuite) TestCRDSimple(c *check.C) {
cmd, display := s.traefikCmd(withConfigFile("fixtures/k8s_crd.toml"))
defer display(c)
2019-03-11 13:54:05 +00:00
err := cmd.Start()
2019-03-11 13:54:05 +00:00
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()
2019-03-11 13:54:05 +00:00
err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", 60*time.Second, try.StatusCodeIs(http.StatusOK), try.BodyContains("Host(`foo.com`)"))
2019-03-11 13:54:05 +00:00
c.Assert(err, checker.IsNil)
err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", 1*time.Second, try.StatusCodeIs(http.StatusOK), try.BodyContains("PathPrefix(`/tobestripped`)"))
c.Assert(err, checker.IsNil)
2019-03-11 13:54:05 +00:00
err = try.GetRequest("http://127.0.0.1:8080/api/providers/kubernetescrd/routers", 1*time.Second, try.StatusCodeIs(http.StatusOK), try.BodyContains("default/stripprefix"))
c.Assert(err, checker.IsNil)
2019-03-11 13:54:05 +00:00
err = try.GetRequest("http://127.0.0.1:8080/api/providers/kubernetescrd/middlewares", 1*time.Second, try.StatusCodeIs(http.StatusOK), try.BodyContains("stripprefix"))
2019-03-11 13:54:05 +00:00
c.Assert(err, checker.IsNil)
}