@@ -2,19 +2,51 @@ package yomo
22
33import (
44 "testing"
5+ "time"
56
67 "github.com/stretchr/testify/assert"
8+ "github.com/yomorun/yomo/core"
9+ "github.com/yomorun/yomo/core/frame"
10+ "github.com/yomorun/yomo/core/ylog"
711)
812
9- func TestSourceSendDataToServer (t * testing.T ) {
10- source := NewSource ("test-source" , "localhost:9000" , WithCredential ("token:<CREDENTIAL>" ))
11- defer source .Close ()
13+ func TestSource (t * testing.T ) {
14+ t .Parallel ()
1215
13- // connect to server
16+ source := NewSource (
17+ "test-source" ,
18+ "localhost:9000" ,
19+ WithCredential ("token:<CREDENTIAL>" ),
20+ WithLogger (ylog .Default ()),
21+ WithObserveDataTags (0x22 ),
22+ WithSourceQuicConfig (core .DefalutQuicConfig ),
23+ WithSourceTLSConfig (nil ),
24+ )
25+
26+ exit := make (chan struct {})
27+ time .AfterFunc (time .Second , func () {
28+ source .Close ()
29+ close (exit )
30+ })
31+
32+ source .SetErrorHandler (func (err error ) {})
33+
34+ source .SetReceiveHandler (func (tag frame.Tag , data []byte ) {
35+ assert .Equal (t , uint32 (0x22 ), tag )
36+ assert .Equal (t , []byte ("backflow" ), data )
37+ })
38+
39+ // connect to zipper
1440 err := source .Connect ()
1541 assert .Nil (t , err )
1642
17- // send data to server
43+ // send data to zipper
1844 err = source .Write (0x21 , []byte ("test" ))
1945 assert .Nil (t , err )
46+
47+ // broadcast data to zipper
48+ err = source .Broadcast (0x21 , []byte ("test" ))
49+ assert .Nil (t , err )
50+
51+ <- exit
2052}
0 commit comments