Skip to content

Commit 563237f

Browse files
WillSmisifuweid
authored andcommitted
test: add test cases for parse_test.go
Signed-off-by: WillSmisi <[email protected]>
1 parent 68519ab commit 563237f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

apis/filters/parse_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,50 @@ func TestArgsMatchKVList(t *testing.T) {
223223
}
224224
}
225225
}
226+
227+
func TestArgsValidate(t *testing.T) {
228+
tests := []struct {
229+
name string
230+
testArgs Args
231+
accepted map[string]bool
232+
wantErr bool
233+
}{
234+
{
235+
name: "mapping keys are in the accepted set",
236+
testArgs: Args{
237+
map[string]map[string]bool{
238+
"created": {
239+
"today": true,
240+
},
241+
},
242+
},
243+
accepted: map[string]bool{
244+
"created": true,
245+
},
246+
wantErr: false,
247+
},
248+
{
249+
name: "mapping keys are not in the accepted set",
250+
testArgs: Args{
251+
map[string]map[string]bool{
252+
"created": {
253+
"today": true,
254+
},
255+
},
256+
},
257+
accepted: map[string]bool{
258+
"created": false,
259+
},
260+
wantErr: true,
261+
},
262+
}
263+
for _, tt := range tests {
264+
t.Run(tt.name, func(t *testing.T) {
265+
err := tt.testArgs.Validate(tt.accepted)
266+
if (err != nil) != tt.wantErr {
267+
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
268+
return
269+
}
270+
})
271+
}
272+
}

0 commit comments

Comments
 (0)