Enables the use of elements declared in other providers
This commit is contained in:
parent
a79d6aa669
commit
8735263930
16 changed files with 753 additions and 94 deletions
24
integration/fixtures/multiprovider.toml
Normal file
24
integration/fixtures/multiprovider.toml
Normal file
|
@ -0,0 +1,24 @@
|
|||
[log]
|
||||
logLevel = "DEBUG"
|
||||
|
||||
[api]
|
||||
|
||||
[entryPoints]
|
||||
[entryPoints.http]
|
||||
address = ":8000"
|
||||
|
||||
[Providers]
|
||||
[Providers.Rest]
|
||||
|
||||
[Providers.File]
|
||||
|
||||
[Services]
|
||||
[Services.service]
|
||||
[Services.service.LoadBalancer]
|
||||
|
||||
[[Services.service.LoadBalancer.Servers]]
|
||||
URL = "{{.Server}}"
|
||||
Weight = 1
|
||||
[Middlewares]
|
||||
[Middlewares.customheader.Headers.CustomRequestHeaders]
|
||||
X-Custom="CustomValue"
|
|
@ -1,6 +1,8 @@
|
|||
package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
@ -9,6 +11,7 @@ import (
|
|||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/containous/traefik/config"
|
||||
"github.com/containous/traefik/integration/try"
|
||||
"github.com/go-check/check"
|
||||
checker "github.com/vdemeester/shakers"
|
||||
|
@ -434,3 +437,53 @@ func (s *SimpleSuite) TestKeepTrailingSlash(c *check.C) {
|
|||
|
||||
http.DefaultClient.CheckRedirect = oldCheckRedirect
|
||||
}
|
||||
|
||||
func (s *SimpleSuite) TestMultiprovider(c *check.C) {
|
||||
s.createComposeProject(c, "base")
|
||||
s.composeProject.Start(c)
|
||||
|
||||
server := "http://" + s.composeProject.Container(c, "whoami1").NetworkSettings.IPAddress
|
||||
|
||||
file := s.adaptFile(c, "fixtures/multiprovider.toml", struct {
|
||||
Server string
|
||||
}{Server: server})
|
||||
defer os.Remove(file)
|
||||
|
||||
cmd, output := s.traefikCmd(withConfigFile(file))
|
||||
defer output(c)
|
||||
|
||||
err := cmd.Start()
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer cmd.Process.Kill()
|
||||
|
||||
err = try.GetRequest("http://127.0.0.1:8080/api/providers/file/services", 1000*time.Millisecond, try.BodyContains("service"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
config := config.Configuration{
|
||||
Routers: map[string]*config.Router{
|
||||
"router1": {
|
||||
EntryPoints: []string{"http"},
|
||||
Middlewares: []string{"file.customheader"},
|
||||
Service: "file.service",
|
||||
Rule: "PathPrefix:/",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
json, err := json.Marshal(config)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
request, err := http.NewRequest(http.MethodPut, "http://127.0.0.1:8080/api/providers/rest", bytes.NewReader(json))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
response, err := http.DefaultClient.Do(request)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(response.StatusCode, checker.Equals, http.StatusOK)
|
||||
|
||||
err = try.GetRequest("http://127.0.0.1:8080/api/providers/rest/routers", 1000*time.Millisecond, try.BodyContains("PathPrefix:/"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.GetRequest("http://127.0.0.1:8000/", 1*time.Second, try.StatusCodeIs(http.StatusOK), try.BodyContains("CustomValue"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ func (s *TracingSuite) TestZipkinRateLimit(c *check.C) {
|
|||
err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusTooManyRequests))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.GetRequest("http://"+s.ZipkinIP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("forward service1/router1", "ratelimit"))
|
||||
err = try.GetRequest("http://"+s.ZipkinIP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("forward service1/file.router1", "file.ratelimit"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ func (s *TracingSuite) TestZipkinRetry(c *check.C) {
|
|||
err = try.GetRequest("http://127.0.0.1:8000/retry", 500*time.Millisecond, try.StatusCodeIs(http.StatusBadGateway))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.GetRequest("http://"+s.ZipkinIP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("forward service2/router2", "retry"))
|
||||
err = try.GetRequest("http://"+s.ZipkinIP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("forward service2/file.router2", "file.retry"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
}
|
||||
|
||||
|
@ -132,6 +132,6 @@ func (s *TracingSuite) TestZipkinAuth(c *check.C) {
|
|||
err = try.GetRequest("http://127.0.0.1:8000/auth", 500*time.Millisecond, try.StatusCodeIs(http.StatusUnauthorized))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.GetRequest("http://"+s.ZipkinIP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("entrypoint http", "basic-auth"))
|
||||
err = try.GetRequest("http://"+s.ZipkinIP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("entrypoint http", "file.basic-auth"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue