Add TestStreamingHashtag

pull/50/head
178inaba 2017-04-30 04:53:13 +09:00
parent e2a440b170
commit c32612c3c9
1 changed files with 42 additions and 2 deletions

View File

@ -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)
}
}