2019-01-29 17:54:05 +01:00
package marathon
import (
"context"
"math"
"testing"
2019-08-03 03:58:23 +02:00
"github.com/containous/traefik/v2/pkg/config/dynamic"
2019-01-29 17:54:05 +01:00
"github.com/gambol99/go-marathon"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
2019-09-30 18:12:04 +02:00
func Int ( v int ) * int { return & v }
func Bool ( v bool ) * bool { return & v }
2019-09-13 17:46:04 +02:00
2019-01-29 17:54:05 +01:00
func TestGetConfigurationAPIErrors ( t * testing . T ) {
fakeClient := newFakeClient ( true , marathon . Applications { } )
p := & Provider {
marathonClient : fakeClient ,
}
actualConfig := p . getConfigurations ( context . Background ( ) )
fakeClient . AssertExpectations ( t )
if actualConfig != nil {
t . Errorf ( "configuration should have been nil, got %v" , actualConfig )
}
}
func TestBuildConfiguration ( t * testing . T ) {
testCases := [ ] struct {
2019-06-21 09:24:04 +02:00
desc string
applications * marathon . Applications
constraints string
defaultRule string
2019-07-10 09:26:04 +02:00
expected * dynamic . Configuration
2019-01-29 17:54:05 +01:00
} {
{
desc : "simple application" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 ) ,
withTasks ( localhostTask ( taskPorts ( 80 ) ) ) ,
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"app" : {
Service : "app" ,
Rule : "Host(`app.marathon.localhost`)" ,
2019-01-29 17:54:05 +01:00
} ,
2019-04-15 18:22:07 +02:00
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-08-26 10:30:05 +02:00
"app" : { LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-04-15 18:22:07 +02:00
} } ,
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
{
desc : "filtered task" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 ) ,
withTasks ( localhostTask ( taskPorts ( 80 ) , taskState ( taskStateStaging ) ) ) ,
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-04-15 18:22:07 +02:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router { } ,
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service { } ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
{
desc : "multiple ports" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"app" : {
Service : "app" ,
Rule : "Host(`app.marathon.localhost`)" ,
2019-01-29 17:54:05 +01:00
} ,
2019-04-15 18:22:07 +02:00
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-08-26 10:30:05 +02:00
"app" : { LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-04-15 18:22:07 +02:00
} } ,
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
{
desc : "with basic auth" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.middlewares.Middleware1.basicauth.users" , "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0" ) ,
withLabel ( "traefik.http.routers.app.middlewares" , "Middleware1" ) ,
2019-01-29 17:54:05 +01:00
withTasks ( localhostTask ( taskPorts ( 80 ) ) ) ,
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"app" : {
Service : "app" ,
Rule : "Host(`app.marathon.localhost`)" ,
Middlewares : [ ] string { "Middleware1" } ,
2019-01-29 17:54:05 +01:00
} ,
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware {
2019-04-15 18:22:07 +02:00
"Middleware1" : {
2019-07-10 09:26:04 +02:00
BasicAuth : & dynamic . BasicAuth {
2019-04-15 18:22:07 +02:00
Users : [ ] string {
"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/" ,
"test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0" ,
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
2019-04-15 18:22:07 +02:00
} ,
2019-07-10 09:26:04 +02:00
Services : map [ string ] * dynamic . Service {
2019-08-26 10:30:05 +02:00
"app" : { LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-04-15 18:22:07 +02:00
} } ,
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
{
desc : "2 applications in the same service" ,
applications : withApplications (
application (
appID ( "/foo-v000" ) ,
withTasks ( localhostTask ( taskPorts ( 8080 ) ) ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.services.Service1.LoadBalancer.server.port" , "index:0" ) ,
withLabel ( "traefik.http.routers.Router1.rule" , "Host(`app.marathon.localhost`)" ) ,
2019-01-29 17:54:05 +01:00
) ,
application (
appID ( "/foo-v001" ) ,
withTasks ( localhostTask ( taskPorts ( 8081 ) ) ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.services.Service1.LoadBalancer.server.port" , "index:0" ) ,
withLabel ( "traefik.http.routers.Router1.rule" , "Host(`app.marathon.localhost`)" ) ,
2019-01-29 17:54:05 +01:00
) ,
) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"Router1" : {
Service : "Service1" ,
Rule : "Host(`app.marathon.localhost`)" ,
2019-01-29 17:54:05 +01:00
} ,
2019-04-15 18:22:07 +02:00
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-08-26 10:30:05 +02:00
"Service1" : { LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:8080" ,
2019-04-15 18:22:07 +02:00
} ,
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:8081" ,
2019-04-15 18:22:07 +02:00
} ,
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-04-15 18:22:07 +02:00
} } ,
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
{
desc : "2 applications with 2 tasks in the same service" ,
applications : withApplications (
application (
appID ( "/foo-v000" ) ,
withTasks ( localhostTask ( taskPorts ( 8080 ) ) ) ,
withTasks ( localhostTask ( taskPorts ( 8081 ) ) ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.services.Service1.LoadBalancer.server.port" , "index:0" ) ,
withLabel ( "traefik.http.routers.Router1.rule" , "Host(`app.marathon.localhost`)" ) ,
2019-01-29 17:54:05 +01:00
) ,
application (
appID ( "/foo-v001" ) ,
withTasks ( localhostTask ( taskPorts ( 8082 ) ) ) ,
withTasks ( localhostTask ( taskPorts ( 8083 ) ) ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.services.Service1.LoadBalancer.server.port" , "index:0" ) ,
withLabel ( "traefik.http.routers.Router1.rule" , "Host(`app.marathon.localhost`)" ) ,
2019-01-29 17:54:05 +01:00
) ,
) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"Router1" : {
Service : "Service1" ,
Rule : "Host(`app.marathon.localhost`)" ,
2019-01-29 17:54:05 +01:00
} ,
2019-04-15 18:22:07 +02:00
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-08-26 10:30:05 +02:00
"Service1" : { LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:8080" ,
2019-04-15 18:22:07 +02:00
} ,
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:8081" ,
2019-04-15 18:22:07 +02:00
} ,
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:8082" ,
2019-04-15 18:22:07 +02:00
} ,
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:8083" ,
2019-04-15 18:22:07 +02:00
} ,
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-04-15 18:22:07 +02:00
} } ,
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
{
desc : "2 applications" ,
applications : withApplications (
application (
appID ( "/foo" ) ,
withTasks ( localhostTask ( taskPorts ( 8080 ) ) ) ,
) ,
application (
appID ( "/bar" ) ,
withTasks ( localhostTask ( taskPorts ( 8081 ) ) ) ,
) ,
) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"foo" : {
Service : "foo" ,
Rule : "Host(`foo.marathon.localhost`)" ,
2019-01-29 17:54:05 +01:00
} ,
2019-04-15 18:22:07 +02:00
"bar" : {
Service : "bar" ,
Rule : "Host(`bar.marathon.localhost`)" ,
2019-01-29 17:54:05 +01:00
} ,
2019-04-15 18:22:07 +02:00
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-08-26 10:30:05 +02:00
"foo" : { LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:8080" ,
2019-04-15 18:22:07 +02:00
} ,
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-04-15 18:22:07 +02:00
} } ,
2019-08-26 10:30:05 +02:00
"bar" : { LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:8081" ,
2019-04-15 18:22:07 +02:00
} ,
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-04-15 18:22:07 +02:00
} } ,
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
{
desc : "two tasks no labels" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 ) ,
withTasks ( localhostTask ( taskPorts ( 80 ) ) , localhostTask ( taskPorts ( 81 ) ) ) ,
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"app" : {
Service : "app" ,
Rule : "Host(`app.marathon.localhost`)" ,
} ,
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-04-15 18:22:07 +02:00
"app" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:81" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
{
desc : "simple application with label on service" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 ) ,
withTasks ( localhostTask ( taskPorts ( 80 ) ) ) ,
2019-06-05 22:18:06 +02:00
withLabel ( "traefik.http.services.Service1.loadbalancer.passhostheader" , "true" ) ,
2019-01-29 17:54:05 +01:00
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"app" : {
Service : "Service1" ,
Rule : "Host(`app.marathon.localhost`)" ,
2019-01-29 17:54:05 +01:00
} ,
2019-04-15 18:22:07 +02:00
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-08-26 10:30:05 +02:00
"Service1" : { LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-04-15 18:22:07 +02:00
} } ,
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
{
desc : "one app with labels" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-06-05 22:18:06 +02:00
withLabel ( "traefik.http.services.Service1.loadbalancer.passhostheader" , "true" ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.routers.Router1.rule" , "Host(`foo.com`)" ) ,
withLabel ( "traefik.http.routers.Router1.service" , "Service1" ) ,
2019-01-29 17:54:05 +01:00
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"Router1" : {
Service : "Service1" ,
Rule : "Host(`foo.com`)" ,
} ,
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-04-15 18:22:07 +02:00
"Service1" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
{
desc : "one app with rule label" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.routers.Router1.rule" , "Host(`foo.com`)" ) ,
2019-01-29 17:54:05 +01:00
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
} ,
HTTP : & dynamic . HTTPConfiguration {
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-04-15 18:22:07 +02:00
"app" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
2019-07-10 09:26:04 +02:00
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"Router1" : {
Service : "app" ,
Rule : "Host(`foo.com`)" ,
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
} ,
{
desc : "one app with rule label and one service" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.routers.Router1.rule" , "Host(`foo.com`)" ) ,
2019-06-05 22:18:06 +02:00
withLabel ( "traefik.http.services.Service1.loadbalancer.passhostheader" , "true" ) ,
2019-01-29 17:54:05 +01:00
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"Router1" : {
Service : "Service1" ,
Rule : "Host(`foo.com`)" ,
} ,
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-04-15 18:22:07 +02:00
"Service1" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
{
desc : "one app with rule label and two services" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.routers.Router1.rule" , "Host(`foo.com`)" ) ,
2019-06-05 22:18:06 +02:00
withLabel ( "traefik.http.services.Service1.loadbalancer.passhostheader" , "true" ) ,
withLabel ( "traefik.http.services.Service2.loadbalancer.passhostheader" , "true" ) ,
2019-01-29 17:54:05 +01:00
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
} ,
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router { } ,
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-04-15 18:22:07 +02:00
"Service1" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
2019-04-15 18:22:07 +02:00
"Service2" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
{
2019-06-05 22:18:06 +02:00
desc : "two apps with same service name and different passhostheader" ,
2019-01-29 17:54:05 +01:00
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-06-05 22:18:06 +02:00
withLabel ( "traefik.http.services.Service1.loadbalancer.passhostheader" , "false" ) ,
2019-01-29 17:54:05 +01:00
) ,
application (
appID ( "/app2" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-06-05 22:18:06 +02:00
withLabel ( "traefik.http.services.Service1.loadbalancer.passhostheader" , "true" ) ,
2019-01-29 17:54:05 +01:00
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-04-15 18:22:07 +02:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"app" : {
Service : "Service1" ,
Rule : "Host(`app.marathon.localhost`)" ,
} ,
"app2" : {
Service : "Service1" ,
Rule : "Host(`app2.marathon.localhost`)" ,
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service { } ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
{
desc : "two apps with two identical middleware" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-08-26 12:20:06 +02:00
withLabel ( "traefik.http.middlewares.Middleware1.inflightreq.amount" , "42" ) ,
2019-01-29 17:54:05 +01:00
) ,
application (
appID ( "/app2" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-08-26 12:20:06 +02:00
withLabel ( "traefik.http.middlewares.Middleware1.inflightreq.amount" , "42" ) ,
2019-01-29 17:54:05 +01:00
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"app" : {
Service : "app" ,
Rule : "Host(`app.marathon.localhost`)" ,
} ,
"app2" : {
Service : "app2" ,
Rule : "Host(`app2.marathon.localhost`)" ,
2019-01-29 17:54:05 +01:00
} ,
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware {
2019-04-15 18:22:07 +02:00
"Middleware1" : {
2019-08-26 12:20:06 +02:00
InFlightReq : & dynamic . InFlightReq {
Amount : 42 ,
SourceCriterion : & dynamic . SourceCriterion {
RequestHost : true ,
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
2019-07-10 09:26:04 +02:00
Services : map [ string ] * dynamic . Service {
2019-04-15 18:22:07 +02:00
"app" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-04-15 18:22:07 +02:00
} ,
} ,
"app2" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
{
desc : "two apps with two different middlewares" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-08-26 12:20:06 +02:00
withLabel ( "traefik.http.middlewares.Middleware1.inflightreq.amount" , "42" ) ,
2019-01-29 17:54:05 +01:00
) ,
application (
appID ( "/app2" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-08-26 12:20:06 +02:00
withLabel ( "traefik.http.middlewares.Middleware1.inflightreq.amount" , "41" ) ,
2019-01-29 17:54:05 +01:00
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"app" : {
Service : "app" ,
Rule : "Host(`app.marathon.localhost`)" ,
} ,
"app2" : {
Service : "app2" ,
Rule : "Host(`app2.marathon.localhost`)" ,
} ,
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-04-15 18:22:07 +02:00
"app" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
2019-04-15 18:22:07 +02:00
"app2" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
{
desc : "two apps with two different routers with same name" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.routers.Router1.rule" , "Host(`foo.com`)" ) ,
2019-01-29 17:54:05 +01:00
) ,
application (
appID ( "/app2" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.routers.Router1.rule" , "Host(`bar.com`)" ) ,
2019-01-29 17:54:05 +01:00
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
} ,
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router { } ,
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-04-15 18:22:07 +02:00
"app" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
2019-04-15 18:22:07 +02:00
"app2" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
{
desc : "two apps with two identical routers with same name" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.routers.Router1.rule" , "Host(`foo.com`)" ) ,
2019-06-05 22:18:06 +02:00
withLabel ( "traefik.http.services.Service1.LoadBalancer.passhostheader" , "true" ) ,
2019-01-29 17:54:05 +01:00
) ,
application (
appID ( "/app2" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.routers.Router1.rule" , "Host(`foo.com`)" ) ,
2019-06-05 22:18:06 +02:00
withLabel ( "traefik.http.services.Service1.LoadBalancer.passhostheader" , "true" ) ,
2019-01-29 17:54:05 +01:00
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"Router1" : {
Service : "Service1" ,
Rule : "Host(`foo.com`)" ,
} ,
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-04-15 18:22:07 +02:00
"Service1" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
{
desc : "two apps with two identical routers with same name" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.routers.Router1.rule" , "Host(`foo.com`)" ) ,
2019-01-29 17:54:05 +01:00
) ,
application (
appID ( "/app2" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.routers.Router1.rule" , "Host(`foo.com`)" ) ,
2019-01-29 17:54:05 +01:00
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
} ,
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router { } ,
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-04-15 18:22:07 +02:00
"app" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
2019-04-15 18:22:07 +02:00
"app2" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
{
desc : "one app with wrong label" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
withLabel ( "traefik.wrong.label" , "tchouk" ) ,
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"app" : {
Service : "app" ,
Rule : "Host(`app.marathon.localhost`)" ,
} ,
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-04-15 18:22:07 +02:00
"app" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
{
desc : "one app with label port" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.services.Service1.LoadBalancer.server.scheme" , "h2c" ) ,
withLabel ( "traefik.http.services.Service1.LoadBalancer.server.port" , "90" ) ,
2019-01-29 17:54:05 +01:00
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"app" : {
Service : "Service1" ,
Rule : "Host(`app.marathon.localhost`)" ,
} ,
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-04-15 18:22:07 +02:00
"Service1" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "h2c://localhost:90" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
{
desc : "one app with label port on two services" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.services.Service1.LoadBalancer.server.port" , "" ) ,
withLabel ( "traefik.http.services.Service2.LoadBalancer.server.port" , "8080" ) ,
2019-01-29 17:54:05 +01:00
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
} ,
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router { } ,
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-04-15 18:22:07 +02:00
"Service1" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
2019-04-15 18:22:07 +02:00
"Service2" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:8080" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
{
desc : "one app without port" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( ) ) ,
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-04-15 18:22:07 +02:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router { } ,
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service { } ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
{
desc : "one app without port with middleware" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( ) ) ,
2019-03-14 09:30:04 +01:00
withLabel ( "traefik.http.middlewares.Middleware1.basicauth.users" , "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0" ) ,
2019-01-29 17:54:05 +01:00
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-04-15 18:22:07 +02:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router { } ,
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service { } ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
{
desc : "one app with traefik.enable=false" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( ) ) ,
withLabel ( "traefik.enable" , "false" ) ,
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-04-15 18:22:07 +02:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router { } ,
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service { } ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
{
desc : "one app with traefik.enable=false" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( ) ) ,
withLabel ( "traefik.enable" , "false" ) ,
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-04-15 18:22:07 +02:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router { } ,
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service { } ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
{
desc : "one app with non matching constraint" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
withLabel ( "traefik.tags" , "foo" ) ,
) ) ,
2019-06-21 09:24:04 +02:00
constraints : ` Label("traefik.tags", "bar") ` ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-04-15 18:22:07 +02:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router { } ,
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service { } ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
{
desc : "one app with non matching marathon constraint" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
constraint ( "rack_id:CLUSTER:rack-1" ) ,
) ) ,
2019-06-21 09:24:04 +02:00
constraints : ` MarathonConstraint("rack_id:CLUSTER:rack-2") ` ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-04-15 18:22:07 +02:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router { } ,
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service { } ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
{
desc : "one app with matching marathon constraint" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
constraint ( "rack_id:CLUSTER:rack-1" ) ,
) ) ,
2019-06-21 09:24:04 +02:00
constraints : ` MarathonConstraint("rack_id:CLUSTER:rack-1") ` ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"app" : {
Service : "app" ,
Rule : "Host(`app.marathon.localhost`)" ,
} ,
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-04-15 18:22:07 +02:00
"app" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
{
desc : "one app with matching constraint" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
withLabel ( "traefik.tags" , "bar" ) ,
) ) ,
2019-06-21 09:24:04 +02:00
constraints : ` Label("traefik.tags", "bar") ` ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-01-29 17:54:05 +01:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"app" : {
Service : "app" ,
Rule : "Host(`app.marathon.localhost`)" ,
} ,
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-04-15 18:22:07 +02:00
"app" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
{
desc : "one app with group as subdomain rule" ,
2019-01-30 16:24:07 +01:00
defaultRule : ` Host(" {{ .Name | trimPrefix "/" | splitList "/" | strsToItfs | reverse | join "." }} .marathon.localhost") ` ,
2019-01-29 17:54:05 +01:00
applications : withApplications (
application (
appID ( "/a/b/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService { } ,
2019-04-15 18:22:07 +02:00
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"a_b_app" : {
Service : "a_b_app" ,
Rule : ` Host("app.b.a.marathon.localhost") ` ,
} ,
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-04-15 18:22:07 +02:00
"a_b_app" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-04-15 18:22:07 +02:00
} ,
} ,
2019-01-29 17:54:05 +01:00
} ,
} ,
2019-04-15 18:22:07 +02:00
} ,
} ,
{
desc : "one app with tcp labels" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
withLabel ( "traefik.tcp.routers.foo.rule" , "HostSNI(`foo.bar`)" ) ,
withLabel ( "traefik.tcp.routers.foo.tls" , "true" ) ,
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter {
2019-04-15 18:22:07 +02:00
"foo" : {
Service : "app" ,
Rule : "HostSNI(`foo.bar`)" ,
2019-07-10 09:26:04 +02:00
TLS : & dynamic . RouterTCPTLSConfig { } ,
2019-04-15 18:22:07 +02:00
} ,
} ,
2019-07-10 09:26:04 +02:00
Services : map [ string ] * dynamic . TCPService {
2019-04-15 18:22:07 +02:00
"app" : {
2019-09-13 20:00:06 +02:00
LoadBalancer : & dynamic . TCPServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . TCPServer {
2019-04-15 18:22:07 +02:00
{
Address : "localhost:80" ,
} ,
2019-01-29 17:54:05 +01:00
} ,
2019-09-13 17:46:04 +02:00
TerminationDelay : Int ( 100 ) ,
2019-04-15 18:22:07 +02:00
} ,
} ,
} ,
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router { } ,
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service { } ,
2019-04-15 18:22:07 +02:00
} ,
} ,
} ,
{
desc : "one app with tcp labels without rule" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
withLabel ( "traefik.tcp.routers.foo.tls" , "true" ) ,
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter { } ,
Services : map [ string ] * dynamic . TCPService {
2019-04-15 18:22:07 +02:00
"app" : {
2019-09-13 20:00:06 +02:00
LoadBalancer : & dynamic . TCPServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . TCPServer {
2019-04-15 18:22:07 +02:00
{
Address : "localhost:80" ,
} ,
} ,
2019-09-13 17:46:04 +02:00
TerminationDelay : Int ( 100 ) ,
2019-04-15 18:22:07 +02:00
} ,
} ,
} ,
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router { } ,
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service { } ,
2019-04-15 18:22:07 +02:00
} ,
} ,
} ,
{
desc : "one app with tcp labels with port" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
withLabel ( "traefik.tcp.routers.foo.rule" , "HostSNI(`foo.bar`)" ) ,
withLabel ( "traefik.tcp.routers.foo.tls" , "true" ) ,
withLabel ( "traefik.tcp.services.foo.loadbalancer.server.port" , "8080" ) ,
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter {
2019-04-15 18:22:07 +02:00
"foo" : {
Service : "foo" ,
Rule : "HostSNI(`foo.bar`)" ,
2019-07-10 09:26:04 +02:00
TLS : & dynamic . RouterTCPTLSConfig { } ,
2019-04-15 18:22:07 +02:00
} ,
} ,
2019-07-10 09:26:04 +02:00
Services : map [ string ] * dynamic . TCPService {
2019-04-15 18:22:07 +02:00
"foo" : {
2019-09-13 20:00:06 +02:00
LoadBalancer : & dynamic . TCPServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . TCPServer {
2019-04-15 18:22:07 +02:00
{
Address : "localhost:8080" ,
} ,
} ,
2019-09-13 17:46:04 +02:00
TerminationDelay : Int ( 100 ) ,
} ,
} ,
} ,
} ,
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router { } ,
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service { } ,
} ,
} ,
} ,
{
desc : "one app with tcp labels with port, with termination delay" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
withLabel ( "traefik.tcp.routers.foo.rule" , "HostSNI(`foo.bar`)" ) ,
withLabel ( "traefik.tcp.routers.foo.tls" , "true" ) ,
withLabel ( "traefik.tcp.services.foo.loadbalancer.server.port" , "8080" ) ,
withLabel ( "traefik.tcp.services.foo.loadbalancer.terminationdelay" , "200" ) ,
) ) ,
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter {
"foo" : {
Service : "foo" ,
Rule : "HostSNI(`foo.bar`)" ,
TLS : & dynamic . RouterTCPTLSConfig { } ,
} ,
} ,
Services : map [ string ] * dynamic . TCPService {
"foo" : {
2019-09-13 20:00:06 +02:00
LoadBalancer : & dynamic . TCPServersLoadBalancer {
2019-09-13 17:46:04 +02:00
Servers : [ ] dynamic . TCPServer {
{
Address : "localhost:8080" ,
} ,
} ,
TerminationDelay : Int ( 200 ) ,
2019-04-15 18:22:07 +02:00
} ,
} ,
} ,
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router { } ,
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service { } ,
2019-04-15 18:22:07 +02:00
} ,
} ,
} ,
{
desc : "one app with tcp labels with port and http service" ,
applications : withApplications (
application (
appID ( "/app" ) ,
appPorts ( 80 , 81 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
withLabel ( "traefik.tcp.routers.foo.rule" , "HostSNI(`foo.bar`)" ) ,
withLabel ( "traefik.tcp.routers.foo.tls" , "true" ) ,
withLabel ( "traefik.tcp.services.foo.loadbalancer.server.port" , "8080" ) ,
2019-06-05 22:18:06 +02:00
withLabel ( "traefik.http.services.bar.loadbalancer.passhostheader" , "true" ) ,
2019-04-15 18:22:07 +02:00
) ) ,
2019-07-10 09:26:04 +02:00
expected : & dynamic . Configuration {
TCP : & dynamic . TCPConfiguration {
Routers : map [ string ] * dynamic . TCPRouter {
2019-04-15 18:22:07 +02:00
"foo" : {
Service : "foo" ,
Rule : "HostSNI(`foo.bar`)" ,
2019-07-10 09:26:04 +02:00
TLS : & dynamic . RouterTCPTLSConfig { } ,
2019-04-15 18:22:07 +02:00
} ,
} ,
2019-07-10 09:26:04 +02:00
Services : map [ string ] * dynamic . TCPService {
2019-04-15 18:22:07 +02:00
"foo" : {
2019-09-13 20:00:06 +02:00
LoadBalancer : & dynamic . TCPServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . TCPServer {
2019-04-15 18:22:07 +02:00
{
Address : "localhost:8080" ,
} ,
} ,
2019-09-13 17:46:04 +02:00
TerminationDelay : Int ( 100 ) ,
2019-04-15 18:22:07 +02:00
} ,
} ,
} ,
} ,
2019-07-10 09:26:04 +02:00
HTTP : & dynamic . HTTPConfiguration {
Routers : map [ string ] * dynamic . Router {
2019-04-15 18:22:07 +02:00
"app" : {
Service : "bar" ,
Rule : "Host(`app.marathon.localhost`)" ,
} ,
} ,
2019-07-10 09:26:04 +02:00
Middlewares : map [ string ] * dynamic . Middleware { } ,
Services : map [ string ] * dynamic . Service {
2019-04-15 18:22:07 +02:00
"bar" : {
2019-08-26 10:30:05 +02:00
LoadBalancer : & dynamic . ServersLoadBalancer {
2019-07-10 09:26:04 +02:00
Servers : [ ] dynamic . Server {
2019-04-15 18:22:07 +02:00
{
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-04-15 18:22:07 +02:00
} ,
} ,
2019-09-30 18:12:04 +02:00
PassHostHeader : Bool ( true ) ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
}
for _ , test := range testCases {
test := test
t . Run ( test . desc , func ( t * testing . T ) {
t . Parallel ( )
2019-01-30 16:24:07 +01:00
defaultRule := "Host(`{{ normalize .Name }}.marathon.localhost`)"
2019-01-29 17:54:05 +01:00
if len ( test . defaultRule ) > 0 {
defaultRule = test . defaultRule
}
p := & Provider {
2019-06-21 09:24:04 +02:00
DefaultRule : defaultRule ,
ExposedByDefault : true ,
2019-01-29 17:54:05 +01:00
}
p . Constraints = test . constraints
err := p . Init ( )
require . NoError ( t , err )
actualConfig := p . buildConfiguration ( context . Background ( ) , test . applications )
assert . NotNil ( t , actualConfig )
2019-04-15 18:22:07 +02:00
assert . Equal ( t , test . expected , actualConfig )
2019-01-29 17:54:05 +01:00
} )
}
}
func TestApplicationFilterEnabled ( t * testing . T ) {
testCases := [ ] struct {
desc string
exposedByDefault bool
enabledLabel string
expected bool
} {
{
desc : "exposed and tolerated by valid label value" ,
exposedByDefault : true ,
enabledLabel : "true" ,
expected : true ,
} ,
{
desc : "exposed but overridden by label" ,
exposedByDefault : true ,
enabledLabel : "false" ,
expected : false ,
} ,
{
desc : "non-exposed but overridden by label" ,
exposedByDefault : false ,
enabledLabel : "true" ,
expected : true ,
} ,
}
for _ , test := range testCases {
test := test
t . Run ( test . desc , func ( t * testing . T ) {
t . Parallel ( )
2019-06-17 11:48:05 +02:00
provider := & Provider { ExposedByDefault : true }
2019-01-29 17:54:05 +01:00
app := application ( withLabel ( "traefik.enable" , test . enabledLabel ) )
extraConf , err := provider . getConfiguration ( app )
require . NoError ( t , err )
2019-06-21 09:24:04 +02:00
if provider . keepApplication ( context . Background ( ) , extraConf , stringValueMap ( app . Labels ) ) != test . expected {
2019-01-29 17:54:05 +01:00
t . Errorf ( "got unexpected filtering = %t" , ! test . expected )
}
} )
}
}
func TestGetServer ( t * testing . T ) {
type expected struct {
2019-07-10 09:26:04 +02:00
server dynamic . Server
2019-01-29 17:54:05 +01:00
error string
}
testCases := [ ] struct {
desc string
provider Provider
app marathon . Application
extraConf configuration
2019-07-10 09:26:04 +02:00
defaultServer dynamic . Server
2019-01-29 17:54:05 +01:00
expected expected
} {
{
desc : "undefined host" ,
provider : Provider { } ,
app : application ( ) ,
extraConf : configuration { } ,
2019-07-10 09:26:04 +02:00
defaultServer : dynamic . Server { } ,
2019-01-29 17:54:05 +01:00
expected : expected {
error : ` host is undefined for task "taskID" app "" ` ,
} ,
} ,
{
desc : "with task port" ,
provider : Provider { } ,
app : application (
appID ( "/app" ) ,
appPorts ( 80 ) ,
withTasks ( localhostTask ( taskPorts ( 80 ) ) ) ,
) ,
extraConf : configuration { } ,
2019-07-10 09:26:04 +02:00
defaultServer : dynamic . Server {
2019-01-29 17:54:05 +01:00
Scheme : "http" ,
} ,
expected : expected {
2019-07-10 09:26:04 +02:00
server : dynamic . Server {
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
{
desc : "without task port" ,
provider : Provider { } ,
app : application (
appID ( "/app" ) ,
appPorts ( 80 ) ,
withTasks ( localhostTask ( ) ) ,
) ,
extraConf : configuration { } ,
2019-07-10 09:26:04 +02:00
defaultServer : dynamic . Server {
2019-01-29 17:54:05 +01:00
Scheme : "http" ,
} ,
expected : expected {
error : "unable to process ports for /app taskID: no port found" ,
} ,
} ,
{
desc : "with default server port" ,
provider : Provider { } ,
app : application (
appID ( "/app" ) ,
appPorts ( 80 ) ,
withTasks ( localhostTask ( taskPorts ( 80 ) ) ) ,
) ,
extraConf : configuration { } ,
2019-07-10 09:26:04 +02:00
defaultServer : dynamic . Server {
2019-01-29 17:54:05 +01:00
Scheme : "http" ,
Port : "88" ,
} ,
expected : expected {
2019-07-10 09:26:04 +02:00
server : dynamic . Server {
2019-06-05 22:18:06 +02:00
URL : "http://localhost:88" ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
{
desc : "with invalid default server port" ,
provider : Provider { } ,
app : application (
appID ( "/app" ) ,
appPorts ( 80 ) ,
withTasks ( localhostTask ( taskPorts ( 80 ) ) ) ,
) ,
extraConf : configuration { } ,
2019-07-10 09:26:04 +02:00
defaultServer : dynamic . Server {
2019-01-29 17:54:05 +01:00
Scheme : "http" ,
Port : "aaaa" ,
} ,
expected : expected {
error : ` unable to process ports for /app taskID: strconv.Atoi: parsing "aaaa": invalid syntax ` ,
} ,
} ,
{
desc : "with negative default server port" ,
provider : Provider { } ,
app : application (
appID ( "/app" ) ,
appPorts ( 80 ) ,
withTasks ( localhostTask ( taskPorts ( 80 ) ) ) ,
) ,
extraConf : configuration { } ,
2019-07-10 09:26:04 +02:00
defaultServer : dynamic . Server {
2019-01-29 17:54:05 +01:00
Scheme : "http" ,
Port : "-6" ,
} ,
expected : expected {
error : ` unable to process ports for /app taskID: explicitly specified port -6 must be greater than zero ` ,
} ,
} ,
{
desc : "with port index" ,
provider : Provider { } ,
app : application (
appID ( "/app" ) ,
appPorts ( 80 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
) ,
extraConf : configuration { } ,
2019-07-10 09:26:04 +02:00
defaultServer : dynamic . Server {
2019-01-29 17:54:05 +01:00
Scheme : "http" ,
Port : "index:1" ,
} ,
expected : expected {
2019-07-10 09:26:04 +02:00
server : dynamic . Server {
2019-06-05 22:18:06 +02:00
URL : "http://localhost:81" ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
{
desc : "with out of range port index" ,
provider : Provider { } ,
app : application (
appID ( "/app" ) ,
appPorts ( 80 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
) ,
extraConf : configuration { } ,
2019-07-10 09:26:04 +02:00
defaultServer : dynamic . Server {
2019-01-29 17:54:05 +01:00
Scheme : "http" ,
Port : "index:2" ,
} ,
expected : expected {
error : "unable to process ports for /app taskID: index 2 must be within range (0, 1)" ,
} ,
} ,
{
desc : "with invalid port index" ,
provider : Provider { } ,
app : application (
appID ( "/app" ) ,
appPorts ( 80 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
) ,
extraConf : configuration { } ,
2019-07-10 09:26:04 +02:00
defaultServer : dynamic . Server {
2019-01-29 17:54:05 +01:00
Scheme : "http" ,
Port : "index:aaa" ,
} ,
expected : expected {
error : ` unable to process ports for /app taskID: strconv.Atoi: parsing "aaa": invalid syntax ` ,
} ,
} ,
{
desc : "with application port and no task port" ,
provider : Provider { } ,
app : application (
appID ( "/app" ) ,
appPorts ( 80 ) ,
portDefinition ( 80 ) ,
withTasks ( localhostTask ( ) ) ,
) ,
extraConf : configuration { } ,
2019-07-10 09:26:04 +02:00
defaultServer : dynamic . Server {
2019-01-29 17:54:05 +01:00
Scheme : "http" ,
} ,
expected : expected {
2019-07-10 09:26:04 +02:00
server : dynamic . Server {
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
{
desc : "with IP per task" ,
provider : Provider { } ,
app : application (
appID ( "/app" ) ,
appPorts ( 80 ) ,
ipAddrPerTask ( 88 ) ,
withTasks ( localhostTask ( ) ) ,
) ,
extraConf : configuration { } ,
2019-07-10 09:26:04 +02:00
defaultServer : dynamic . Server {
2019-01-29 17:54:05 +01:00
Scheme : "http" ,
} ,
expected : expected {
2019-07-10 09:26:04 +02:00
server : dynamic . Server {
2019-06-05 22:18:06 +02:00
URL : "http://127.0.0.1:88" ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
{
desc : "with container network" ,
provider : Provider { } ,
app : application (
containerNetwork ( ) ,
appID ( "/app" ) ,
appPorts ( 80 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
) ,
extraConf : configuration { } ,
2019-07-10 09:26:04 +02:00
defaultServer : dynamic . Server {
2019-01-29 17:54:05 +01:00
Scheme : "http" ,
} ,
expected : expected {
2019-07-10 09:26:04 +02:00
server : dynamic . Server {
2019-06-05 22:18:06 +02:00
URL : "http://127.0.0.1:80" ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
{
desc : "with bridge network" ,
provider : Provider { } ,
app : application (
bridgeNetwork ( ) ,
appID ( "/app" ) ,
appPorts ( 83 ) ,
withTasks ( localhostTask ( taskPorts ( 80 , 81 ) ) ) ,
) ,
extraConf : configuration { } ,
2019-07-10 09:26:04 +02:00
defaultServer : dynamic . Server {
2019-01-29 17:54:05 +01:00
Scheme : "http" ,
} ,
expected : expected {
2019-07-10 09:26:04 +02:00
server : dynamic . Server {
2019-06-05 22:18:06 +02:00
URL : "http://localhost:80" ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
{
desc : "with several IP addresses on task" ,
provider : Provider { } ,
app : application (
ipAddrPerTask ( 88 ) ,
appID ( "/app" ) ,
appPorts ( 83 ) ,
withTasks (
task (
withTaskID ( "myTask" ) ,
host ( "localhost" ) ,
ipAddresses ( "127.0.0.1" , "127.0.0.2" ) ,
taskState ( taskStateRunning ) ,
) ) ,
) ,
extraConf : configuration {
Marathon : specificConfiguration {
IPAddressIdx : 0 ,
} ,
} ,
2019-07-10 09:26:04 +02:00
defaultServer : dynamic . Server {
2019-01-29 17:54:05 +01:00
Scheme : "http" ,
} ,
expected : expected {
2019-07-10 09:26:04 +02:00
server : dynamic . Server {
2019-06-05 22:18:06 +02:00
URL : "http://127.0.0.1:88" ,
2019-01-29 17:54:05 +01:00
} ,
} ,
} ,
{
desc : "with several IP addresses on task, undefined [MinInt32] IPAddressIdx" ,
provider : Provider { } ,
app : application (
ipAddrPerTask ( 88 ) ,
appID ( "/app" ) ,
appPorts ( 83 ) ,
withTasks (
task (
host ( "localhost" ) ,
ipAddresses ( "127.0.0.1" , "127.0.0.2" ) ,
taskState ( taskStateRunning ) ,
) ) ,
) ,
extraConf : configuration {
Marathon : specificConfiguration {
IPAddressIdx : math . MinInt32 ,
} ,
} ,
2019-07-10 09:26:04 +02:00
defaultServer : dynamic . Server {
2019-01-29 17:54:05 +01:00
Scheme : "http" ,
} ,
expected : expected {
error : "found 2 task IP addresses but missing IP address index for Marathon application /app on task taskID" ,
} ,
} ,
{
desc : "with several IP addresses on task, IPAddressIdx out of range" ,
provider : Provider { } ,
app : application (
ipAddrPerTask ( 88 ) ,
appID ( "/app" ) ,
appPorts ( 83 ) ,
withTasks (
task (
host ( "localhost" ) ,
ipAddresses ( "127.0.0.1" , "127.0.0.2" ) ,
taskState ( taskStateRunning ) ,
) ) ,
) ,
extraConf : configuration {
Marathon : specificConfiguration {
IPAddressIdx : 3 ,
} ,
} ,
2019-07-10 09:26:04 +02:00
defaultServer : dynamic . Server {
2019-01-29 17:54:05 +01:00
Scheme : "http" ,
} ,
expected : expected {
error : "cannot use IP address index to select from 2 task IP addresses for Marathon application /app on task taskID" ,
} ,
} ,
{
desc : "with task without IP address" ,
provider : Provider { } ,
app : application (
ipAddrPerTask ( 88 ) ,
appID ( "/app" ) ,
appPorts ( 83 ) ,
withTasks (
task (
host ( "localhost" ) ,
taskState ( taskStateRunning ) ,
) ) ,
) ,
extraConf : configuration { } ,
2019-07-10 09:26:04 +02:00
defaultServer : dynamic . Server {
2019-01-29 17:54:05 +01:00
Scheme : "http" ,
} ,
expected : expected {
error : "missing IP address for Marathon application /app on task taskID" ,
} ,
} ,
}
for _ , test := range testCases {
test := test
t . Run ( test . desc , func ( t * testing . T ) {
t . Parallel ( )
task := task ( )
if len ( test . app . Tasks ) > 0 {
task = * test . app . Tasks [ 0 ]
}
server , err := test . provider . getServer ( test . app , task , test . extraConf , test . defaultServer )
if len ( test . expected . error ) > 0 {
require . EqualError ( t , err , test . expected . error )
} else {
require . NoError ( t , err )
assert . Equal ( t , test . expected . server , server )
}
} )
}
}