forked from yomorun/yomo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
source_test.go
52 lines (41 loc) · 1.01 KB
/
source_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
package yomo
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/yomorun/yomo/core"
"github.com/yomorun/yomo/core/frame"
"github.com/yomorun/yomo/core/ylog"
)
func TestSource(t *testing.T) {
t.Parallel()
source := NewSource(
"test-source",
"localhost:9000",
WithCredential("token:<CREDENTIAL>"),
WithLogger(ylog.Default()),
WithObserveDataTags(0x22),
WithSourceQuicConfig(core.DefalutQuicConfig),
WithSourceTLSConfig(nil),
)
exit := make(chan struct{})
time.AfterFunc(time.Second, func() {
source.Close()
close(exit)
})
source.SetErrorHandler(func(err error) {})
source.SetReceiveHandler(func(tag frame.Tag, data []byte) {
assert.Equal(t, uint32(0x22), tag)
assert.Equal(t, []byte("backflow"), data)
})
// connect to zipper
err := source.Connect()
assert.Nil(t, err)
// send data to zipper
err = source.Write(0x21, []byte("test"))
assert.Nil(t, err)
// broadcast data to zipper
err = source.Broadcast(0x21, []byte("test"))
assert.Nil(t, err)
<-exit
}