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

Function TestDoRequestNewWayReader

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

Source from the content-addressed store, hash-verified

1454}
1455
1456func TestDoRequestNewWayReader(t *testing.T) {
1457 reqObj := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
1458 reqBodyExpected, _ := runtime.Encode(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), reqObj)
1459 expectedObj := &v1.Service{Spec: v1.ServiceSpec{Ports: []v1.ServicePort{{
1460 Protocol: "TCP",
1461 Port: 12345,
1462 TargetPort: intstr.FromInt(12345),
1463 }}}}
1464 expectedBody, _ := runtime.Encode(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), expectedObj)
1465 fakeHandler := utiltesting.FakeHandler{
1466 StatusCode: 200,
1467 ResponseBody: string(expectedBody),
1468 T: t,
1469 }
1470 testServer := httptest.NewServer(&fakeHandler)
1471 defer testServer.Close()
1472 c := testRESTClient(t, testServer)
1473 obj, err := c.Verb("POST").
1474 Resource("bar").
1475 Name("baz").
1476 Prefix("foo").
1477 Timeout(time.Second).
1478 Body(bytes.NewBuffer(reqBodyExpected)).
1479 Do().Get()
1480 if err != nil {
1481 t.Errorf("Unexpected error: %v %#v", err, err)
1482 return
1483 }
1484 if obj == nil {
1485 t.Error("nil obj")
1486 } else if !apiequality.Semantic.DeepDerivative(expectedObj, obj) {
1487 t.Errorf("Expected: %#v, got %#v", expectedObj, obj)
1488 }
1489 tmpStr := string(reqBodyExpected)
1490 requestURL := defaultResourcePathWithPrefix("foo", "bar", "", "baz")
1491 requestURL += "?timeout=1s"
1492 fakeHandler.ValidateRequest(t, requestURL, "POST", &tmpStr)
1493}
1494
1495func TestDoRequestNewWayObj(t *testing.T) {
1496 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
PrefixMethod · 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…