| 1 | package filter |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "time" |
| 6 | |
| 7 | "github.com/ffuf/ffuf/v2/pkg/ffuf" |
| 8 | ) |
| 9 | |
| 10 | func TestNewTimeFilter(t *testing.T) { |
| 11 | fp, _ := NewTimeFilter(">100") |
| 12 | |
| 13 | f := fp.(*TimeFilter) |
| 14 | |
| 15 | if !f.gt || f.lt { |
| 16 | t.Errorf("Time filter was expected to have greater-than") |
| 17 | } |
| 18 | |
| 19 | if f.ms != 100 { |
| 20 | t.Errorf("Time filter was expected to have ms == 100") |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | func TestNewTimeFilterError(t *testing.T) { |
| 25 | _, err := NewTimeFilter("100>") |
| 26 | if err == nil { |
| 27 | t.Errorf("Was expecting an error from errenous input data") |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | func TestTimeFiltering(t *testing.T) { |
| 32 | f, _ := NewTimeFilter(">100") |
| 33 | |
| 34 | for i, test := range []struct { |
| 35 | input int64 |
| 36 | output bool |
| 37 | }{ |
| 38 | {1342, true}, |
| 39 | {2000, true}, |
| 40 | {35000, true}, |
| 41 | {1458700, true}, |
| 42 | {99, false}, |
| 43 | {2, false}, |
| 44 | } { |
| 45 | resp := ffuf.Response{ |
| 46 | Data: []byte("dahhhhhtaaaaa"), |
| 47 | Duration: time.Duration(test.input * int64(time.Millisecond)), |
| 48 | } |
| 49 | filterReturn, _ := f.Filter(&resp) |
| 50 | if filterReturn != test.output { |
| 51 | t.Errorf("Filter test %d: Was expecing filter return value of %t but got %t", i, test.output, filterReturn) |
| 52 | } |
| 53 | } |
| 54 | } |