@@ -11,67 +11,53 @@ import (
11
11
)
12
12
13
13
var (
14
- expectedOutputMasked = `creating workspace test
15
- creating service svc1 {
16
- + "connect_timeout": 60000
17
- + "host": "[masked]"
18
- + "id": "9ecf5708-f2f4-444e-a4c7-fcd3a57f9a6d"
19
- + "name": "svc1"
20
- + "protocol": "http"
21
- + "read_timeout": 60000
14
+ expectedOutputMasked = `updating service svc1 {
15
+ "connect_timeout": 60000,
16
+ "enabled": true,
17
+ "host": "[masked]",
18
+ "id": "9ecf5708-f2f4-444e-a4c7-fcd3a57f9a6d",
19
+ "name": "svc1",
20
+ "port": 80,
21
+ "protocol": "http",
22
+ "read_timeout": 60000,
23
+ "retries": 5,
24
+ "write_timeout": 60000
22
25
+ "tags": [
23
26
+ "[masked] is an external host. I like [masked]!",
24
27
+ "foo:foo",
25
28
+ "baz:[masked]",
26
29
+ "another:[masked]",
27
30
+ "bar:[masked]"
28
31
+ ]
29
- + "write_timeout": 60000
30
- }
31
-
32
- creating plugin rate-limiting (global) {
33
- + "config": {
34
- + "minute": 123
35
- + }
36
- + "id": "a1368a28-cb5c-4eee-86d8-03a6bdf94b5e"
37
- + "name": "rate-limiting"
38
32
}
39
33
34
+ creating plugin rate-limiting (global)
40
35
Summary:
41
- Created: 2
42
- Updated: 0
36
+ Created: 1
37
+ Updated: 1
43
38
Deleted: 0
44
39
`
45
40
46
- expectedOutputUnMasked = `creating workspace test
47
- creating service svc1 {
48
- + "connect_timeout": 60000
49
- + "host": "mockbin.org"
50
- + "id": "9ecf5708-f2f4-444e-a4c7-fcd3a57f9a6d"
51
- + "name": "svc1"
52
- + "protocol": "http"
53
- + "read_timeout": 60000
41
+ expectedOutputUnMasked = `updating service svc1 {
42
+ "connect_timeout": 60000,
43
+ "enabled": true,
44
+ "host": "mockbin.org",
45
+ "id": "9ecf5708-f2f4-444e-a4c7-fcd3a57f9a6d",
46
+ "name": "svc1",
47
+ "port": 80,
48
+ "protocol": "http",
49
+ "read_timeout": 60000,
50
+ "retries": 5,
51
+ "write_timeout": 60000
54
52
+ "tags": [
55
- + "mockbin.org is an external host. I like mockbin.org!",
56
- + "foo:foo",
57
- + "baz:bazbaz",
58
- + "another:bazbaz",
59
- + "bar:barbar"
53
+ + "test"
60
54
+ ]
61
- + "write_timeout": 60000
62
- }
63
-
64
- creating plugin rate-limiting (global) {
65
- + "config": {
66
- + "minute": 123
67
- + }
68
- + "id": "a1368a28-cb5c-4eee-86d8-03a6bdf94b5e"
69
- + "name": "rate-limiting"
70
55
}
71
56
57
+ creating plugin rate-limiting (global)
72
58
Summary:
73
- Created: 2
74
- Updated: 0
59
+ Created: 1
60
+ Updated: 1
75
61
Deleted: 0
76
62
`
77
63
@@ -87,48 +73,69 @@ Summary:
87
73
// test scope:
88
74
// - 1.x
89
75
// - 2.x
90
- func Test_Diff_Workspace_UnMasked_OlderThan3x (t * testing.T ) {
76
+ func Test_Diff_Workspace_OlderThan3x (t * testing.T ) {
91
77
tests := []struct {
92
78
name string
93
79
stateFile string
94
80
expectedState utils.KongRawState
95
- envVars map [string ]string
96
81
}{
97
82
{
98
83
name : "diff with not existent workspace doesn't error out" ,
99
84
stateFile : "testdata/diff/001-not-existing-workspace/kong.yaml" ,
100
- envVars : diffEnvVars ,
101
85
},
102
86
}
103
87
for _ , tc := range tests {
104
88
t .Run (tc .name , func (t * testing.T ) {
105
- for k , v := range tc .envVars {
106
- os .Setenv (k , v )
107
- defer func (k string ) {
108
- os .Unsetenv (k )
109
- }(k )
110
- }
111
89
runWhen (t , "kong" , "<3.0.0" )
112
90
teardown := setup (t )
113
91
defer teardown (t )
114
92
115
- out , err := diff (tc .stateFile , "--no-mask-deck-env-vars-value" )
93
+ _ , err := diff (tc .stateFile )
116
94
assert .NoError (t , err )
117
- assert .Equal (t , out , expectedOutputUnMasked )
118
95
})
119
96
}
120
97
}
121
- func Test_Diff_Workspace_Masked_OlderThan3x (t * testing.T ) {
98
+
99
+ // test scope:
100
+ // - 3.x
101
+ func Test_Diff_Workspace_NewerThan3x (t * testing.T ) {
122
102
tests := []struct {
123
103
name string
124
104
stateFile string
125
105
expectedState utils.KongRawState
126
- envVars map [string ]string
127
106
}{
128
107
{
129
108
name : "diff with not existent workspace doesn't error out" ,
130
- stateFile : "testdata/diff/001-not-existing-workspace/kong.yaml" ,
131
- envVars : diffEnvVars ,
109
+ stateFile : "testdata/diff/001-not-existing-workspace/kong3x.yaml" ,
110
+ },
111
+ }
112
+ for _ , tc := range tests {
113
+ t .Run (tc .name , func (t * testing.T ) {
114
+ runWhen (t , "kong" , ">=3.0.0" )
115
+ teardown := setup (t )
116
+ defer teardown (t )
117
+
118
+ _ , err := diff (tc .stateFile )
119
+ assert .NoError (t , err )
120
+ })
121
+ }
122
+ }
123
+
124
+ // test scope:
125
+ // - 2.8.0
126
+ func Test_Diff_Masked_OlderThan3x (t * testing.T ) {
127
+ tests := []struct {
128
+ name string
129
+ initialStateFile string
130
+ stateFile string
131
+ expectedState utils.KongRawState
132
+ envVars map [string ]string
133
+ }{
134
+ {
135
+ name : "env variable are masked" ,
136
+ initialStateFile : "testdata/diff/002-mask/initial.yaml" ,
137
+ stateFile : "testdata/diff/002-mask/kong.yaml" ,
138
+ envVars : diffEnvVars ,
132
139
},
133
140
}
134
141
for _ , tc := range tests {
@@ -139,30 +146,35 @@ func Test_Diff_Workspace_Masked_OlderThan3x(t *testing.T) {
139
146
os .Unsetenv (k )
140
147
}(k )
141
148
}
142
- runWhen (t , "kong" , "<3.0 .0" )
149
+ runWhen (t , "kong" , "==2.8 .0" )
143
150
teardown := setup (t )
144
151
defer teardown (t )
145
152
153
+ // initialize state
154
+ assert .NoError (t , sync (tc .initialStateFile ))
155
+
146
156
out , err := diff (tc .stateFile )
147
157
assert .NoError (t , err )
148
- assert .Equal (t , out , expectedOutputMasked )
158
+ assert .Equal (t , expectedOutputMasked , out )
149
159
})
150
160
}
151
161
}
152
162
153
163
// test scope:
154
164
// - 3.x
155
- func Test_Diff_Workspace_UnMasked_NewerThan3x (t * testing.T ) {
165
+ func Test_Diff_Masked_NewerThan3x (t * testing.T ) {
156
166
tests := []struct {
157
- name string
158
- stateFile string
159
- expectedState utils.KongRawState
160
- envVars map [string ]string
167
+ name string
168
+ initialStateFile string
169
+ stateFile string
170
+ expectedState utils.KongRawState
171
+ envVars map [string ]string
161
172
}{
162
173
{
163
- name : "diff with not existent workspace doesn't error out" ,
164
- stateFile : "testdata/diff/001-not-existing-workspace/kong3x.yaml" ,
165
- envVars : diffEnvVars ,
174
+ name : "env variable are masked" ,
175
+ initialStateFile : "testdata/diff/002-mask/initial3x.yaml" ,
176
+ stateFile : "testdata/diff/002-mask/kong3x.yaml" ,
177
+ envVars : diffEnvVars ,
166
178
},
167
179
}
168
180
for _ , tc := range tests {
@@ -177,23 +189,70 @@ func Test_Diff_Workspace_UnMasked_NewerThan3x(t *testing.T) {
177
189
teardown := setup (t )
178
190
defer teardown (t )
179
191
192
+ // initialize state
193
+ assert .NoError (t , sync (tc .initialStateFile ))
194
+
195
+ out , err := diff (tc .stateFile )
196
+ assert .NoError (t , err )
197
+ assert .Equal (t , expectedOutputMasked , out )
198
+ })
199
+ }
200
+ }
201
+
202
+ // test scope:
203
+ // - 2.8.0
204
+ func Test_Diff_Unasked_OlderThan3x (t * testing.T ) {
205
+ tests := []struct {
206
+ name string
207
+ initialStateFile string
208
+ stateFile string
209
+ expectedState utils.KongRawState
210
+ envVars map [string ]string
211
+ }{
212
+ {
213
+ name : "env variable are unmasked" ,
214
+ initialStateFile : "testdata/diff/003-unmask/initial.yaml" ,
215
+ stateFile : "testdata/diff/003-unmask/kong.yaml" ,
216
+ envVars : diffEnvVars ,
217
+ },
218
+ }
219
+ for _ , tc := range tests {
220
+ t .Run (tc .name , func (t * testing.T ) {
221
+ for k , v := range tc .envVars {
222
+ os .Setenv (k , v )
223
+ defer func (k string ) {
224
+ os .Unsetenv (k )
225
+ }(k )
226
+ }
227
+ runWhen (t , "kong" , "==2.8.0" )
228
+ teardown := setup (t )
229
+ defer teardown (t )
230
+
231
+ // initialize state
232
+ assert .NoError (t , sync (tc .initialStateFile ))
233
+
180
234
out , err := diff (tc .stateFile , "--no-mask-deck-env-vars-value" )
181
235
assert .NoError (t , err )
182
- assert .Equal (t , out , expectedOutputUnMasked )
236
+ assert .Equal (t , expectedOutputUnMasked , out )
183
237
})
184
238
}
185
239
}
186
- func Test_Diff_Workspace_Masked_NewerThan3x (t * testing.T ) {
240
+
241
+ // test scope:
242
+ // - 3.x
243
+ func Test_Diff_Unasked_NewerThan3x (t * testing.T ) {
187
244
tests := []struct {
188
- name string
189
- stateFile string
190
- expectedState utils.KongRawState
191
- envVars map [string ]string
245
+ name string
246
+ initialStateFile string
247
+ stateFile string
248
+ expectedState utils.KongRawState
249
+ envVars map [string ]string
192
250
}{
193
251
{
194
- name : "diff with not existent workspace doesn't error out" ,
195
- stateFile : "testdata/diff/001-not-existing-workspace/kong3x.yaml" ,
196
- envVars : diffEnvVars ,
252
+ name : "env variable are unmasked" ,
253
+ initialStateFile : "testdata/diff/003-unmask/initial3x.yaml" ,
254
+ stateFile : "testdata/diff/003-unmask/kong3x.yaml" ,
255
+ envVars : diffEnvVars ,
197
256
},
198
257
}
199
258
for _ , tc := range tests {
@@ -208,9 +267,12 @@ func Test_Diff_Workspace_Masked_NewerThan3x(t *testing.T) {
208
267
teardown := setup (t )
209
268
defer teardown (t )
210
269
211
- out , err := diff (tc .stateFile )
270
+ // initialize state
271
+ assert .NoError (t , sync (tc .initialStateFile ))
272
+
273
+ out , err := diff (tc .stateFile , "--no-mask-deck-env-vars-value" )
212
274
assert .NoError (t , err )
213
- assert .Equal (t , out , expectedOutputMasked )
275
+ assert .Equal (t , expectedOutputUnMasked , out )
214
276
})
215
277
}
216
278
}
0 commit comments