| 1 | package packets |
| 2 | |
| 3 | import ( |
| 4 | "net" |
| 5 | "reflect" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestQueueActivity(t *testing.T) { |
| 10 | i := net.IP{} |
| 11 | h := net.HardwareAddr{} |
| 12 | a := Activity{ |
| 13 | IP: i, |
| 14 | MAC: h, |
| 15 | } |
| 16 | var units = []struct { |
| 17 | got interface{} |
| 18 | exp interface{} |
| 19 | }{ |
| 20 | {a.IP, i}, |
| 21 | {a.MAC, h}, |
| 22 | {a.Source, false}, |
| 23 | } |
| 24 | for _, u := range units { |
| 25 | if !reflect.DeepEqual(u.exp, u.got) { |
| 26 | t.Fatalf("expected '%v', got '%v'", u.exp, u.got) |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | func TestQueueTraffic(t *testing.T) { |
| 32 | tr := Traffic{} |
| 33 | var units = []struct { |
| 34 | got interface{} |
| 35 | exp interface{} |
| 36 | }{ |
| 37 | {tr.Sent, uint64(0)}, |
| 38 | {tr.Received, uint64(0)}, |
| 39 | } |
| 40 | for _, u := range units { |
| 41 | if !reflect.DeepEqual(u.exp, u.got) { |
| 42 | t.Fatalf("expected '%v', got '%v'", u.exp, u.got) |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | func TestQueueStats(t *testing.T) { |
| 48 | s := Stats{} |
| 49 | var units = []struct { |
| 50 | got interface{} |
| 51 | exp interface{} |
| 52 | }{ |
| 53 | {s.Sent, uint64(0)}, |
| 54 | {s.Received, uint64(0)}, |
| 55 | {s.PktReceived, uint64(0)}, |
| 56 | {s.Errors, uint64(0)}, |
| 57 | } |
| 58 | for _, u := range units { |
| 59 | if !reflect.DeepEqual(u.exp, u.got) { |
| 60 | t.Fatalf("expected '%v', got '%v'", u.exp, u.got) |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | // TODO: add tests for the rest of queue.go |