| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package probing |
| 18 |
|
| 19 |
import "testing" |
| 20 |
|
| 21 |
func TestGetMessageLength(t *testing.T) { |
| 22 |
tests := []struct { |
| 23 |
description string |
| 24 |
pinger *Pinger |
| 25 |
expected int |
| 26 |
}{ |
| 27 |
{ |
| 28 |
description: "IPv4 total size < 2048", |
| 29 |
pinger: &Pinger{ |
| 30 |
Size: 24, |
| 31 |
ipv4: true, |
| 32 |
}, |
| 33 |
expected: 2048, |
| 34 |
}, |
| 35 |
{ |
| 36 |
description: "IPv4 total size > 2048", |
| 37 |
pinger: &Pinger{ |
| 38 |
Size: 1993, |
| 39 |
ipv4: true, |
| 40 |
}, |
| 41 |
expected: 2049, |
| 42 |
}, |
| 43 |
{ |
| 44 |
description: "IPv6 total size < 2048", |
| 45 |
pinger: &Pinger{ |
| 46 |
Size: 24, |
| 47 |
ipv4: false, |
| 48 |
}, |
| 49 |
expected: 2048, |
| 50 |
}, |
| 51 |
{ |
| 52 |
description: "IPv6 total size > 2048", |
| 53 |
pinger: &Pinger{ |
| 54 |
Size: 1953, |
| 55 |
ipv4: false, |
| 56 |
}, |
| 57 |
expected: 2049, |
| 58 |
}, |
| 59 |
} |
| 60 |
|
| 61 |
for _, tt := range tests { |
| 62 |
t.Run(tt.description, func(t *testing.T) { |
| 63 |
actual := tt.pinger.getMessageLength() |
| 64 |
if tt.expected != actual { |
| 65 |
t.Fatalf("unexpected message length, expected: %d, actual %d", tt.expected, actual) |
| 66 |
} |
| 67 |
}) |
| 68 |
} |
| 69 |
} |