| 1 | package filter |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | ) |
| 6 | |
| 7 | func TestNewFilterByName(t *testing.T) { |
| 8 | scf, _ := NewFilterByName("status", "200") |
| 9 | if _, ok := scf.(*StatusFilter); !ok { |
| 10 | t.Errorf("Was expecting statusfilter") |
| 11 | } |
| 12 | |
| 13 | szf, _ := NewFilterByName("size", "200") |
| 14 | if _, ok := szf.(*SizeFilter); !ok { |
| 15 | t.Errorf("Was expecting sizefilter") |
| 16 | } |
| 17 | |
| 18 | wf, _ := NewFilterByName("word", "200") |
| 19 | if _, ok := wf.(*WordFilter); !ok { |
| 20 | t.Errorf("Was expecting wordfilter") |
| 21 | } |
| 22 | |
| 23 | lf, _ := NewFilterByName("line", "200") |
| 24 | if _, ok := lf.(*LineFilter); !ok { |
| 25 | t.Errorf("Was expecting linefilter") |
| 26 | } |
| 27 | |
| 28 | ref, _ := NewFilterByName("regexp", "200") |
| 29 | if _, ok := ref.(*RegexpFilter); !ok { |
| 30 | t.Errorf("Was expecting regexpfilter") |
| 31 | } |
| 32 | |
| 33 | tf, _ := NewFilterByName("time", "200") |
| 34 | if _, ok := tf.(*TimeFilter); !ok { |
| 35 | t.Errorf("Was expecting timefilter") |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | func TestNewFilterByNameError(t *testing.T) { |
| 40 | _, err := NewFilterByName("status", "invalid") |
| 41 | if err == nil { |
| 42 | t.Errorf("Was expecing an error") |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | func TestNewFilterByNameNotFound(t *testing.T) { |
| 47 | _, err := NewFilterByName("nonexistent", "invalid") |
| 48 | if err == nil { |
| 49 | t.Errorf("Was expecing an error with invalid filter name") |
| 50 | } |
| 51 | } |