forked from helmfile/vals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vals_gcpsecrets_test.go
184 lines (179 loc) · 4.26 KB
/
vals_gcpsecrets_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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package vals
import (
"os"
"reflect"
"testing"
"github.com/helmfile/vals/pkg/config"
)
// setup:
// echo -n "foo: bar" | gcloud secrets create valstestvar --data-file=- --replication-policy=automatic
// GCP_PROJECT=secret-test-99234 go test -run '^(TestValues_GCPSecretsManager)$'
func TestValues_GCPSecretsManager(t *testing.T) {
if os.Getenv("SKIP_TESTS") != "" {
t.Skip("Skipping tests")
}
projectId := os.Getenv("GCP_PROJECT")
if projectId == "" {
t.Fatalf("gcpsecrets tests require GCP_PROJECT env var set correctly")
}
tests := []struct {
name string
secrets map[string]string
config map[string]interface{}
want map[string]interface{}
}{
{
"latest string",
map[string]string{"valstestvar": "foo: bar"},
map[string]interface{}{
"provider": map[string]interface{}{
"name": "gcpsecrets",
"version": "latest",
"type": "string",
"path": projectId,
},
"inline": map[string]interface{}{
"valstestvar": "valstestvar",
},
},
map[string]interface{}{"valstestvar": "foo: bar"},
},
{
"fallback string",
map[string]string{},
map[string]interface{}{
"provider": map[string]interface{}{
"name": "gcpsecrets",
"version": "latest",
"type": "string",
"path": projectId,
"fallback_value": "default-value",
},
"inline": map[string]interface{}{
"missingvar": "missingvar",
},
},
map[string]interface{}{"missingvar": "default-value"},
},
{
"empty fallback string",
map[string]string{},
map[string]interface{}{
"provider": map[string]interface{}{
"name": "gcpsecrets",
"version": "latest",
"type": "string",
"path": projectId,
"fallback_value": "",
},
"inline": map[string]interface{}{
"missingvar": "missingvar",
},
},
map[string]interface{}{"missingvar": ""},
},
{
"v1 string",
map[string]string{"valstestvar": "foo: bar"},
map[string]interface{}{
"provider": map[string]interface{}{
"name": "gcpsecrets",
"version": "1",
"type": "string",
"path": projectId,
},
"inline": map[string]interface{}{
"valstestvar": "valstestvar",
},
},
map[string]interface{}{"valstestvar": "foo: bar"},
},
{
"optional string",
map[string]string{},
map[string]interface{}{
"provider": map[string]interface{}{
"name": "gcpsecrets",
"version": "1",
"type": "string",
"path": projectId,
"optional": true,
},
"inline": map[string]interface{}{
"missingvar": "",
},
},
map[string]interface{}{"missingvar": ""},
},
{
"v1 map",
map[string]string{"valstestvar": "foo: bar"},
map[string]interface{}{
"provider": map[string]interface{}{
"name": "gcpsecrets",
"version": "1",
"type": "map",
"path": projectId,
},
"inline": map[string]interface{}{
"valstestvar": "valstestvar",
},
},
map[string]interface{}{
"valstestvar": map[string]interface{}{
"foo": "bar",
},
},
},
{
"latest map",
map[string]string{"valstestvar": "foo: bar"},
map[string]interface{}{
"provider": map[string]interface{}{
"name": "gcpsecrets",
"version": "latest",
"type": "map",
"path": projectId,
},
"inline": map[string]interface{}{
"valstestvar": "valstestvar",
},
},
map[string]interface{}{
"valstestvar": map[string]interface{}{
"foo": "bar",
},
},
},
{
"trim_nl string",
map[string]string{"valstestvar": "foo: bar\n"},
map[string]interface{}{
"provider": map[string]interface{}{
"name": "gcpsecrets",
"version": "latest",
"type": "string",
"path": projectId,
"trim_nl": true,
},
"inline": map[string]interface{}{
"valstestvar": "valstestvar",
},
},
map[string]interface{}{"valstestvar": "foo: bar"},
},
}
for i := range tests {
tt := tests[i]
t.Run(tt.name, func(t *testing.T) {
mapConfig := config.Map(tt.config)
vals, err := Load(mapConfig)
if err != nil {
t.Fatalf("%v", err)
}
if !reflect.DeepEqual(vals, tt.want) {
t.Errorf("unexpected value for vals: want='%s', got='%s'", tt.want, vals)
}
})
}
}