MCPcopy
hub / github.com/kubernetes/client-go / TestDoRequestNewWayObj

Function TestDoRequestNewWayObj

rest/request_test.go:1495–1532  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1493}
1494
1495func TestDoRequestNewWayObj(t *testing.T) {
1496 reqObj := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
1497 reqBodyExpected, _ := runtime.Encode(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), reqObj)
1498 expectedObj := &v1.Service{Spec: v1.ServiceSpec{Ports: []v1.ServicePort{{
1499 Protocol: "TCP",
1500 Port: 12345,
1501 TargetPort: intstr.FromInt(12345),
1502 }}}}
1503 expectedBody, _ := runtime.Encode(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), expectedObj)
1504 fakeHandler := utiltesting.FakeHandler{
1505 StatusCode: 200,
1506 ResponseBody: string(expectedBody),
1507 T: t,
1508 }
1509 testServer := httptest.NewServer(&fakeHandler)
1510 defer testServer.Close()
1511 c := testRESTClient(t, testServer)
1512 obj, err := c.Verb("POST").
1513 Suffix("baz").
1514 Name("bar").
1515 Resource("foo").
1516 Timeout(time.Second).
1517 Body(reqObj).
1518 Do().Get()
1519 if err != nil {
1520 t.Errorf("Unexpected error: %v %#v", err, err)
1521 return
1522 }
1523 if obj == nil {
1524 t.Error("nil obj")
1525 } else if !apiequality.Semantic.DeepDerivative(expectedObj, obj) {
1526 t.Errorf("Expected: %#v, got %#v", expectedObj, obj)
1527 }
1528 tmpStr := string(reqBodyExpected)
1529 requestURL := defaultResourcePathWithPrefix("", "foo", "", "bar/baz")
1530 requestURL += "?timeout=1s"
1531 fakeHandler.ValidateRequest(t, requestURL, "POST", &tmpStr)
1532}
1533
1534func TestDoRequestNewWayFile(t *testing.T) {
1535 reqObj := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}

Callers

nothing calls this directly

Calls 15

ValidateRequestMethod · 0.95
testRESTClientFunction · 0.85
BodyMethod · 0.80
TimeoutMethod · 0.80
SuffixMethod · 0.80
CloseMethod · 0.65
GetMethod · 0.65
DoMethod · 0.65
ResourceMethod · 0.65
VerbMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected