mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 11:13:48 +00:00
Change PodLogs test to use testClient validate
And also switch the 200s to http.StatusOK while I'm here.
This commit is contained in:
parent
a10a2f0e2b
commit
4115738558
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package unversioned
|
package unversioned
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ func TestListEmptyPods(t *testing.T) {
|
|||||||
ns := api.NamespaceDefault
|
ns := api.NamespaceDefault
|
||||||
c := &testClient{
|
c := &testClient{
|
||||||
Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath("pods", ns, ""), Query: buildQueryValues(nil)},
|
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())
|
podList, err := c.Setup(t).Pods(ns).List(labels.Everything(), fields.Everything())
|
||||||
c.Validate(t, podList, err)
|
c.Validate(t, podList, err)
|
||||||
@ -41,7 +42,7 @@ func TestListPods(t *testing.T) {
|
|||||||
ns := api.NamespaceDefault
|
ns := api.NamespaceDefault
|
||||||
c := &testClient{
|
c := &testClient{
|
||||||
Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath("pods", ns, ""), Query: buildQueryValues(nil)},
|
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{
|
Body: &api.PodList{
|
||||||
Items: []api.Pod{
|
Items: []api.Pod{
|
||||||
{
|
{
|
||||||
@ -72,7 +73,7 @@ func TestListPodsLabels(t *testing.T) {
|
|||||||
Path: testapi.Default.ResourcePath("pods", ns, ""),
|
Path: testapi.Default.ResourcePath("pods", ns, ""),
|
||||||
Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
|
Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
|
||||||
Response: Response{
|
Response: Response{
|
||||||
StatusCode: 200,
|
StatusCode: http.StatusOK,
|
||||||
Body: &api.PodList{
|
Body: &api.PodList{
|
||||||
Items: []api.Pod{
|
Items: []api.Pod{
|
||||||
{
|
{
|
||||||
@ -102,7 +103,7 @@ func TestGetPod(t *testing.T) {
|
|||||||
c := &testClient{
|
c := &testClient{
|
||||||
Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(nil)},
|
Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(nil)},
|
||||||
Response: Response{
|
Response: Response{
|
||||||
StatusCode: 200,
|
StatusCode: http.StatusOK,
|
||||||
Body: &api.Pod{
|
Body: &api.Pod{
|
||||||
Status: api.PodStatus{
|
Status: api.PodStatus{
|
||||||
Phase: api.PodRunning,
|
Phase: api.PodRunning,
|
||||||
@ -135,7 +136,7 @@ func TestDeletePod(t *testing.T) {
|
|||||||
ns := api.NamespaceDefault
|
ns := api.NamespaceDefault
|
||||||
c := &testClient{
|
c := &testClient{
|
||||||
Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(nil)},
|
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)
|
err := c.Setup(t).Pods(ns).Delete("foo", nil)
|
||||||
c.Validate(t, nil, err)
|
c.Validate(t, nil, err)
|
||||||
@ -157,7 +158,7 @@ func TestCreatePod(t *testing.T) {
|
|||||||
c := &testClient{
|
c := &testClient{
|
||||||
Request: testRequest{Method: "POST", Path: testapi.Default.ResourcePath("pods", ns, ""), Query: buildQueryValues(nil), Body: requestPod},
|
Request: testRequest{Method: "POST", Path: testapi.Default.ResourcePath("pods", ns, ""), Query: buildQueryValues(nil), Body: requestPod},
|
||||||
Response: Response{
|
Response: Response{
|
||||||
StatusCode: 200,
|
StatusCode: http.StatusOK,
|
||||||
Body: requestPod,
|
Body: requestPod,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -182,7 +183,7 @@ func TestUpdatePod(t *testing.T) {
|
|||||||
}
|
}
|
||||||
c := &testClient{
|
c := &testClient{
|
||||||
Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(nil)},
|
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)
|
receivedPod, err := c.Setup(t).Pods(ns).Update(requestPod)
|
||||||
c.Validate(t, receivedPod, err)
|
c.Validate(t, receivedPod, err)
|
||||||
@ -194,22 +195,22 @@ func TestPodGetLogs(t *testing.T) {
|
|||||||
Follow: true,
|
Follow: true,
|
||||||
Timestamps: 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)
|
body, err := c.Setup(t).Pods(ns).GetLogs("podName", opts).Stream()
|
||||||
if request.verb != "GET" {
|
if err != nil {
|
||||||
t.Fatalf("unexpected verb %q, expected %q", request.verb, "GET")
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
|
||||||
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])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
defer body.Close()
|
||||||
|
c.ValidateCommon(t, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user