Add TestStreamingWS

This commit is contained in:
178inaba 2017-04-23 20:04:06 +09:00
parent df768f24da
commit ee6a6dbcc9

View File

@ -151,6 +151,31 @@ func wsTest(t *testing.T, q chan Event, cancel func()) {
} }
} }
func TestStreamingWS(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(wsMock))
defer ts.Close()
client := NewClient(&Config{Server: ":"})
_, err := client.StreamingWSPublicLocal(context.Background())
if err == nil {
t.Fatalf("should be fail: %v", err)
}
client = NewClient(&Config{Server: ts.URL})
ctx, cancel := context.WithCancel(context.Background())
cancel()
q, err := client.StreamingWSPublicLocal(ctx)
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
go func() {
e := <-q
if errorEvent, ok := e.(*ErrorEvent); !ok {
t.Fatalf("should be fail: %v", errorEvent.err)
}
}()
}
func TestHandleWS(t *testing.T) { func TestHandleWS(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
u := websocket.Upgrader{} u := websocket.Upgrader{}