-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconfig_test.go
93 lines (78 loc) · 1.75 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
package pentagon
import (
"testing"
"github.com/vimeo/pentagon/vault"
)
func TestSetDefaults(t *testing.T) {
c := &Config{
Vault: VaultConfig{
AuthType: vault.AuthTypeToken,
},
Mappings: []Mapping{
{
VaultPath: "vaultPath",
SecretName: "theSecret",
},
},
}
c.SetDefaults()
if c.Label != DefaultLabelValue {
t.Fatalf("label should be %s, is %s", DefaultLabelValue, c.Label)
}
if c.Namespace != DefaultNamespace {
t.Fatalf("namespace should be %s, is %s", DefaultNamespace, c.Namespace)
}
if c.Vault.DefaultEngineType != vault.EngineTypeKeyValueV1 {
t.Fatalf("unexpected default engine type: %s", c.Vault.DefaultEngineType)
}
for _, m := range c.Mappings {
if m.VaultEngineType == "" {
t.Fatalf("empty vault engine type for mapping: %+v", m)
}
if m.SecretType == "" {
t.Fatalf("empty Kubernetes secret type for mapping: %+v", m)
}
}
}
func TestNoClobber(t *testing.T) {
c := &Config{
Label: "foo",
Namespace: "bar",
Mappings: []Mapping{
{
SecretType: "kubernetes.io/tls",
},
},
}
c.SetDefaults()
if c.Label != "foo" {
t.Fatalf("label should still be foo, is %s", c.Label)
}
if c.Namespace != "bar" {
t.Fatalf("namespace should still be bar, is %s", c.Namespace)
}
for _, m := range c.Mappings {
if m.SecretType != "kubernetes.io/tls" {
t.Fatalf("Kubernetes secret type should still be 'kubernetes.io/tls', is %s", m.SecretType)
}
}
}
func TestValidate(t *testing.T) {
c := &Config{}
err := c.Validate()
if err == nil {
t.Fatal("configuration should have been invalid")
}
c = &Config{
Mappings: []Mapping{
{
VaultPath: "foo",
SecretName: "bar",
},
},
}
err = c.Validate()
if err != nil {
t.Fatalf("configuration should have been valid: %s", err)
}
}