-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathstore_test.go
37 lines (28 loc) · 1.56 KB
/
store_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package traefikkop
import (
"encoding/json"
"testing"
"github.com/BurntSushi/toml"
"github.com/stretchr/testify/require"
"github.com/traefik/traefik/v2/pkg/config/dynamic"
)
const NGINX_CONF_JSON = `{"http":{"routers":{"nginx@docker":{"service":"nginx","rule":"Host('nginx.local')"}},"services":{"nginx@docker":{"loadBalancer":{"servers":[{"url":"http://172.20.0.2:80"}],"passHostHeader":true}}}},"tcp":{},"udp":{},"tls":{"options":{"default":{"clientAuth":{},"alpnProtocols":["h2","http/1.1","acme-tls/1"]}}}}`
const NGINX_CONF_JSON_DIFFRENT_SERVICE_NAME = `{"http":{"routers":{"nginx@docker":{"service":"nginx-nginx","rule":"Host('nginx.local')"}},"services":{"nginx-nginx@docker":{"loadBalancer":{"servers":[{"url":"http://172.20.0.2:80"}],"passHostHeader":true}}}},"tcp":{},"udp":{},"tls":{"options":{"default":{"clientAuth":{},"alpnProtocols":["h2","http/1.1","acme-tls/1"]}}}}`
func Test_collectKeys(t *testing.T) {
cfg := &dynamic.Configuration{}
_, err := toml.DecodeFile("./fixtures/sample.toml", &cfg)
require.NoError(t, err)
keys := collectKeys(cfg.HTTP.Middlewares)
require.NotEmpty(t, keys)
require.Contains(t, keys, "Middleware21")
require.Contains(t, collectKeys(cfg.HTTP.Services), "Service0")
cfg = &dynamic.Configuration{}
err = json.Unmarshal([]byte(NGINX_CONF_JSON), cfg)
require.NoError(t, err)
keys = collectKeys(cfg.HTTP.Routers)
require.Len(t, keys, 1)
}
// keys := collectKeys(cfg.HTTP.Middlewares)
// require.NotEmpty(t, keys)
// require.True(t, keys.Contains("Middleware21"))
// require.True(t, collectKeys(cfg.HTTP.Services).Contains("Service0"))