-
Notifications
You must be signed in to change notification settings - Fork 8
/
server_test.go
107 lines (88 loc) · 1.9 KB
/
server_test.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package avahi
import (
"testing"
"time"
"github.com/godbus/dbus/v5"
)
// TestNew ensures that New() works without errors.
func TestNew(t *testing.T) {
conn, err := dbus.SystemBus()
if err != nil {
t.Fatal(err)
}
_, err = ServerNew(conn)
if err != nil {
t.Fatal(err)
}
}
func TestNewClose(t *testing.T) {
conn, err := dbus.SystemBus()
if err != nil {
t.Fatal(err)
}
a, err := ServerNew(conn)
if err != nil {
t.Fatal(err)
}
doneChannel := make(chan struct{})
go func() {
a.Close()
doneChannel <- struct{}{}
}()
select {
case <-time.After(2 * time.Second):
t.Fatal("Close() is deadlocked")
case <-doneChannel:
}
}
func TestBasic(t *testing.T) {
conn, err := dbus.SystemBus()
if err != nil {
t.Fatal(err)
}
a, err := ServerNew(conn)
if err != nil {
t.Fatalf("Avahi new failed: %v", err)
}
s, err := a.GetHostName()
if err != nil {
t.Fatalf("GetHostName() failed: %v", err)
}
t.Log("GetHostName()", s)
s, err = a.GetAlternativeHostName(s)
if err != nil {
t.Fatalf("GetAlternativeHostName() failed: %v", err)
}
t.Log("GetAlternativeHostName()", s)
////
i, err := a.GetAPIVersion()
if err != nil {
t.Fatalf("GetAPIVersion() failed: %v", err)
}
t.Log("GetAPIVersion()", i)
s, err = a.GetNetworkInterfaceNameByIndex(1)
if err != nil {
t.Fatalf("GetNetworkInterfaceNameByIndex() failed: %v", err)
}
t.Log("GetNetworkInterfaceNameByIndex()", s)
i, err = a.GetNetworkInterfaceIndexByName(s)
if err != nil {
t.Fatalf("GetNetworkInterfaceIndexByName() failed: %v", err)
}
if i != 1 {
t.Fatal("GetNetworkInterfaceIndexByName() returned wrong index")
}
t.Log("GetNetworkInterfaceIndexByName()", i)
///
egc, err := a.EntryGroupNew()
if err != nil {
t.Fatalf("EntryGroupNew() failed: %v", err)
}
b, err := egc.IsEmpty()
if err != nil {
t.Fatalf("egc.IsEmpty() failed: %v", err)
}
if b != true {
t.Fatal("Entry group must initially be empty")
}
}