2017-10-02 10:32:02 +02:00
package anonymize
import (
2018-10-01 19:18:03 +02:00
"os"
2017-10-02 10:32:02 +02:00
"testing"
"time"
2019-08-03 03:58:23 +02:00
"github.com/containous/traefik/v2/pkg/config/static"
"github.com/containous/traefik/v2/pkg/ping"
"github.com/containous/traefik/v2/pkg/provider/acme"
"github.com/containous/traefik/v2/pkg/provider/docker"
"github.com/containous/traefik/v2/pkg/provider/file"
"github.com/containous/traefik/v2/pkg/provider/kubernetes/crd"
"github.com/containous/traefik/v2/pkg/provider/kubernetes/ingress"
traefiktls "github.com/containous/traefik/v2/pkg/tls"
"github.com/containous/traefik/v2/pkg/tracing/datadog"
"github.com/containous/traefik/v2/pkg/tracing/haystack"
"github.com/containous/traefik/v2/pkg/tracing/instana"
"github.com/containous/traefik/v2/pkg/tracing/jaeger"
"github.com/containous/traefik/v2/pkg/tracing/zipkin"
"github.com/containous/traefik/v2/pkg/types"
2019-02-18 07:52:03 +01:00
assetfs "github.com/elazarl/go-bindata-assetfs"
2020-08-17 18:04:03 +02:00
ptypes "github.com/traefik/paerser/types"
2017-10-02 10:32:02 +02:00
)
func TestDo_globalConfiguration ( t * testing . T ) {
2018-11-27 17:42:04 +01:00
config := & static . Configuration { }
2017-10-02 10:32:02 +02:00
2018-11-27 17:42:04 +01:00
config . Global = & static . Global {
CheckNewVersion : true ,
2019-09-16 17:26:06 +02:00
SendAnonymousUsage : true ,
2018-11-27 17:42:04 +01:00
}
2019-03-14 19:32:03 +01:00
2017-10-02 10:32:02 +02:00
config . AccessLog = & types . AccessLog {
FilePath : "AccessLog FilePath" ,
Format : "AccessLog Format" ,
2019-03-14 19:32:03 +01:00
Filters : & types . AccessLogFilters {
2019-06-17 11:48:05 +02:00
StatusCodes : [ ] string { "200" , "500" } ,
2019-03-14 19:32:03 +01:00
RetryAttempts : true ,
MinDuration : 10 ,
} ,
Fields : & types . AccessLogFields {
DefaultMode : "drop" ,
2019-06-17 11:48:05 +02:00
Names : map [ string ] string {
2019-03-14 19:32:03 +01:00
"RequestHost" : "keep" ,
} ,
Headers : & types . FieldHeaders {
DefaultMode : "drop" ,
2019-06-17 11:48:05 +02:00
Names : map [ string ] string {
2019-03-14 19:32:03 +01:00
"Referer" : "keep" ,
} ,
} ,
} ,
BufferingSize : 4 ,
2017-10-02 10:32:02 +02:00
}
2019-03-14 19:32:03 +01:00
2018-11-27 17:42:04 +01:00
config . Log = & types . TraefikLog {
2019-04-16 15:30:09 +02:00
Level : "Level" ,
2018-11-27 17:42:04 +01:00
FilePath : "/foo/path" ,
Format : "json" ,
}
2019-03-14 19:32:03 +01:00
2018-11-27 17:42:04 +01:00
config . EntryPoints = static . EntryPoints {
2017-10-02 10:32:02 +02:00
"foo" : {
Address : "foo Address" ,
2018-11-27 17:42:04 +01:00
Transport : & static . EntryPointsTransport {
RespondingTimeouts : & static . RespondingTimeouts {
2020-08-17 18:04:03 +02:00
ReadTimeout : ptypes . Duration ( 111 * time . Second ) ,
WriteTimeout : ptypes . Duration ( 111 * time . Second ) ,
IdleTimeout : ptypes . Duration ( 111 * time . Second ) ,
2018-11-27 17:42:04 +01:00
} ,
} ,
ProxyProtocol : & static . ProxyProtocol {
2017-10-10 14:50:03 +02:00
TrustedIPs : [ ] string { "127.0.0.1/32" , "192.168.0.1" } ,
} ,
2017-10-02 10:32:02 +02:00
} ,
"fii" : {
Address : "fii Address" ,
2018-11-27 17:42:04 +01:00
Transport : & static . EntryPointsTransport {
RespondingTimeouts : & static . RespondingTimeouts {
2020-08-17 18:04:03 +02:00
ReadTimeout : ptypes . Duration ( 111 * time . Second ) ,
WriteTimeout : ptypes . Duration ( 111 * time . Second ) ,
IdleTimeout : ptypes . Duration ( 111 * time . Second ) ,
2018-11-27 17:42:04 +01:00
} ,
} ,
ProxyProtocol : & static . ProxyProtocol {
2017-10-10 14:50:03 +02:00
TrustedIPs : [ ] string { "127.0.0.1/32" , "192.168.0.1" } ,
} ,
2017-10-02 10:32:02 +02:00
} ,
}
2019-07-19 11:52:04 +02:00
config . CertificatesResolvers = map [ string ] static . CertificateResolver {
"default" : {
ACME : & acme . Configuration {
Email : "acme Email" ,
CAServer : "CAServer" ,
Storage : "Storage" ,
KeyType : "MyKeyType" ,
2020-08-21 11:12:04 +02:00
DNSChallenge : & acme . DNSChallenge { Provider : "DNSProvider" } ,
HTTPChallenge : & acme . HTTPChallenge {
2019-07-19 11:52:04 +02:00
EntryPoint : "MyEntryPoint" ,
} ,
2020-08-21 11:12:04 +02:00
TLSChallenge : & acme . TLSChallenge { } ,
2017-10-02 10:32:02 +02:00
} ,
} ,
}
2018-11-27 17:42:04 +01:00
config . Providers = & static . Providers {
2020-08-17 18:04:03 +02:00
ProvidersThrottleDuration : ptypes . Duration ( 111 * time . Second ) ,
2017-10-02 10:32:02 +02:00
}
2018-11-27 17:42:04 +01:00
config . ServersTransport = & static . ServersTransport {
InsecureSkipVerify : true ,
2019-06-17 11:48:05 +02:00
RootCAs : [ ] traefiktls . FileOrContent { "RootCAs 1" , "RootCAs 2" , "RootCAs 3" } ,
2018-11-27 17:42:04 +01:00
MaxIdleConnsPerHost : 111 ,
ForwardingTimeouts : & static . ForwardingTimeouts {
2020-08-17 18:04:03 +02:00
DialTimeout : ptypes . Duration ( 111 * time . Second ) ,
ResponseHeaderTimeout : ptypes . Duration ( 111 * time . Second ) ,
2018-11-27 17:42:04 +01:00
} ,
2017-10-02 10:32:02 +02:00
}
2018-11-27 17:42:04 +01:00
config . API = & static . API {
2019-07-19 12:28:07 +02:00
Dashboard : true ,
2018-10-01 19:18:03 +02:00
DashboardAssets : & assetfs . AssetFS {
Asset : func ( path string ) ( [ ] byte , error ) {
return nil , nil
} ,
AssetDir : func ( path string ) ( [ ] string , error ) {
return nil , nil
} ,
AssetInfo : func ( path string ) ( os . FileInfo , error ) {
return nil , nil
} ,
Prefix : "fii" ,
} ,
}
2018-11-27 17:42:04 +01:00
config . Providers . File = & file . Provider {
2019-03-27 15:02:06 +01:00
Directory : "file Directory" ,
Watch : true ,
Filename : "file Filename" ,
DebugLogGeneratedTemplate : true ,
}
config . Providers . Docker = & docker . Provider {
2019-06-21 09:24:04 +02:00
Constraints : ` Label("foo", "bar") ` ,
2019-03-27 15:02:06 +01:00
Watch : true ,
2019-03-14 19:32:03 +01:00
Endpoint : "MyEndPoint" ,
DefaultRule : "PathPrefix(`/`)" ,
TLS : & types . ClientTLS {
CA : "myCa" ,
CAOptional : true ,
Cert : "mycert.pem" ,
Key : "mycert.key" ,
InsecureSkipVerify : true ,
} ,
ExposedByDefault : true ,
UseBindPortIP : true ,
SwarmMode : true ,
Network : "MyNetwork" ,
SwarmModeRefreshSeconds : 42 ,
}
2019-07-08 21:36:03 +02:00
config . Providers . KubernetesIngress = & ingress . Provider {
2019-03-14 19:32:03 +01:00
Endpoint : "MyEndpoint" ,
Token : "MyToken" ,
CertAuthFilePath : "MyCertAuthPath" ,
DisablePassHostHeaders : true ,
Namespaces : [ ] string { "a" , "b" } ,
LabelSelector : "myLabelSelector" ,
IngressClass : "MyIngressClass" ,
}
config . Providers . KubernetesCRD = & crd . Provider {
Endpoint : "MyEndpoint" ,
Token : "MyToken" ,
CertAuthFilePath : "MyCertAuthPath" ,
DisablePassHostHeaders : true ,
Namespaces : [ ] string { "a" , "b" } ,
LabelSelector : "myLabelSelector" ,
IngressClass : "MyIngressClass" ,
}
2018-11-27 17:42:04 +01:00
// FIXME Test the other providers once they are migrated
2017-10-02 10:32:02 +02:00
2019-03-14 19:32:03 +01:00
config . Metrics = & types . Metrics {
Prometheus : & types . Prometheus {
2019-07-19 12:28:07 +02:00
Buckets : [ ] float64 { 0.1 , 0.3 , 1.2 , 5 } ,
2019-03-14 19:32:03 +01:00
} ,
2019-09-02 12:18:04 +02:00
Datadog : & types . Datadog {
2019-03-14 19:32:03 +01:00
Address : "localhost:8181" ,
2019-06-17 11:48:05 +02:00
PushInterval : 12 ,
2019-03-14 19:32:03 +01:00
} ,
StatsD : & types . Statsd {
Address : "localhost:8182" ,
2019-06-17 11:48:05 +02:00
PushInterval : 42 ,
2019-03-14 19:32:03 +01:00
} ,
InfluxDB : & types . InfluxDB {
Address : "localhost:8183" ,
Protocol : "http" ,
2019-06-17 11:48:05 +02:00
PushInterval : 22 ,
2019-03-14 19:32:03 +01:00
Database : "myDB" ,
RetentionPolicy : "12" ,
Username : "a" ,
Password : "aaaa" ,
} ,
}
2019-07-19 12:28:07 +02:00
config . Ping = & ping . Handler { }
2019-03-14 19:32:03 +01:00
config . Tracing = & static . Tracing {
ServiceName : "myServiceName" ,
SpanNameLimit : 3 ,
Jaeger : & jaeger . Config {
SamplingServerURL : "aaa" ,
SamplingType : "bbb" ,
SamplingParam : 43 ,
LocalAgentHostPort : "ccc" ,
Gen128Bit : true ,
Propagation : "ddd" ,
TraceContextHeaderName : "eee" ,
} ,
Zipkin : & zipkin . Config {
HTTPEndpoint : "fff" ,
SameSpan : true ,
ID128Bit : true ,
SampleRate : 53 ,
} ,
2019-09-02 12:18:04 +02:00
Datadog : & datadog . Config {
2019-03-14 19:32:03 +01:00
LocalAgentHostPort : "ggg" ,
GlobalTag : "eee" ,
Debug : true ,
PrioritySampling : true ,
} ,
Instana : & instana . Config {
LocalAgentHost : "fff" ,
LocalAgentPort : 32 ,
LogLevel : "ggg" ,
} ,
2019-06-28 00:16:04 +02:00
Haystack : & haystack . Config {
LocalAgentHost : "fff" ,
LocalAgentPort : 32 ,
GlobalTag : "eee" ,
TraceIDHeaderName : "fff" ,
ParentIDHeaderName : "ggg" ,
SpanIDHeaderName : "hhh" ,
BaggagePrefixHeaderName : "iii" ,
} ,
2019-03-14 19:32:03 +01:00
}
config . HostResolver = & types . HostResolverConfig {
CnameFlattening : true ,
ResolvConfig : "aaa" ,
ResolvDepth : 3 ,
}
2017-10-02 10:32:02 +02:00
cleanJSON , err := Do ( config , true )
if err != nil {
t . Fatal ( err , cleanJSON )
}
}