2019-07-10 07:26:04 +00:00
|
|
|
package dynamic_test
|
2019-05-16 08:58:06 +00:00
|
|
|
|
|
|
|
import (
|
2019-06-17 16:14:08 +00:00
|
|
|
"context"
|
2019-05-16 08:58:06 +00:00
|
|
|
"testing"
|
|
|
|
|
2019-07-10 07:26:04 +00:00
|
|
|
"github.com/containous/traefik/pkg/config/dynamic"
|
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
|
|
|
|
func TestPopulateUsedby(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
2019-07-10 07:26:04 +00:00
|
|
|
conf *dynamic.RuntimeConfiguration
|
|
|
|
expected dynamic.RuntimeConfiguration
|
2019-05-16 08:58:06 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "nil config",
|
|
|
|
conf: nil,
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: dynamic.RuntimeConfiguration{},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "One service used by two routers",
|
2019-07-10 07:26:04 +00:00
|
|
|
conf: &dynamic.RuntimeConfiguration{
|
|
|
|
Routers: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
expected: dynamic.RuntimeConfiguration{
|
|
|
|
Routers: map[string]*dynamic.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo@myprovider": {},
|
|
|
|
"bar@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
conf: &dynamic.RuntimeConfiguration{
|
|
|
|
Services: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
Routers: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
expected: dynamic.RuntimeConfiguration{
|
|
|
|
Routers: map[string]*dynamic.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo@myprovider": {},
|
|
|
|
"bar@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
conf: &dynamic.RuntimeConfiguration{
|
|
|
|
Services: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
Routers: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
expected: dynamic.RuntimeConfiguration{
|
|
|
|
Routers: map[string]*dynamic.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
conf: &dynamic.RuntimeConfiguration{
|
|
|
|
Services: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
Routers: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
expected: dynamic.RuntimeConfiguration{
|
|
|
|
Routers: map[string]*dynamic.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {},
|
|
|
|
"foo@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
conf: &dynamic.RuntimeConfiguration{
|
|
|
|
Services: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
Middlewares: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
Routers: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
expected: dynamic.RuntimeConfiguration{
|
|
|
|
Routers: map[string]*dynamic.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {},
|
|
|
|
"test@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
Middlewares: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
conf: &dynamic.RuntimeConfiguration{
|
|
|
|
Services: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
Middlewares: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
Routers: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
expected: dynamic.RuntimeConfiguration{
|
|
|
|
Services: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
conf: &dynamic.RuntimeConfiguration{
|
|
|
|
Services: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
Middlewares: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
Routers: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
expected: dynamic.RuntimeConfiguration{
|
|
|
|
Routers: map[string]*dynamic.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
Middlewares: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
conf: &dynamic.RuntimeConfiguration{
|
|
|
|
Services: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
Middlewares: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
Routers: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
expected: dynamic.RuntimeConfiguration{
|
|
|
|
Routers: map[string]*dynamic.RouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {},
|
|
|
|
"test@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
Middlewares: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
conf: &dynamic.RuntimeConfiguration{
|
|
|
|
TCPRouters: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
TCPServices: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
expected: dynamic.RuntimeConfiguration{
|
|
|
|
TCPRouters: map[string]*dynamic.TCPRouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo@myprovider": {},
|
|
|
|
"bar@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPServices: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
conf: &dynamic.RuntimeConfiguration{
|
|
|
|
TCPServices: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
TCPRouters: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
expected: dynamic.RuntimeConfiguration{
|
|
|
|
TCPRouters: map[string]*dynamic.TCPRouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"foo@myprovider": {},
|
|
|
|
"bar@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPServices: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
conf: &dynamic.RuntimeConfiguration{
|
|
|
|
TCPServices: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
TCPRouters: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
expected: dynamic.RuntimeConfiguration{
|
|
|
|
TCPRouters: map[string]*dynamic.TCPRouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPServices: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
conf: &dynamic.RuntimeConfiguration{
|
|
|
|
TCPServices: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
TCPRouters: map[string]*dynamic.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-10 07:26:04 +00:00
|
|
|
expected: dynamic.RuntimeConfiguration{
|
|
|
|
TCPRouters: map[string]*dynamic.TCPRouterInfo{
|
2019-06-21 07:54:04 +00:00
|
|
|
"bar@myprovider": {},
|
|
|
|
"foo@myprovider": {},
|
2019-05-16 08:58:06 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPServices: map[string]*dynamic.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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-06-17 16:14:08 +00:00
|
|
|
|
|
|
|
func TestGetTCPRoutersByEntrypoints(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
2019-07-10 07:26:04 +00:00
|
|
|
conf dynamic.Configuration
|
2019-06-17 16:14:08 +00:00
|
|
|
entryPoints []string
|
2019-07-10 07:26:04 +00:00
|
|
|
expected map[string]map[string]*dynamic.TCPRouterInfo
|
2019-06-17 16:14:08 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "Empty Configuration without entrypoint",
|
2019-07-10 07:26:04 +00:00
|
|
|
conf: dynamic.Configuration{},
|
2019-06-17 16:14:08 +00:00
|
|
|
entryPoints: []string{""},
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: map[string]map[string]*dynamic.TCPRouterInfo{},
|
2019-06-17 16:14:08 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Empty Configuration with unknown entrypoints",
|
2019-07-10 07:26:04 +00:00
|
|
|
conf: dynamic.Configuration{},
|
2019-06-17 16:14:08 +00:00
|
|
|
entryPoints: []string{"foo"},
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: map[string]map[string]*dynamic.TCPRouterInfo{},
|
2019-06-17 16:14:08 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Valid configuration with an unknown entrypoint",
|
2019-07-10 07:26:04 +00:00
|
|
|
conf: dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2019-06-17 16:14:08 +00:00
|
|
|
"foo": {
|
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`bar.foo`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
TCP: &dynamic.TCPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.TCPRouter{
|
2019-06-17 16:14:08 +00:00
|
|
|
"foo": {
|
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`bar.foo`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
entryPoints: []string{"foo"},
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: map[string]map[string]*dynamic.TCPRouterInfo{},
|
2019-06-17 16:14:08 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Valid configuration with a known entrypoint",
|
2019-07-10 07:26:04 +00:00
|
|
|
conf: dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2019-06-17 16:14:08 +00:00
|
|
|
"foo": {
|
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`bar.foo`)",
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
EntryPoints: []string{"webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "bar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`foo.bar`)",
|
|
|
|
},
|
|
|
|
"foobar": {
|
|
|
|
EntryPoints: []string{"web", "webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foobar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`bar.foobar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
TCP: &dynamic.TCPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.TCPRouter{
|
2019-06-17 16:14:08 +00:00
|
|
|
"foo": {
|
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`bar.foo`)",
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
EntryPoints: []string{"webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "bar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`foo.bar`)",
|
|
|
|
},
|
|
|
|
"foobar": {
|
|
|
|
EntryPoints: []string{"web", "webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foobar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`bar.foobar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
entryPoints: []string{"web"},
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: map[string]map[string]*dynamic.TCPRouterInfo{
|
2019-06-17 16:14:08 +00:00
|
|
|
"web": {
|
|
|
|
"foo": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPRouter: &dynamic.TCPRouter{
|
2019-06-17 16:14:08 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`bar.foo`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"foobar": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPRouter: &dynamic.TCPRouter{
|
2019-06-17 16:14:08 +00:00
|
|
|
EntryPoints: []string{"web", "webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foobar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`bar.foobar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Valid configuration with multiple known entrypoints",
|
2019-07-10 07:26:04 +00:00
|
|
|
conf: dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2019-06-17 16:14:08 +00:00
|
|
|
"foo": {
|
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`bar.foo`)",
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
EntryPoints: []string{"webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "bar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`foo.bar`)",
|
|
|
|
},
|
|
|
|
"foobar": {
|
|
|
|
EntryPoints: []string{"web", "webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foobar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`bar.foobar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
TCP: &dynamic.TCPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.TCPRouter{
|
2019-06-17 16:14:08 +00:00
|
|
|
"foo": {
|
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`bar.foo`)",
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
EntryPoints: []string{"webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "bar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`foo.bar`)",
|
|
|
|
},
|
|
|
|
"foobar": {
|
|
|
|
EntryPoints: []string{"web", "webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foobar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`bar.foobar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
entryPoints: []string{"web", "webs"},
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: map[string]map[string]*dynamic.TCPRouterInfo{
|
2019-06-17 16:14:08 +00:00
|
|
|
"web": {
|
|
|
|
"foo": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPRouter: &dynamic.TCPRouter{
|
2019-06-17 16:14:08 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`bar.foo`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"foobar": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPRouter: &dynamic.TCPRouter{
|
2019-06-17 16:14:08 +00:00
|
|
|
EntryPoints: []string{"web", "webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foobar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`bar.foobar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"webs": {
|
|
|
|
"bar": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPRouter: &dynamic.TCPRouter{
|
2019-06-17 16:14:08 +00:00
|
|
|
|
|
|
|
EntryPoints: []string{"webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "bar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`foo.bar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"foobar": {
|
2019-07-10 07:26:04 +00:00
|
|
|
TCPRouter: &dynamic.TCPRouter{
|
2019-06-17 16:14:08 +00:00
|
|
|
EntryPoints: []string{"web", "webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foobar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`bar.foobar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
test := test
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
2019-07-10 07:26:04 +00:00
|
|
|
runtimeConfig := dynamic.NewRuntimeConfig(test.conf)
|
2019-06-17 16:14:08 +00:00
|
|
|
actual := runtimeConfig.GetTCPRoutersByEntrypoints(context.Background(), test.entryPoints)
|
|
|
|
assert.Equal(t, test.expected, actual)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetRoutersByEntrypoints(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
2019-07-10 07:26:04 +00:00
|
|
|
conf dynamic.Configuration
|
2019-06-17 16:14:08 +00:00
|
|
|
entryPoints []string
|
2019-07-10 07:26:04 +00:00
|
|
|
expected map[string]map[string]*dynamic.RouterInfo
|
2019-06-17 16:14:08 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "Empty Configuration without entrypoint",
|
2019-07-10 07:26:04 +00:00
|
|
|
conf: dynamic.Configuration{},
|
2019-06-17 16:14:08 +00:00
|
|
|
entryPoints: []string{""},
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: map[string]map[string]*dynamic.RouterInfo{},
|
2019-06-17 16:14:08 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Empty Configuration with unknown entrypoints",
|
2019-07-10 07:26:04 +00:00
|
|
|
conf: dynamic.Configuration{},
|
2019-06-17 16:14:08 +00:00
|
|
|
entryPoints: []string{"foo"},
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: map[string]map[string]*dynamic.RouterInfo{},
|
2019-06-17 16:14:08 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Valid configuration with an unknown entrypoint",
|
2019-07-10 07:26:04 +00:00
|
|
|
conf: dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2019-06-17 16:14:08 +00:00
|
|
|
"foo": {
|
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`bar.foo`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
TCP: &dynamic.TCPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.TCPRouter{
|
2019-06-17 16:14:08 +00:00
|
|
|
"foo": {
|
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`bar.foo`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
entryPoints: []string{"foo"},
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: map[string]map[string]*dynamic.RouterInfo{},
|
2019-06-17 16:14:08 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Valid configuration with a known entrypoint",
|
2019-07-10 07:26:04 +00:00
|
|
|
conf: dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2019-06-17 16:14:08 +00:00
|
|
|
"foo": {
|
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`bar.foo`)",
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
EntryPoints: []string{"webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "bar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`foo.bar`)",
|
|
|
|
},
|
|
|
|
"foobar": {
|
|
|
|
EntryPoints: []string{"web", "webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foobar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`bar.foobar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
TCP: &dynamic.TCPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.TCPRouter{
|
2019-06-17 16:14:08 +00:00
|
|
|
"foo": {
|
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`bar.foo`)",
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
EntryPoints: []string{"webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "bar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`foo.bar`)",
|
|
|
|
},
|
|
|
|
"foobar": {
|
|
|
|
EntryPoints: []string{"web", "webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foobar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`bar.foobar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
entryPoints: []string{"web"},
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: map[string]map[string]*dynamic.RouterInfo{
|
2019-06-17 16:14:08 +00:00
|
|
|
"web": {
|
|
|
|
"foo": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-06-17 16:14:08 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`bar.foo`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"foobar": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-06-17 16:14:08 +00:00
|
|
|
EntryPoints: []string{"web", "webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foobar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`bar.foobar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Valid configuration with multiple known entrypoints",
|
2019-07-10 07:26:04 +00:00
|
|
|
conf: dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2019-06-17 16:14:08 +00:00
|
|
|
"foo": {
|
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`bar.foo`)",
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
EntryPoints: []string{"webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "bar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`foo.bar`)",
|
|
|
|
},
|
|
|
|
"foobar": {
|
|
|
|
EntryPoints: []string{"web", "webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foobar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`bar.foobar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
TCP: &dynamic.TCPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.TCPRouter{
|
2019-06-17 16:14:08 +00:00
|
|
|
"foo": {
|
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`bar.foo`)",
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
EntryPoints: []string{"webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "bar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`foo.bar`)",
|
|
|
|
},
|
|
|
|
"foobar": {
|
|
|
|
EntryPoints: []string{"web", "webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foobar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "HostSNI(`bar.foobar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
entryPoints: []string{"web", "webs"},
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: map[string]map[string]*dynamic.RouterInfo{
|
2019-06-17 16:14:08 +00:00
|
|
|
"web": {
|
|
|
|
"foo": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-06-17 16:14:08 +00:00
|
|
|
EntryPoints: []string{"web"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foo-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`bar.foo`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"foobar": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-06-17 16:14:08 +00:00
|
|
|
EntryPoints: []string{"web", "webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foobar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`bar.foobar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"webs": {
|
|
|
|
"bar": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-06-17 16:14:08 +00:00
|
|
|
|
|
|
|
EntryPoints: []string{"webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "bar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`foo.bar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"foobar": {
|
2019-07-10 07:26:04 +00:00
|
|
|
Router: &dynamic.Router{
|
2019-06-17 16:14:08 +00:00
|
|
|
EntryPoints: []string{"web", "webs"},
|
2019-06-21 07:54:04 +00:00
|
|
|
Service: "foobar-service@myprovider",
|
2019-06-17 16:14:08 +00:00
|
|
|
Rule: "Host(`bar.foobar`)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
test := test
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
2019-07-10 07:26:04 +00:00
|
|
|
runtimeConfig := dynamic.NewRuntimeConfig(test.conf)
|
2019-06-17 16:14:08 +00:00
|
|
|
actual := runtimeConfig.GetRoutersByEntrypoints(context.Background(), test.entryPoints, false)
|
|
|
|
assert.Equal(t, test.expected, actual)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|