Add TestStreamingHashtag
This commit is contained in:
parent
e2a440b170
commit
c32612c3c9
|
@ -165,6 +165,9 @@ func TestStreamingUser(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) {
|
||||||
if isEnd {
|
if isEnd {
|
||||||
return
|
return
|
||||||
|
} else if r.URL.Path != "/api/v1/streaming/user" {
|
||||||
|
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
f, _ := w.(http.Flusher)
|
f, _ := w.(http.Flusher)
|
||||||
fmt.Fprintln(w, `
|
fmt.Fprintln(w, `
|
||||||
|
@ -202,7 +205,7 @@ func TestStreamingPublic(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) {
|
||||||
if isEnd {
|
if isEnd {
|
||||||
return
|
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)
|
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -229,7 +232,7 @@ data: {"content": "bar"}
|
||||||
AccessToken: "zoo",
|
AccessToken: "zoo",
|
||||||
})
|
})
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
q, err := client.StreamingPublic(ctx, false)
|
q, err := client.StreamingPublic(ctx, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not be fail: %v", err)
|
t.Fatalf("should not be fail: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -252,4 +255,41 @@ data: {"content": "bar"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStreamingHashtag(t *testing.T) {
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user