-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathprotocol_test.go
More file actions
46 lines (39 loc) · 1.06 KB
/
protocol_test.go
File metadata and controls
46 lines (39 loc) · 1.06 KB
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
// CGo binding for Avahi
//
// Copyright (C) 2025 by Prashant Andoriya
// See LICENSE for license terms and conditions
//
// Unit tests for Protocol string conversion
//
//go:build linux || freebsd
package avahi
import "testing"
// TestProtocolString verifies string output for known protocol values
func TestProtocolString(t *testing.T) {
tests := []struct {
proto Protocol
want string
}{
{ProtocolIP4, "ip4"},
{ProtocolIP6, "ip6"},
{ProtocolUnspec, "unspec"},
}
for _, tt := range tests {
if got := tt.proto.String(); got != tt.want {
t.Fatalf("proto=%v: got %q, want %q", tt.proto, got, tt.want)
}
}
}
// TestProtocolStringUnknown verifies that unknown protocol values
// are converted into a meaningful, non empty string that clearly
// indicates an unsupported or unexpected protocol
func TestProtocolStringUnknown(t *testing.T) {
p := Protocol(12345)
s := p.String()
if s == "" {
t.Fatalf("Protocol.String() returned empty string for unknown protocol")
}
if s[:7] != "UNKNOWN" {
t.Fatalf("unexpected string for unknown protocol: %q", s)
}
}