Move dynamic config into a dedicated package.

This commit is contained in:
Ludovic Fernandez 2019-07-10 09:26:04 +02:00 committed by Traefiker Bot
parent 09cc1161c9
commit c8bf8e896a
102 changed files with 3170 additions and 3166 deletions

View file

@ -6,13 +6,13 @@ import (
"net/http/httptest"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares/headers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func stubResponse(_ map[string]*config.Middleware) *http.Response {
func stubResponse(_ map[string]*dynamic.Middleware) *http.Response {
return &http.Response{Header: make(http.Header)}
}
@ -21,24 +21,24 @@ func TestBuilderBuild(t *testing.T) {
desc string
middlewares []string
// buildResponse is needed because secure use a private context key
buildResponse func(map[string]*config.Middleware) *http.Response
conf map[string]*config.Middleware
buildResponse func(map[string]*dynamic.Middleware) *http.Response
conf map[string]*dynamic.Middleware
assertResponse func(*testing.T, *http.Response)
}{
{
desc: "no configuration",
middlewares: []string{"foo", "bar"},
buildResponse: stubResponse,
conf: map[string]*config.Middleware{},
conf: map[string]*dynamic.Middleware{},
assertResponse: func(t *testing.T, resp *http.Response) {},
},
{
desc: "one modifier",
middlewares: []string{"foo", "bar"},
buildResponse: stubResponse,
conf: map[string]*config.Middleware{
conf: map[string]*dynamic.Middleware{
"foo": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
},
},
@ -52,7 +52,7 @@ func TestBuilderBuild(t *testing.T) {
{
desc: "secure: one modifier",
middlewares: []string{"foo", "bar"},
buildResponse: func(middlewares map[string]*config.Middleware) *http.Response {
buildResponse: func(middlewares map[string]*dynamic.Middleware) *http.Response {
ctx := context.Background()
var request *http.Request
@ -69,14 +69,14 @@ func TestBuilderBuild(t *testing.T) {
return &http.Response{Header: make(http.Header), Request: request}
},
conf: map[string]*config.Middleware{
conf: map[string]*dynamic.Middleware{
"foo": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
ReferrerPolicy: "no-referrer",
},
},
"bar": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomResponseHeaders: map[string]string{"X-Bar": "bar"},
},
},
@ -91,14 +91,14 @@ func TestBuilderBuild(t *testing.T) {
desc: "two modifiers",
middlewares: []string{"foo", "bar"},
buildResponse: stubResponse,
conf: map[string]*config.Middleware{
conf: map[string]*dynamic.Middleware{
"foo": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
},
},
"bar": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomResponseHeaders: map[string]string{"X-Bar": "bar"},
},
},
@ -114,14 +114,14 @@ func TestBuilderBuild(t *testing.T) {
desc: "modifier order",
middlewares: []string{"foo", "bar"},
buildResponse: stubResponse,
conf: map[string]*config.Middleware{
conf: map[string]*dynamic.Middleware{
"foo": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
},
},
"bar": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomResponseHeaders: map[string]string{"X-Foo": "bar"},
},
},
@ -136,19 +136,19 @@ func TestBuilderBuild(t *testing.T) {
desc: "chain",
middlewares: []string{"chain"},
buildResponse: stubResponse,
conf: map[string]*config.Middleware{
conf: map[string]*dynamic.Middleware{
"foo": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
},
},
"bar": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomResponseHeaders: map[string]string{"X-Foo": "bar"},
},
},
"chain": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"foo", "bar"},
},
},
@ -166,8 +166,8 @@ func TestBuilderBuild(t *testing.T) {
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
rtConf := config.NewRuntimeConfig(config.Configuration{
HTTP: &config.HTTPConfiguration{
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Middlewares: test.conf,
},
})