-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
115 lines (92 loc) · 2.12 KB
/
client_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
108
109
110
111
112
113
114
115
package helvargo
import (
"fmt"
"path"
"sync"
"testing"
"github.com/nuqz/chanfan"
"github.com/nuqz/helvar-go/message"
ht "github.com/nuqz/helvar-go/testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var (
fakeSrvPort = 49876
)
func TestClient(t *testing.T) {
defaultNet := ht.MustNetFromYAMLFile(path.Join("testing", "test_net.yml"))
fakeSrv := ht.NewRouter(fmt.Sprintf(":%d", fakeSrvPort), defaultNet)
require.NoError(t, fakeSrv.Listen())
client := NewClient("localhost", fakeSrvPort)
_, err := client.Transceive(message.NewQueryTime())
assert.Error(t, err)
errs, err := client.Connect(4, 4)
require.NoError(t, err)
go func() {
for err := range chanfan.Merge(errs) {
require.NoError(t, err)
}
}()
var wg sync.WaitGroup
wg.Add(4)
go func() {
clusters, err := client.GetClusters()
require.NoError(t, err)
for _, expected := range defaultNet.Clusters {
found := false
for _, actual := range clusters {
found = actual.ID == expected.ID
if found {
break
}
}
assert.True(t, found)
}
wg.Done()
}()
go func() {
routers, err := client.GetRouters()
require.NoError(t, err)
for _, expected := range defaultNet.Routers {
found := false
for _, actual := range routers {
found = actual.ID == expected.ID
if found {
break
}
}
assert.True(t, found)
}
wg.Done()
}()
go func() {
groups, err := client.GetGroups()
require.NoError(t, err)
for _, group := range groups {
name, err := client.GetGroupName(group)
require.NoError(t, err)
group.Name = name
devs, err := client.GetDevices(group)
require.NoError(t, err)
t.Logf("%+v", devs)
for _, dev := range devs {
name, err := client.GetDeviceName(dev)
require.NoError(t, err)
dev.Name = name
t.Logf("GID: %d Name: %s / Address: %s Name %s",
group.ID, group.Name, dev.Address, dev.Name)
}
}
wg.Done()
}()
go func() {
netTime, err := client.GetTime()
require.NoError(t, err)
t.Log(netTime)
wg.Done()
}()
wg.Wait()
client.Disconnect()
_, err = client.Transceive(message.NewQueryTime())
assert.Error(t, err)
}