@@ -168,35 +168,94 @@ func TestGetAllFlags(t *testing.T) {
168
168
}
169
169
170
170
// when - get all with open scope
171
- flags , err := mux .GetAllFlags ("" )
171
+ flagConfig , err := mux .GetAllFlags ("" )
172
172
if err != nil {
173
173
t .Fatal ("error when retrieving all flags" )
174
174
return
175
175
}
176
176
177
- if len (flags ) == 0 {
177
+ if len (flagConfig ) == 0 {
178
178
t .Fatal ("expected no empty flags" )
179
179
return
180
180
}
181
181
182
182
// when - get all with a scope
183
- flags , err = mux .GetAllFlags ("A" )
183
+ flagConfig , err = mux .GetAllFlags ("A" )
184
184
if err != nil {
185
185
t .Fatal ("error when retrieving all flags" )
186
186
return
187
187
}
188
188
189
- if len (flags ) == 0 || ! strings .Contains (flags , fmt .Sprintf ("\" source\" :\" %s\" " , "A" )) {
189
+ if len (flagConfig ) == 0 || ! strings .Contains (flagConfig , fmt .Sprintf ("\" source\" :\" %s\" " , "A" )) {
190
190
t .Fatal ("expected flags to be scoped" )
191
191
return
192
192
}
193
193
194
194
// when - get all for a flagless-scope
195
- flags , err = mux .GetAllFlags ("C" )
195
+ flagConfig , err = mux .GetAllFlags ("C" )
196
196
if err != nil {
197
197
t .Fatal ("error when retrieving all flags" )
198
198
return
199
199
}
200
200
201
- assert .Equal (t , flags , emptyConfigString )
201
+ assert .Equal (t , flagConfig , emptyConfigString )
202
+ }
203
+
204
+ func TestGetAllFlagsMetadata (t * testing.T ) {
205
+ // given
206
+ mux , err := NewMux (getSimpleFlagStore ())
207
+ if err != nil {
208
+ t .Fatal ("error during flag extraction" )
209
+ return
210
+ }
211
+
212
+ // when - get all with open scope
213
+ flagConfig , err := mux .GetAllFlags ("" )
214
+ if err != nil {
215
+ t .Fatal ("error when retrieving all flags" )
216
+ return
217
+ }
218
+
219
+ if len (flagConfig ) == 0 {
220
+ t .Fatal ("expected no empty flags" )
221
+ return
222
+ }
223
+
224
+ if ! strings .Contains (flagConfig , "\" keyA\" :\" valueA\" " ) {
225
+ t .Fatal ("expected unique metadata key for A to be present" )
226
+ return
227
+ }
228
+
229
+ if ! strings .Contains (flagConfig , "\" keyB\" :\" valueB\" " ) {
230
+ t .Fatal ("expected unique metadata key for B to be present" )
231
+ return
232
+ }
233
+
234
+ // duplicated keys are removed
235
+ if strings .Contains (flagConfig , "\" keyDuped\" :\" value\" " ) {
236
+ t .Fatal ("expected duplicated metadata key NOT to be present" )
237
+ return
238
+ }
239
+
240
+ // when - get all with a scope
241
+ flagConfig , err = mux .GetAllFlags ("A" )
242
+ if err != nil {
243
+ t .Fatal ("error when retrieving all flags" )
244
+ return
245
+ }
246
+
247
+ if len (flagConfig ) == 0 {
248
+ t .Fatal ("expected no empty flags" )
249
+ return
250
+ }
251
+
252
+ if ! strings .Contains (flagConfig , "\" keyA\" :\" valueA\" " ) {
253
+ t .Fatal ("expected unique metadata key to be present" )
254
+ return
255
+ }
256
+
257
+ if ! strings .Contains (flagConfig , "\" keyDuped\" :\" value\" " ) {
258
+ t .Fatal ("expected duplicated metadata key to be present" )
259
+ return
260
+ }
202
261
}
0 commit comments