Added tests for list API calls
This commit is contained in:
parent
5ff4ecfd52
commit
f9fc8ad95d
3 changed files with 366 additions and 1 deletions
|
@ -293,3 +293,43 @@ data: {"content": "foo"}
|
|||
t.Fatalf("want %q but %q", "foo", events[0].(*UpdateEvent).Status.Content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStreamingList(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/list" {
|
||||
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.StreamingList(ctx, "1")
|
||||
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…
Add table
Add a link
Reference in a new issue