2019-01-15 05:28:04 -08:00
package server
import (
"testing"
2019-03-15 09:42:03 +01:00
"github.com/containous/traefik/pkg/config"
2019-01-15 05:28:04 -08:00
"github.com/stretchr/testify/assert"
)
func TestAggregator ( t * testing . T ) {
testCases := [ ] struct {
desc string
given config . Configurations
2019-03-14 09:30:04 +01:00
expected * config . HTTPConfiguration
2019-01-15 05:28:04 -08:00
} {
{
desc : "Nil returns an empty configuration" ,
given : nil ,
2019-03-14 09:30:04 +01:00
expected : & config . HTTPConfiguration {
2019-01-15 05:28:04 -08:00
Routers : make ( map [ string ] * config . Router ) ,
Middlewares : make ( map [ string ] * config . Middleware ) ,
Services : make ( map [ string ] * config . Service ) ,
} ,
} ,
{
desc : "Returns fully qualified elements from a mono-provider configuration map" ,
given : config . Configurations {
"provider-1" : & config . Configuration {
2019-03-14 09:30:04 +01:00
HTTP : & config . HTTPConfiguration {
Routers : map [ string ] * config . Router {
"router-1" : { } ,
} ,
Middlewares : map [ string ] * config . Middleware {
"middleware-1" : { } ,
} ,
Services : map [ string ] * config . Service {
"service-1" : { } ,
} ,
2019-01-15 05:28:04 -08:00
} ,
} ,
} ,
2019-03-14 09:30:04 +01:00
expected : & config . HTTPConfiguration {
2019-01-15 05:28:04 -08:00
Routers : map [ string ] * config . Router {
2019-06-20 00:40:05 +02:00
"provider-1@router-1" : { } ,
2019-01-15 05:28:04 -08:00
} ,
Middlewares : map [ string ] * config . Middleware {
2019-06-20 00:40:05 +02:00
"provider-1@middleware-1" : { } ,
2019-01-15 05:28:04 -08:00
} ,
Services : map [ string ] * config . Service {
2019-06-20 00:40:05 +02:00
"provider-1@service-1" : { } ,
2019-01-15 05:28:04 -08:00
} ,
} ,
} ,
{
desc : "Returns fully qualified elements from a multi-provider configuration map" ,
given : config . Configurations {
"provider-1" : & config . Configuration {
2019-03-14 09:30:04 +01:00
HTTP : & config . HTTPConfiguration {
Routers : map [ string ] * config . Router {
"router-1" : { } ,
} ,
Middlewares : map [ string ] * config . Middleware {
"middleware-1" : { } ,
} ,
Services : map [ string ] * config . Service {
"service-1" : { } ,
} ,
2019-01-15 05:28:04 -08:00
} ,
} ,
"provider-2" : & config . Configuration {
2019-03-14 09:30:04 +01:00
HTTP : & config . HTTPConfiguration {
Routers : map [ string ] * config . Router {
"router-1" : { } ,
} ,
Middlewares : map [ string ] * config . Middleware {
"middleware-1" : { } ,
} ,
Services : map [ string ] * config . Service {
"service-1" : { } ,
} ,
2019-01-15 05:28:04 -08:00
} ,
} ,
} ,
2019-03-14 09:30:04 +01:00
expected : & config . HTTPConfiguration {
2019-01-15 05:28:04 -08:00
Routers : map [ string ] * config . Router {
2019-06-20 00:40:05 +02:00
"provider-1@router-1" : { } ,
"provider-2@router-1" : { } ,
2019-01-15 05:28:04 -08:00
} ,
Middlewares : map [ string ] * config . Middleware {
2019-06-20 00:40:05 +02:00
"provider-1@middleware-1" : { } ,
"provider-2@middleware-1" : { } ,
2019-01-15 05:28:04 -08:00
} ,
Services : map [ string ] * config . Service {
2019-06-20 00:40:05 +02:00
"provider-1@service-1" : { } ,
"provider-2@service-1" : { } ,
2019-01-15 05:28:04 -08:00
} ,
} ,
} ,
}
for _ , test := range testCases {
test := test
t . Run ( test . desc , func ( t * testing . T ) {
t . Parallel ( )
2019-03-14 09:30:04 +01:00
2019-01-15 05:28:04 -08:00
actual := mergeConfiguration ( test . given )
2019-03-14 09:30:04 +01:00
assert . Equal ( t , test . expected , actual . HTTP )
2019-01-15 05:28:04 -08:00
} )
}
}