Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change PodLogs test to use testClient validate #17396

Merged
merged 1 commit into from
Nov 19, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 24 additions & 23 deletions pkg/client/unversioned/pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package unversioned

import (
"net/http"
"net/url"
"testing"

Expand All @@ -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)
Expand All @@ -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{
{
Expand Down Expand Up @@ -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{
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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,
},
}
Expand All @@ -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)
Expand All @@ -194,22 +195,22 @@ func TestPodGetLogs(t *testing.T) {
Follow: true,
Timestamps: true,
}
c := &testClient{}

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")
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},
}
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])
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who's checking this after the change? ValidateCommon seems not checking the request.params.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I misunderstood the usage of the request in testClient. Nevermind my previous question.

Did you remove "previous": "false" intentionally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. testClient actually roundtrips a request to a local http server. In that round trip, empty and false query parameters get stripped, so the server never sees them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

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)
}