From ee6a6dbcc97838b9dbba51cb57eec969b004a239 Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Sun, 23 Apr 2017 20:04:06 +0900 Subject: [PATCH] Add TestStreamingWS --- streaming_ws_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/streaming_ws_test.go b/streaming_ws_test.go index 304e6bc..f041984 100644 --- a/streaming_ws_test.go +++ b/streaming_ws_test.go @@ -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) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { u := websocket.Upgrader{}