Stream support for k8s client request
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user