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