File tree Expand file tree Collapse file tree 2 files changed +49
-1
lines changed
Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ func FromURLParam(param string) (map[string][]string, error) {
9696func Validate (filter map [string ][]string ) error {
9797 for name := range filter {
9898 if _ , exist := acceptedFilters [name ]; ! exist {
99- return fmt .Errorf ("Invalid filter %s" , name )
99+ return fmt .Errorf ("invalid filter %s" , name )
100100 }
101101 }
102102
Original file line number Diff line number Diff line change @@ -50,3 +50,51 @@ func TestParseFilter(t *testing.T) {
5050 }
5151 }
5252}
53+
54+ func TestValidate (t * testing.T ) {
55+ type args struct {
56+ filter map [string ][]string
57+ }
58+ tests := []struct {
59+ name string
60+ args args
61+ wantErr bool
62+ }{
63+ {
64+ name : "normal successful case" ,
65+ args : args {
66+ filter : map [string ][]string {
67+ "id" : {"a" },
68+ },
69+ },
70+ wantErr : false ,
71+ },
72+ {
73+ name : "failure case with nonexistence" ,
74+ args : args {
75+ filter : map [string ][]string {
76+ "id" : {"a" },
77+ "nonexistence" : {"b" },
78+ },
79+ },
80+ wantErr : true ,
81+ },
82+ {
83+ name : "failure case with future filter name" ,
84+ args : args {
85+ filter : map [string ][]string {
86+ "id" : {"a" },
87+ "before" : {"b" }, // this will be implemented in the future.
88+ },
89+ },
90+ wantErr : true ,
91+ },
92+ }
93+ for _ , tt := range tests {
94+ t .Run (tt .name , func (t * testing.T ) {
95+ if err := Validate (tt .args .filter ); (err != nil ) != tt .wantErr {
96+ t .Errorf ("Validate() error = %v, wantErr %v" , err , tt .wantErr )
97+ }
98+ })
99+ }
100+ }
You can’t perform that action at this time.
0 commit comments