-
Notifications
You must be signed in to change notification settings - Fork 16
/
kv_test.go
68 lines (54 loc) · 1.7 KB
/
kv_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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package traefikkop
import (
"encoding/json"
"fmt"
"testing"
"github.com/BurntSushi/toml"
"github.com/stretchr/testify/require"
"github.com/traefik/traefik/v2/pkg/config/dynamic"
)
func Test_configToKV(t *testing.T) {
cfg := &dynamic.Configuration{}
_, err := toml.DecodeFile("./fixtures/sample.toml", &cfg)
require.NoError(t, err)
got, err := ConfigToKV(*cfg)
require.NoError(t, err)
require.NotNil(t, got)
require.Contains(t, got, "traefik/http/services/Service0/loadBalancer/healthCheck/port")
require.Contains(t, got, "traefik/http/middlewares/Middleware15/forwardAuth/authRequestHeaders/1")
require.NotContains(t, got, "traefik/tls/options/TLS0/sniStrict")
// should not include @docker in names
cfg = &dynamic.Configuration{}
err = json.Unmarshal([]byte(NGINX_CONF_JSON), cfg)
require.NoError(t, err)
got, err = ConfigToKV(*cfg)
require.NoError(t, err)
// dumpKV(got)
require.NotContains(t, got, "traefik/http/routers/nginx@docker/service")
require.NotContains(t, got, "traefik/http/services/nginx@docker/loadBalancer/passHostHeader")
// t.Fail()
}
func dumpKV(kv map[string]interface{}) {
for k, v := range kv {
fmt.Printf("%s = %s\n", k, v)
}
}
func Test_stringify(t *testing.T) {
v := 15552000
s := stringify(v)
require.Equal(t, "15552000", s, "int should match")
b := false
s = stringify(b)
require.Equal(t, "false", s, "bool should match")
b = true
s = stringify(b)
require.Equal(t, "true", s, "bool should match")
}
func Test_stringifyFloat(t *testing.T) {
f := float64(15552000)
s := stringifyFloat(f)
require.Equal(t, "15552000", s, "float should match")
f32 := float32(15552000)
s = stringifyFloat(float64(f32))
require.Equal(t, "15552000", s, "float should match")
}