2017-09-15 18:56:04 +00:00
|
|
|
package configuration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-04-16 15:42:03 +00:00
|
|
|
"github.com/containous/traefik/middlewares/tracing"
|
|
|
|
"github.com/containous/traefik/middlewares/tracing/jaeger"
|
|
|
|
"github.com/containous/traefik/middlewares/tracing/zipkin"
|
2017-10-11 08:38:03 +00:00
|
|
|
"github.com/containous/traefik/provider"
|
|
|
|
"github.com/containous/traefik/provider/file"
|
2018-04-16 15:42:03 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2017-09-15 18:56:04 +00:00
|
|
|
)
|
|
|
|
|
2017-10-11 08:38:03 +00:00
|
|
|
const defaultConfigFile = "traefik.toml"
|
|
|
|
|
|
|
|
func TestSetEffectiveConfigurationFileProviderFilename(t *testing.T) {
|
2018-04-16 15:42:03 +00:00
|
|
|
testCases := []struct {
|
2018-05-22 10:02:03 +00:00
|
|
|
desc string
|
|
|
|
fileProvider *file.Provider
|
|
|
|
wantFileProviderFilename string
|
|
|
|
wantFileProviderTraefikFile string
|
2017-10-11 08:38:03 +00:00
|
|
|
}{
|
|
|
|
{
|
2018-05-22 10:02:03 +00:00
|
|
|
desc: "no filename for file provider given",
|
|
|
|
fileProvider: &file.Provider{},
|
|
|
|
wantFileProviderFilename: "",
|
|
|
|
wantFileProviderTraefikFile: defaultConfigFile,
|
2017-10-11 08:38:03 +00:00
|
|
|
},
|
|
|
|
{
|
2018-05-22 10:02:03 +00:00
|
|
|
desc: "filename for file provider given",
|
|
|
|
fileProvider: &file.Provider{BaseProvider: provider.BaseProvider{Filename: "other.toml"}},
|
|
|
|
wantFileProviderFilename: "other.toml",
|
|
|
|
wantFileProviderTraefikFile: defaultConfigFile,
|
2017-10-11 08:38:03 +00:00
|
|
|
},
|
2018-03-22 15:14:04 +00:00
|
|
|
{
|
2018-05-22 10:02:03 +00:00
|
|
|
desc: "directory for file provider given",
|
|
|
|
fileProvider: &file.Provider{Directory: "/"},
|
|
|
|
wantFileProviderFilename: "",
|
|
|
|
wantFileProviderTraefikFile: defaultConfigFile,
|
2018-03-22 15:14:04 +00:00
|
|
|
},
|
2017-10-11 08:38:03 +00:00
|
|
|
}
|
|
|
|
|
2018-04-16 15:42:03 +00:00
|
|
|
for _, test := range testCases {
|
2017-10-11 08:38:03 +00:00
|
|
|
test := test
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
2018-04-16 15:42:03 +00:00
|
|
|
|
2017-10-11 08:38:03 +00:00
|
|
|
gc := &GlobalConfiguration{
|
|
|
|
File: test.fileProvider,
|
|
|
|
}
|
|
|
|
|
|
|
|
gc.SetEffectiveConfiguration(defaultConfigFile)
|
|
|
|
|
2018-04-16 15:42:03 +00:00
|
|
|
assert.Equal(t, test.wantFileProviderFilename, gc.File.Filename)
|
2018-05-22 10:02:03 +00:00
|
|
|
assert.Equal(t, test.wantFileProviderTraefikFile, gc.File.TraefikFile)
|
2018-04-16 15:42:03 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetEffectiveConfigurationTracing(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
tracing *tracing.Tracing
|
|
|
|
expected *tracing.Tracing
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "no tracing configuration",
|
|
|
|
tracing: &tracing.Tracing{},
|
|
|
|
expected: &tracing.Tracing{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "tracing bad backend name",
|
|
|
|
tracing: &tracing.Tracing{
|
|
|
|
Backend: "powpow",
|
|
|
|
},
|
|
|
|
expected: &tracing.Tracing{
|
|
|
|
Backend: "powpow",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "tracing jaeger backend name",
|
|
|
|
tracing: &tracing.Tracing{
|
|
|
|
Backend: "jaeger",
|
|
|
|
Zipkin: &zipkin.Config{
|
|
|
|
HTTPEndpoint: "http://localhost:9411/api/v1/spans",
|
|
|
|
SameSpan: false,
|
|
|
|
ID128Bit: true,
|
|
|
|
Debug: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: &tracing.Tracing{
|
|
|
|
Backend: "jaeger",
|
|
|
|
Jaeger: &jaeger.Config{
|
|
|
|
SamplingServerURL: "http://localhost:5778/sampling",
|
|
|
|
SamplingType: "const",
|
|
|
|
SamplingParam: 1.0,
|
2018-04-24 17:22:03 +00:00
|
|
|
LocalAgentHostPort: "127.0.0.1:6831",
|
2018-08-01 11:52:03 +00:00
|
|
|
Propagation: "jaeger",
|
|
|
|
Gen128Bit: false,
|
2018-04-16 15:42:03 +00:00
|
|
|
},
|
|
|
|
Zipkin: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "tracing zipkin backend name",
|
|
|
|
tracing: &tracing.Tracing{
|
|
|
|
Backend: "zipkin",
|
|
|
|
Jaeger: &jaeger.Config{
|
|
|
|
SamplingServerURL: "http://localhost:5778/sampling",
|
|
|
|
SamplingType: "const",
|
|
|
|
SamplingParam: 1.0,
|
2018-04-24 17:22:03 +00:00
|
|
|
LocalAgentHostPort: "127.0.0.1:6831",
|
2018-04-16 15:42:03 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: &tracing.Tracing{
|
|
|
|
Backend: "zipkin",
|
|
|
|
Jaeger: nil,
|
|
|
|
Zipkin: &zipkin.Config{
|
|
|
|
HTTPEndpoint: "http://localhost:9411/api/v1/spans",
|
|
|
|
SameSpan: false,
|
|
|
|
ID128Bit: true,
|
|
|
|
Debug: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "tracing zipkin backend name value override",
|
|
|
|
tracing: &tracing.Tracing{
|
|
|
|
Backend: "zipkin",
|
|
|
|
Jaeger: &jaeger.Config{
|
|
|
|
SamplingServerURL: "http://localhost:5778/sampling",
|
|
|
|
SamplingType: "const",
|
|
|
|
SamplingParam: 1.0,
|
2018-04-24 17:22:03 +00:00
|
|
|
LocalAgentHostPort: "127.0.0.1:6831",
|
2018-04-16 15:42:03 +00:00
|
|
|
},
|
|
|
|
Zipkin: &zipkin.Config{
|
|
|
|
HTTPEndpoint: "http://powpow:9411/api/v1/spans",
|
|
|
|
SameSpan: true,
|
|
|
|
ID128Bit: true,
|
|
|
|
Debug: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: &tracing.Tracing{
|
|
|
|
Backend: "zipkin",
|
|
|
|
Jaeger: nil,
|
|
|
|
Zipkin: &zipkin.Config{
|
|
|
|
HTTPEndpoint: "http://powpow:9411/api/v1/spans",
|
|
|
|
SameSpan: true,
|
|
|
|
ID128Bit: true,
|
|
|
|
Debug: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
test := test
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
gc := &GlobalConfiguration{
|
|
|
|
Tracing: test.tracing,
|
2017-10-11 08:38:03 +00:00
|
|
|
}
|
2018-04-16 15:42:03 +00:00
|
|
|
|
|
|
|
gc.SetEffectiveConfiguration(defaultConfigFile)
|
|
|
|
|
|
|
|
assert.Equal(t, test.expected, gc.Tracing)
|
2017-09-26 08:22:03 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|