Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/utils/filters/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func FromURLParam(param string) (map[string][]string, error) {
func Validate(filter map[string][]string) error {
for name := range filter {
if _, exist := acceptedFilters[name]; !exist {
return fmt.Errorf("Invalid filter %s", name)
return fmt.Errorf("invalid filter %s", name)
}
}

Expand Down
48 changes: 48 additions & 0 deletions pkg/utils/filters/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,51 @@ func TestParseFilter(t *testing.T) {
}
}
}

func TestValidate(t *testing.T) {
type args struct {
filter map[string][]string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "normal successful case",
args: args{
filter: map[string][]string{
"id": {"a"},
},
},
wantErr: false,
},
{
name: "failure case with nonexistence",
args: args{
filter: map[string][]string{
"id": {"a"},
"nonexistence": {"b"},
},
},
wantErr: true,
},
{
name: "failure case with future filter name",
args: args{
filter: map[string][]string{
"id": {"a"},
"before": {"b"}, // this will be implemented in the future.
},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := Validate(tt.args.filter); (err != nil) != tt.wantErr {
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}