Stream support for k8s client request

This commit is contained in:
jhadvig
2014-09-26 19:50:53 +02:00
parent 569f61e072
commit 755b598a7d
2 changed files with 54 additions and 0 deletions

View File

@@ -434,3 +434,37 @@ func TestWatch(t *testing.T) {
t.Fatal("Unexpected non-close")
}
}
func TestStream(t *testing.T) {
auth := AuthInfo{User: "user", Password: "pass"}
expectedBody := "expected body"
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
checkAuth(t, auth, r)
flusher, ok := w.(http.Flusher)
if !ok {
panic("need flusher!")
}
w.Header().Set("Transfer-Encoding", "chunked")
w.WriteHeader(http.StatusOK)
w.Write([]byte(expectedBody))
flusher.Flush()
}))
c, err := New(testServer.URL, "v1beta1", &auth)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
readCloser, err := c.Get().Path("path/to/stream/thing").Stream()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
defer readCloser.Close()
buf := new(bytes.Buffer)
buf.ReadFrom(readCloser)
resultBody := buf.String()
if expectedBody != resultBody {
t.Errorf("Expected %s, got %s", expectedBody, resultBody)
}
}