2019-07-15 15:04:04 +00:00
|
|
|
package runtime_test
|
2019-05-16 08:58:06 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-08-03 01:58:23 +00:00
|
|
|
"github.com/containous/traefik/v2/pkg/config/dynamic"
|
|
|
|
"github.com/containous/traefik/v2/pkg/config/runtime"
|
2019-05-16 08:58:06 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
// all the Routers/Middlewares/Services are considered fully qualified
|
2019-07-15 15:04:04 +00:00
|
|
|
func TestPopulateUsedBy(t *testing.T) {
|
2019-05-16 08:58:06 +00:00
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
2019-07-15 15:04:04 +00:00
|
|
|
conf *runtime.Configuration
|
|
|
|
expected runtime.Configuration
|
2019-05-16 08:58:06 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "nil config",
|
|
|
|
conf: nil,
|
2019-07-15 15:04:04 +00:00
|
|
|
expected: runtime.Configuration{},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "One service used by two routers",
|
2019-07-15 15:04:04 +00:00
|
|
|
conf: &runtime.Configuration{
|
|
|
|
Routers: map[string]*runtime.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`bar.foo`)",
|
|
|
|
},
|
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`foo.bar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Services: map[string]*runtime.ServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Service: &dynamic.Service{
|
|
|
|
LoadBalancer: &dynamic.LoadBalancerService{
|
|
|
|
Servers: []dynamic.Server{
|
2019-06-05 20:18:06 +00:00
|
|
|
{URL: "http://127.0.0.1:8085"},
|
|
|
|
{URL: "http://127.0.0.1:8086"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
HealthCheck: &dynamic.HealthCheck{
|
2019-05-16 08:58:06 +00:00
|
|
|
Interval: "500ms",
|
|
|
|
Path: "/health",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
expected: runtime.Configuration{
|
|
|
|
Routers: map[string]*runtime.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo@myprovider": {},
|
|
|
|
"bar@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Services: map[string]*runtime.ServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
|
|
|
UsedBy: []string{"bar@myprovider", "foo@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "One service used by two routers, but one router with wrong rule",
|
2019-07-15 15:04:04 +00:00
|
|
|
conf: &runtime.Configuration{
|
|
|
|
Services: map[string]*runtime.ServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Service: &dynamic.Service{
|
|
|
|
LoadBalancer: &dynamic.LoadBalancerService{
|
|
|
|
Servers: []dynamic.Server{
|
2019-06-05 20:18:06 +00:00
|
|
|
{URL: "http://127.0.0.1"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Routers: map[string]*runtime.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "WrongRule(`bar.foo`)",
|
|
|
|
},
|
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`foo.bar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
expected: runtime.Configuration{
|
|
|
|
Routers: map[string]*runtime.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo@myprovider": {},
|
|
|
|
"bar@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Services: map[string]*runtime.ServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
|
|
|
UsedBy: []string{"bar@myprovider", "foo@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Broken Service used by one Router",
|
2019-07-15 15:04:04 +00:00
|
|
|
conf: &runtime.Configuration{
|
|
|
|
Services: map[string]*runtime.ServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Service: &dynamic.Service{
|
2019-05-16 08:58:06 +00:00
|
|
|
LoadBalancer: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Routers: map[string]*runtime.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`foo.bar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
expected: runtime.Configuration{
|
|
|
|
Routers: map[string]*runtime.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Services: map[string]*runtime.ServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
|
|
|
UsedBy: []string{"bar@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "2 different Services each used by a disctinct router.",
|
2019-07-15 15:04:04 +00:00
|
|
|
conf: &runtime.Configuration{
|
|
|
|
Services: map[string]*runtime.ServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Service: &dynamic.Service{
|
|
|
|
LoadBalancer: &dynamic.LoadBalancerService{
|
|
|
|
Servers: []dynamic.Server{
|
2019-05-16 08:58:06 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://127.0.0.1:8085",
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://127.0.0.1:8086",
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
HealthCheck: &dynamic.HealthCheck{
|
2019-05-16 08:58:06 +00:00
|
|
|
Interval: "500ms",
|
|
|
|
Path: "/health",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar-service@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Service: &dynamic.Service{
|
|
|
|
LoadBalancer: &dynamic.LoadBalancerService{
|
|
|
|
Servers: []dynamic.Server{
|
2019-05-16 08:58:06 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://127.0.0.1:8087",
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://127.0.0.1:8088",
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
HealthCheck: &dynamic.HealthCheck{
|
2019-05-16 08:58:06 +00:00
|
|
|
Interval: "500ms",
|
|
|
|
Path: "/health",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Routers: map[string]*runtime.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`bar.foo`)",
|
|
|
|
},
|
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "bar-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`foo.bar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
expected: runtime.Configuration{
|
|
|
|
Routers: map[string]*runtime.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {},
|
|
|
|
"foo@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Services: map[string]*runtime.ServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
|
|
|
UsedBy: []string{"foo@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar-service@myprovider": {
|
|
|
|
UsedBy: []string{"bar@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "2 middlewares both used by 2 Routers",
|
2019-07-15 15:04:04 +00:00
|
|
|
conf: &runtime.Configuration{
|
|
|
|
Services: map[string]*runtime.ServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Service: &dynamic.Service{
|
|
|
|
LoadBalancer: &dynamic.LoadBalancerService{
|
|
|
|
Servers: []dynamic.Server{
|
2019-05-16 08:58:06 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://127.0.0.1",
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Middlewares: map[string]*runtime.MiddlewareInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"auth@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Middleware: &dynamic.Middleware{
|
|
|
|
BasicAuth: &dynamic.BasicAuth{
|
2019-05-16 08:58:06 +00:00
|
|
|
Users: []string{"admin:admin"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"addPrefixTest@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Middleware: &dynamic.Middleware{
|
|
|
|
AddPrefix: &dynamic.AddPrefix{
|
2019-05-16 08:58:06 +00:00
|
|
|
Prefix: "/toto",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Routers: map[string]*runtime.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`foo.bar`)",
|
|
|
|
Middlewares: []string{"auth", "addPrefixTest"},
|
|
|
|
},
|
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"test@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`foo.bar.other`)",
|
|
|
|
Middlewares: []string{"addPrefixTest", "auth"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
expected: runtime.Configuration{
|
|
|
|
Routers: map[string]*runtime.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {},
|
|
|
|
"test@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Services: map[string]*runtime.ServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
|
|
|
UsedBy: []string{"bar@myprovider", "test@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Middlewares: map[string]*runtime.MiddlewareInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"auth@myprovider": {
|
|
|
|
UsedBy: []string{"bar@myprovider", "test@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"addPrefixTest@myprovider": {
|
|
|
|
UsedBy: []string{"bar@myprovider", "test@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Unknown middleware is not used by the Router",
|
2019-07-15 15:04:04 +00:00
|
|
|
conf: &runtime.Configuration{
|
|
|
|
Services: map[string]*runtime.ServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Service: &dynamic.Service{
|
|
|
|
LoadBalancer: &dynamic.LoadBalancerService{
|
|
|
|
Servers: []dynamic.Server{
|
2019-05-16 08:58:06 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://127.0.0.1",
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Middlewares: map[string]*runtime.MiddlewareInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"auth@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Middleware: &dynamic.Middleware{
|
|
|
|
BasicAuth: &dynamic.BasicAuth{
|
2019-05-16 08:58:06 +00:00
|
|
|
Users: []string{"admin:admin"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Routers: map[string]*runtime.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`foo.bar`)",
|
|
|
|
Middlewares: []string{"unknown"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
expected: runtime.Configuration{
|
|
|
|
Services: map[string]*runtime.ServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
|
|
|
UsedBy: []string{"bar@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Broken middleware is used by Router",
|
2019-07-15 15:04:04 +00:00
|
|
|
conf: &runtime.Configuration{
|
|
|
|
Services: map[string]*runtime.ServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Service: &dynamic.Service{
|
|
|
|
LoadBalancer: &dynamic.LoadBalancerService{
|
|
|
|
Servers: []dynamic.Server{
|
2019-05-16 08:58:06 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://127.0.0.1",
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Middlewares: map[string]*runtime.MiddlewareInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"auth@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Middleware: &dynamic.Middleware{
|
|
|
|
BasicAuth: &dynamic.BasicAuth{
|
2019-05-16 08:58:06 +00:00
|
|
|
Users: []string{"badConf"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Routers: map[string]*runtime.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`foo.bar`)",
|
2019-06-21 07:54:04 +00:00
|
|
|
Middlewares: []string{"auth@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
expected: runtime.Configuration{
|
|
|
|
Routers: map[string]*runtime.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Services: map[string]*runtime.ServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
|
|
|
UsedBy: []string{"bar@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Middlewares: map[string]*runtime.MiddlewareInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"auth@myprovider": {
|
|
|
|
UsedBy: []string{"bar@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "2 middlewares from 2 disctinct providers both used by 2 Routers",
|
2019-07-15 15:04:04 +00:00
|
|
|
conf: &runtime.Configuration{
|
|
|
|
Services: map[string]*runtime.ServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Service: &dynamic.Service{
|
|
|
|
LoadBalancer: &dynamic.LoadBalancerService{
|
|
|
|
Servers: []dynamic.Server{
|
2019-05-16 08:58:06 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://127.0.0.1",
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Middlewares: map[string]*runtime.MiddlewareInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"auth@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Middleware: &dynamic.Middleware{
|
|
|
|
BasicAuth: &dynamic.BasicAuth{
|
2019-05-16 08:58:06 +00:00
|
|
|
Users: []string{"admin:admin"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"addPrefixTest@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Middleware: &dynamic.Middleware{
|
|
|
|
AddPrefix: &dynamic.AddPrefix{
|
2019-05-16 08:58:06 +00:00
|
|
|
Prefix: "/titi",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"addPrefixTest@anotherprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Middleware: &dynamic.Middleware{
|
|
|
|
AddPrefix: &dynamic.AddPrefix{
|
2019-05-16 08:58:06 +00:00
|
|
|
Prefix: "/toto",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Routers: map[string]*runtime.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`foo.bar`)",
|
2019-06-21 07:54:04 +00:00
|
|
|
Middlewares: []string{"auth", "addPrefixTest@anotherprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"test@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`foo.bar.other`)",
|
|
|
|
Middlewares: []string{"addPrefixTest", "auth"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
expected: runtime.Configuration{
|
|
|
|
Routers: map[string]*runtime.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {},
|
|
|
|
"test@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Services: map[string]*runtime.ServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
|
|
|
UsedBy: []string{"bar@myprovider", "test@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
Middlewares: map[string]*runtime.MiddlewareInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"auth@myprovider": {
|
|
|
|
UsedBy: []string{"bar@myprovider", "test@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"addPrefixTest@myprovider": {
|
|
|
|
UsedBy: []string{"test@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"addPrefixTest@anotherprovider": {
|
|
|
|
UsedBy: []string{"bar@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// TCP tests from hereon
|
|
|
|
{
|
|
|
|
desc: "TCP, One service used by two routers",
|
2019-07-15 15:04:04 +00:00
|
|
|
conf: &runtime.Configuration{
|
|
|
|
TCPRouters: map[string]*runtime.TCPRouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPRouter: &dynamic.TCPRouter{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`bar.foo`)",
|
|
|
|
},
|
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPRouter: &dynamic.TCPRouter{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`foo.bar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
TCPServices: map[string]*runtime.TCPServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPService: &dynamic.TCPService{
|
|
|
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
|
|
|
Servers: []dynamic.TCPServer{
|
2019-05-16 08:58:06 +00:00
|
|
|
{
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
Port: "8085",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
Port: "8086",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
expected: runtime.Configuration{
|
|
|
|
TCPRouters: map[string]*runtime.TCPRouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo@myprovider": {},
|
|
|
|
"bar@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
TCPServices: map[string]*runtime.TCPServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
|
|
|
UsedBy: []string{"bar@myprovider", "foo@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "TCP, One service used by two routers, but one router with wrong rule",
|
2019-07-15 15:04:04 +00:00
|
|
|
conf: &runtime.Configuration{
|
|
|
|
TCPServices: map[string]*runtime.TCPServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPService: &dynamic.TCPService{
|
|
|
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
|
|
|
Servers: []dynamic.TCPServer{
|
2019-05-16 08:58:06 +00:00
|
|
|
{
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
TCPRouters: map[string]*runtime.TCPRouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPRouter: &dynamic.TCPRouter{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "WrongRule(`bar.foo`)",
|
|
|
|
},
|
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPRouter: &dynamic.TCPRouter{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`foo.bar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
expected: runtime.Configuration{
|
|
|
|
TCPRouters: map[string]*runtime.TCPRouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo@myprovider": {},
|
|
|
|
"bar@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
TCPServices: map[string]*runtime.TCPServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
|
|
|
UsedBy: []string{"bar@myprovider", "foo@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "TCP, Broken Service used by one Router",
|
2019-07-15 15:04:04 +00:00
|
|
|
conf: &runtime.Configuration{
|
|
|
|
TCPServices: map[string]*runtime.TCPServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPService: &dynamic.TCPService{
|
2019-05-16 08:58:06 +00:00
|
|
|
LoadBalancer: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
TCPRouters: map[string]*runtime.TCPRouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPRouter: &dynamic.TCPRouter{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`foo.bar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
expected: runtime.Configuration{
|
|
|
|
TCPRouters: map[string]*runtime.TCPRouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
TCPServices: map[string]*runtime.TCPServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
|
|
|
UsedBy: []string{"bar@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "TCP, 2 different Services each used by a disctinct router.",
|
2019-07-15 15:04:04 +00:00
|
|
|
conf: &runtime.Configuration{
|
|
|
|
TCPServices: map[string]*runtime.TCPServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPService: &dynamic.TCPService{
|
|
|
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
|
|
|
Servers: []dynamic.TCPServer{
|
2019-05-16 08:58:06 +00:00
|
|
|
{
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
Port: "8085",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
Port: "8086",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar-service@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPService: &dynamic.TCPService{
|
|
|
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
|
|
|
Servers: []dynamic.TCPServer{
|
2019-05-16 08:58:06 +00:00
|
|
|
{
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
Port: "8087",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
Port: "8088",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
TCPRouters: map[string]*runtime.TCPRouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPRouter: &dynamic.TCPRouter{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`bar.foo`)",
|
|
|
|
},
|
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPRouter: &dynamic.TCPRouter{
|
2019-05-16 08:58:06 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "bar-service@myprovider",
|
2019-05-16 08:58:06 +00:00
|
|
|
Rule: "Host(`foo.bar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
expected: runtime.Configuration{
|
|
|
|
TCPRouters: map[string]*runtime.TCPRouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {},
|
|
|
|
"foo@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-15 15:04:04 +00:00
|
|
|
TCPServices: map[string]*runtime.TCPServiceInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo-service@myprovider": {
|
|
|
|
UsedBy: []string{"foo@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar-service@myprovider": {
|
|
|
|
UsedBy: []string{"bar@myprovider"},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range testCases {
|
|
|
|
test := test
|
|
|
|
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
runtimeConf := test.conf
|
|
|
|
runtimeConf.PopulateUsedBy()
|
|
|
|
|
|
|
|
for key, expectedService := range test.expected.Services {
|
|
|
|
require.NotNil(t, runtimeConf.Services[key])
|
|
|
|
assert.Equal(t, expectedService.UsedBy, runtimeConf.Services[key].UsedBy)
|
|
|
|
}
|
|
|
|
|
|
|
|
for key, expectedMiddleware := range test.expected.Middlewares {
|
|
|
|
require.NotNil(t, runtimeConf.Middlewares[key])
|
|
|
|
assert.Equal(t, expectedMiddleware.UsedBy, runtimeConf.Middlewares[key].UsedBy)
|
|
|
|
}
|
|
|
|
|
|
|
|
for key, expectedTCPService := range test.expected.TCPServices {
|
|
|
|
require.NotNil(t, runtimeConf.TCPServices[key])
|
|
|
|
assert.Equal(t, expectedTCPService.UsedBy, runtimeConf.TCPServices[key].UsedBy)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|