forked from zeromq/goczmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
beacon_test.go
74 lines (59 loc) · 1.07 KB
/
beacon_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
package goczmq
import (
"fmt"
"testing"
)
// TestBeacon tests sending a UDP beacon to a listener
func TestBeacon(t *testing.T) {
speaker := NewBeacon()
var err error
if testing.Verbose() {
err := speaker.Verbose()
if err != nil {
t.Error(err)
}
}
_, err = speaker.Configure(9999)
if err != nil {
t.Error(err)
}
listener := NewBeacon()
if testing.Verbose() {
err = listener.Verbose()
if err != nil {
t.Error(err)
}
}
_, err = listener.Configure(9999)
if err != nil {
t.Error(err)
}
err = listener.Subscribe("HI")
if err != nil {
t.Error(err)
}
err = speaker.Publish("HI", 100)
if err != nil {
t.Error(err)
}
msg := listener.Recv(500)
if len(msg) == 2 {
t.Logf("Address: %s", string(msg[0]))
t.Logf("Beacon: %s", string(msg[1]))
}
listener.Destroy()
speaker.Destroy()
}
func ExampleBeacon() {
beacon := NewBeacon()
defer beacon.Destroy()
address, err := beacon.Configure(9999)
if err != nil {
panic(err)
}
fmt.Printf("started beacon on: %s", address)
err = beacon.Publish("HI", 100)
if err != nil {
panic(err)
}
}