File: utils_windows_test.go

package info (click to toggle)
golang-github-prometheus-community-pro-bing 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 316 kB
  • sloc: makefile: 30
file content (56 lines) | stat: -rw-r--r-- 1,057 bytes parent folder | download | duplicates (2)
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)
			}
		})
	}
}