Debian Codegraph @

utils_windows_test.go

raw symbols SCIP
1 // Copyright The Prometheus Authors
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 //go:build windows
15 // +build windows
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, // default size
31 ipv4: true,
32 },
33 expected: 2048,
34 },
35 {
36 description: "IPv4 total size > 2048",
37 pinger: &Pinger{
38 Size: 1993, // 2048 - 2 * (ipv4.HeaderLen + 8) + 1
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, // 2048 - 2 * (ipv6.HeaderLen + 8) + 1
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 }