This repository has been archived by the owner on Aug 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 388
/
config_test.go
98 lines (94 loc) · 2.23 KB
/
config_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package framework
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestConfig_HelmValuesFromConfig(t *testing.T) {
tests := []struct {
name string
testConfig TestConfig
want map[string]string
}{
{
"returns empty map by default",
TestConfig{},
map[string]string{},
},
{
"sets consul image",
TestConfig{
ConsulImage: "consul:test-version",
},
map[string]string{"global.image": "consul:test-version"},
},
{
"sets consul-k8s image",
TestConfig{
ConsulK8SImage: "consul-k8s:test-version",
},
map[string]string{"global.imageK8S": "consul-k8s:test-version"},
},
{
"sets both images",
TestConfig{
ConsulImage: "consul:test-version",
ConsulK8SImage: "consul-k8s:test-version",
},
map[string]string{
"global.image": "consul:test-version",
"global.imageK8S": "consul-k8s:test-version",
},
},
{
"sets ent license secret",
TestConfig{
EnterpriseLicenseSecretName: "ent-license",
EnterpriseLicenseSecretKey: "key",
},
map[string]string{
"server.enterpriseLicense.secretName": "ent-license",
"server.enterpriseLicense.secretKey": "key",
},
},
{
"doesn't set ent license secret when only secret name is set",
TestConfig{
EnterpriseLicenseSecretName: "ent-license",
},
map[string]string{},
},
{
"doesn't set ent license secret when only secret key is set",
TestConfig{
EnterpriseLicenseSecretKey: "key",
},
map[string]string{},
},
{
"sets openshift value when EnableOpenshift is set",
TestConfig{
EnableOpenshift: true,
},
map[string]string{
"global.openshift.enabled": "true",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
values, err := tt.testConfig.HelmValuesFromConfig()
require.NoError(t, err)
require.Equal(t, values, tt.want)
})
}
}
func TestConfig_HelmValuesFromConfig_EntImage(t *testing.T) {
cfg := TestConfig{
EnableEnterprise: true,
// We need to set a different path because these tests are run from a different directory.
helmChartPath: "../../..",
}
values, err := cfg.HelmValuesFromConfig()
require.NoError(t, err)
require.Contains(t, values["global.image"], "hashicorp/consul-enterprise")
}