Change PodLogs test to use testClient validate

And also switch the 200s to http.StatusOK while I'm here.
This commit is contained in:
Kris 2015-11-17 14:54:09 -08:00
parent a10a2f0e2b
commit 4115738558

View File

@ -17,6 +17,7 @@ limitations under the License.
package unversioned
import (
"net/http"
"net/url"
"testing"
@ -31,7 +32,7 @@ func TestListEmptyPods(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath("pods", ns, ""), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: &api.PodList{}},
Response: Response{StatusCode: http.StatusOK, Body: &api.PodList{}},
}
podList, err := c.Setup(t).Pods(ns).List(labels.Everything(), fields.Everything())
c.Validate(t, podList, err)
@ -41,7 +42,7 @@ func TestListPods(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath("pods", ns, ""), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200,
Response: Response{StatusCode: http.StatusOK,
Body: &api.PodList{
Items: []api.Pod{
{
@ -72,7 +73,7 @@ func TestListPodsLabels(t *testing.T) {
Path: testapi.Default.ResourcePath("pods", ns, ""),
Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: Response{
StatusCode: 200,
StatusCode: http.StatusOK,
Body: &api.PodList{
Items: []api.Pod{
{
@ -102,7 +103,7 @@ func TestGetPod(t *testing.T) {
c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{
StatusCode: 200,
StatusCode: http.StatusOK,
Body: &api.Pod{
Status: api.PodStatus{
Phase: api.PodRunning,
@ -135,7 +136,7 @@ func TestDeletePod(t *testing.T) {
ns := api.NamespaceDefault
c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200},
Response: Response{StatusCode: http.StatusOK},
}
err := c.Setup(t).Pods(ns).Delete("foo", nil)
c.Validate(t, nil, err)
@ -157,7 +158,7 @@ func TestCreatePod(t *testing.T) {
c := &testClient{
Request: testRequest{Method: "POST", Path: testapi.Default.ResourcePath("pods", ns, ""), Query: buildQueryValues(nil), Body: requestPod},
Response: Response{
StatusCode: 200,
StatusCode: http.StatusOK,
Body: requestPod,
},
}
@ -182,7 +183,7 @@ func TestUpdatePod(t *testing.T) {
}
c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: requestPod},
Response: Response{StatusCode: http.StatusOK, Body: requestPod},
}
receivedPod, err := c.Setup(t).Pods(ns).Update(requestPod)
c.Validate(t, receivedPod, err)
@ -194,22 +195,22 @@ func TestPodGetLogs(t *testing.T) {
Follow: true,
Timestamps: true,
}
c := &testClient{}
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.Default.ResourcePath("pods", ns, "podName") + "/log",
Query: url.Values{
"follow": []string{"true"},
"timestamps": []string{"true"},
},
},
Response: Response{StatusCode: http.StatusOK},
}
request := c.Setup(t).Pods(ns).GetLogs("podName", opts)
if request.verb != "GET" {
t.Fatalf("unexpected verb %q, expected %q", request.verb, "GET")
}
if request.resource != "pods" {
t.Fatalf("unexpected resource %q, expected %q", request.subresource, "pods")
}
if request.subresource != "log" {
t.Fatalf("unexpected subresource %q, expected %q", request.subresource, "log")
}
expected := map[string]string{"container": "", "follow": "true", "previous": "false", "timestamps": "true"}
for gotKey, gotValue := range request.params {
if gotValue[0] != expected[gotKey] {
t.Fatalf("unexpected key-value %s=%s, expected %s=%s", gotKey, gotValue[0], gotKey, expected[gotKey])
}
body, err := c.Setup(t).Pods(ns).GetLogs("podName", opts).Stream()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
defer body.Close()
c.ValidateCommon(t, err)
}