From c32612c3c98c05f682bf31d81727b5537156abe6 Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Sun, 30 Apr 2017 04:53:13 +0900 Subject: [PATCH] Add TestStreamingHashtag --- streaming_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/streaming_test.go b/streaming_test.go index f2cfa86..9f5b715 100644 --- a/streaming_test.go +++ b/streaming_test.go @@ -165,6 +165,9 @@ func TestStreamingUser(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if isEnd { return + } else if r.URL.Path != "/api/v1/streaming/user" { + http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) + return } f, _ := w.(http.Flusher) fmt.Fprintln(w, ` @@ -202,7 +205,7 @@ func TestStreamingPublic(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if isEnd { return - } else if r.URL.Path != "/api/v1/streaming/public" { + } else if r.URL.Path != "/api/v1/streaming/public/local" { http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return } @@ -229,7 +232,7 @@ data: {"content": "bar"} AccessToken: "zoo", }) ctx, cancel := context.WithCancel(context.Background()) - q, err := client.StreamingPublic(ctx, false) + q, err := client.StreamingPublic(ctx, true) if err != nil { t.Fatalf("should not be fail: %v", err) } @@ -252,4 +255,41 @@ data: {"content": "bar"} } func TestStreamingHashtag(t *testing.T) { + var isEnd bool + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if isEnd { + return + } else if r.URL.Path != "/api/v1/streaming/hashtag/local" { + http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) + return + } + f, _ := w.(http.Flusher) + fmt.Fprintln(w, ` +event: update +data: {"content": "foo"} + `) + f.Flush() + isEnd = true + })) + defer ts.Close() + + client := NewClient(&Config{Server: ts.URL}) + ctx, cancel := context.WithCancel(context.Background()) + time.AfterFunc(time.Second, cancel) + q, err := client.StreamingHashtag(ctx, "hashtag", true) + if err != nil { + t.Fatalf("should not be fail: %v", err) + } + events := []Event{} + for e := range q { + if _, ok := e.(*ErrorEvent); !ok { + events = append(events, e) + } + } + if len(events) != 1 { + t.Fatalf("result should be one: %d", len(events)) + } + if events[0].(*UpdateEvent).Status.Content != "foo" { + t.Fatalf("want %q but %q", "foo", events[0].(*UpdateEvent).Status.Content) + } }