-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patherr_test.go
More file actions
45 lines (40 loc) · 1.06 KB
/
err_test.go
File metadata and controls
45 lines (40 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
// CGo binding for Avahi
//
// Copyright (C) 2025 by Prashant Andoriya
// See LICENSE for license terms and conditions
//
// Unit tests for Avahi error code handling
//
//go:build linux || freebsd
package avahi
import (
"strings"
"testing"
)
// Compile time assertion that ErrCode implements the error interface.
// This will fail to compile if ErrCode no longer satisfies error.
var _ error = ErrFailure
// TestErrCodeError verifies that ErrCode.Error() returns a non-empty,
//
// The test intentionally does not assert the exact error message, as
// the underlying string is provided by the Avahi C library and may vary across versions or environments.
func TestErrCodeError(t *testing.T) {
tests := []ErrCode{
NoError,
ErrFailure,
ErrInvalidHostName,
ErrInvalidDomainName,
ErrTimeout,
ErrInvalidFlags,
ErrDNSNXDOMAIN,
}
for _, ec := range tests {
s := ec.Error()
if s == "" {
t.Fatalf("ErrCode(%d).Error() returned empty string", ec)
}
if !strings.HasPrefix(s, "avahi: ") {
t.Fatalf("unexpected error prefix for ErrCode(%d): %q", ec, s)
}
}
}