forked from potato2003/actioncable-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsumer_convey_test.go
58 lines (47 loc) · 1.21 KB
/
consumer_convey_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
package actioncable
import (
"fmt"
"net/http"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
func TestConsumerConnect(t *testing.T) {
url := TestWebsocketURL()
if url == nil {
fmt.Printf("Skip %s because os.Getend(\"TEST_WS\") is not set\n", t.Name())
return
}
Convey("Given a valid URL", t, func() {
consumer, _ := CreateConsumer(url, nil)
Convey("consumer.connection should not be nil", func() {
consumer.Connect()
So(consumer.connection, ShouldNotBeNil)
})
Convey("welcome message should be received", func() {
done := make(chan struct{})
go func() {
consumer.Connect()
consumer.connection.waitUntilReady()
done <- struct{}{}
}()
select {
case <-done:
So(consumer.connection.connectedAt, ShouldNotBeNil)
case <-time.After(1 * time.Second):
t.Fatal("Test didn't finish in time")
}
})
Convey("with ConsumerOptions struct", func() {
opt := NewConsumerOptions()
header := http.Header{}
header.Set("User-Agent", "Dummy")
opt.SetHeader(&header)
consumer, _ := CreateConsumer(url, opt)
Convey("consumer.connection should not be nil", func() {
consumer.Connect()
So(consumer.connection, ShouldNotBeNil)
})
})
})
}