Use index-based syntax in KV tests.
This commit is contained in:
parent
e2bac47a0a
commit
3c8c5ebb96
2 changed files with 31 additions and 19 deletions
|
@ -2,6 +2,7 @@ package kv
|
|||
|
||||
import (
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -81,7 +82,18 @@ func withPair(key string, value string) func(map[string]string) {
|
|||
}
|
||||
}
|
||||
|
||||
func withErrorPage(name string, backend, query, status string) func(map[string]string) {
|
||||
func withList(key string, values ...string) func(map[string]string) {
|
||||
return func(pairs map[string]string) {
|
||||
if len(key) == 0 {
|
||||
return
|
||||
}
|
||||
for i, value := range values {
|
||||
pairs[key+"/"+strconv.Itoa(i)] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func withErrorPage(name string, backend string, query string, statuses ...string) func(map[string]string) {
|
||||
return func(pairs map[string]string) {
|
||||
if len(name) == 0 {
|
||||
return
|
||||
|
@ -89,7 +101,7 @@ func withErrorPage(name string, backend, query, status string) func(map[string]s
|
|||
|
||||
withPair(pathFrontendErrorPages+name+pathFrontendErrorPagesBackend, backend)(pairs)
|
||||
withPair(pathFrontendErrorPages+name+pathFrontendErrorPagesQuery, query)(pairs)
|
||||
withPair(pathFrontendErrorPages+name+pathFrontendErrorPagesStatus, status)(pairs)
|
||||
withList(pathFrontendErrorPages+name+pathFrontendErrorPagesStatus, statuses...)(pairs)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,11 +137,14 @@ func TestFiller(t *testing.T) {
|
|||
{Key: "traefik/frontends/frontend.with.dot/errors/bar", Value: []byte("")},
|
||||
{Key: "traefik/frontends/frontend.with.dot/errors/bar/backend", Value: []byte("error")},
|
||||
{Key: "traefik/frontends/frontend.with.dot/errors/bar/query", Value: []byte("/test2")},
|
||||
{Key: "traefik/frontends/frontend.with.dot/errors/bar/status", Value: []byte("400-405")},
|
||||
{Key: "traefik/frontends/frontend.with.dot/errors/bar/status", Value: []byte("")},
|
||||
{Key: "traefik/frontends/frontend.with.dot/errors/bar/status/0", Value: []byte("400-405")},
|
||||
{Key: "traefik/frontends/frontend.with.dot/errors/foo", Value: []byte("")},
|
||||
{Key: "traefik/frontends/frontend.with.dot/errors/foo/backend", Value: []byte("error")},
|
||||
{Key: "traefik/frontends/frontend.with.dot/errors/foo/query", Value: []byte("/test1")},
|
||||
{Key: "traefik/frontends/frontend.with.dot/errors/foo/status", Value: []byte("500-501, 503-599")},
|
||||
{Key: "traefik/frontends/frontend.with.dot/errors/foo/status", Value: []byte("")},
|
||||
{Key: "traefik/frontends/frontend.with.dot/errors/foo/status/0", Value: []byte("500-501")},
|
||||
{Key: "traefik/frontends/frontend.with.dot/errors/foo/status/1", Value: []byte("503-599")},
|
||||
{Key: "traefik/frontends/frontend.with.dot/ratelimit", Value: []byte("")},
|
||||
{Key: "traefik/frontends/frontend.with.dot/ratelimit/extractorfunc", Value: []byte("client.ip")},
|
||||
{Key: "traefik/frontends/frontend.with.dot/ratelimit/rateset", Value: []byte("")},
|
||||
|
@ -150,7 +165,7 @@ func TestFiller(t *testing.T) {
|
|||
frontend("frontend.with.dot",
|
||||
withPair("backend", "backend.with.dot.too"),
|
||||
withPair("routes/route.with.dot/rule", "Host:test.localhost"),
|
||||
withErrorPage("foo", "error", "/test1", "500-501, 503-599"),
|
||||
withErrorPage("foo", "error", "/test1", "500-501", "503-599"),
|
||||
withErrorPage("bar", "error", "/test2", "400-405"),
|
||||
withRateLimit("client.ip",
|
||||
withLimit("foo", "6", "12", "18"),
|
||||
|
@ -168,10 +183,10 @@ func TestFiller(t *testing.T) {
|
|||
withPair("routes/route.with.dot/rule", "Host:test.localhost"),
|
||||
withPair("errors/foo/backend", "error"),
|
||||
withPair("errors/foo/query", "/test1"),
|
||||
withPair("errors/foo/status", "500-501, 503-599"),
|
||||
withList("errors/foo/status", "500-501", "503-599"),
|
||||
withPair("errors/bar/backend", "error"),
|
||||
withPair("errors/bar/query", "/test2"),
|
||||
withPair("errors/bar/status", "400-405"),
|
||||
withList("errors/bar/status", "400-405"),
|
||||
withPair("ratelimit/extractorfunc", "client.ip"),
|
||||
withPair("ratelimit/rateset/foo/average", "6"),
|
||||
withPair("ratelimit/rateset/foo/burst", "12"),
|
||||
|
|
|
@ -93,15 +93,15 @@ func TestProviderBuildConfiguration(t *testing.T) {
|
|||
withPair(pathFrontendPriority, "6"),
|
||||
withPair(pathFrontendPassHostHeader, "false"),
|
||||
withPair(pathFrontendPassTLSCert, "true"),
|
||||
withPair(pathFrontendEntryPoints, "http,https"),
|
||||
withPair(pathFrontendWhiteListSourceRange, "1.1.1.1/24, 1234:abcd::42/32"),
|
||||
withList(pathFrontendEntryPoints, "http", "https"),
|
||||
withList(pathFrontendWhiteListSourceRange, "1.1.1.1/24", "1234:abcd::42/32"),
|
||||
withPair(pathFrontendWhiteListUseXForwardedFor, "true"),
|
||||
withPair(pathFrontendBasicAuth, "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/, test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"),
|
||||
withList(pathFrontendBasicAuth, "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"),
|
||||
withPair(pathFrontendRedirectEntryPoint, "https"),
|
||||
withPair(pathFrontendRedirectRegex, "nope"),
|
||||
withPair(pathFrontendRedirectReplacement, "nope"),
|
||||
withPair(pathFrontendRedirectPermanent, "true"),
|
||||
withErrorPage("foo", "error", "/test1", "500-501, 503-599"),
|
||||
withErrorPage("foo", "error", "/test1", "500-501", "503-599"),
|
||||
withErrorPage("bar", "error", "/test2", "400-405"),
|
||||
withRateLimit("client.ip",
|
||||
withLimit("foo", "6", "12", "18"),
|
||||
|
@ -117,7 +117,7 @@ func TestProviderBuildConfiguration(t *testing.T) {
|
|||
withPair(pathFrontendSSLProxyHeaders+"Content-Type", "application/json; charset=utf-8"),
|
||||
withPair(pathFrontendSSLProxyHeaders+"X-Custom-Header", "test"),
|
||||
withPair(pathFrontendAllowedHosts, "example.com, ssl.example.com"),
|
||||
withPair(pathFrontendHostsProxyHeaders, "foo, bar, goo, hor"),
|
||||
withList(pathFrontendHostsProxyHeaders, "foo", "bar", "goo", "hor"),
|
||||
withPair(pathFrontendSTSSeconds, "666"),
|
||||
withPair(pathFrontendSSLHost, "foo"),
|
||||
withPair(pathFrontendCustomFrameOptionsValue, "foo"),
|
||||
|
@ -139,11 +139,11 @@ func TestProviderBuildConfiguration(t *testing.T) {
|
|||
withPair("routes/route1/rule", "Host:test.localhost"),
|
||||
withPair("routes/route2/rule", "Path:/foo")),
|
||||
entry("tls/foo",
|
||||
withPair("entrypoints", "http,https"),
|
||||
withList("entrypoints", "http", "https"),
|
||||
withPair("certificate/certfile", "certfile1"),
|
||||
withPair("certificate/keyfile", "keyfile1")),
|
||||
entry("tls/bar",
|
||||
withPair("entrypoints", "http,https"),
|
||||
withList("entrypoints", "http", "https"),
|
||||
withPair("certificate/certfile", "certfile2"),
|
||||
withPair("certificate/keyfile", "keyfile2")),
|
||||
),
|
||||
|
@ -682,10 +682,7 @@ func TestProviderGetSlice(t *testing.T) {
|
|||
desc: "multiple entries",
|
||||
kvPairs: filler("traefik",
|
||||
frontend("foo",
|
||||
withPair("entrypoints/0", "courgette"),
|
||||
withPair("entrypoints/1", "carotte"),
|
||||
withPair("entrypoints/2", "tomate"),
|
||||
withPair("entrypoints/3", "aubergine"),
|
||||
withList("entrypoints", "courgette", "carotte", "tomate", "aubergine"),
|
||||
),
|
||||
),
|
||||
keyParts: []string{"traefik/frontends/foo/entrypoints"},
|
||||
|
@ -1210,7 +1207,7 @@ func TestProviderGetErrorPages(t *testing.T) {
|
|||
rootPath: "traefik/frontends/foo",
|
||||
kvPairs: filler("traefik",
|
||||
frontend("foo",
|
||||
withErrorPage("foo", "error", "/test1", "500-501, 503-599"),
|
||||
withErrorPage("foo", "error", "/test1", "500-501", "503-599"),
|
||||
withErrorPage("bar", "error", "/test2", "400-405"))),
|
||||
expected: map[string]*types.ErrorPage{
|
||||
"foo": {
|
||||
|
|
Loading…
Reference in a new issue