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

Function TestDoRequestNewWay

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

Source from the content-addressed store, hash-verified

1225}
1226
1227func TestDoRequestNewWay(t *testing.T) {
1228 reqBody := "request body"
1229 expectedObj := &v1.Service{Spec: v1.ServiceSpec{Ports: []v1.ServicePort{{
1230 Protocol: "TCP",
1231 Port: 12345,
1232 TargetPort: intstr.FromInt(12345),
1233 }}}}
1234 expectedBody, _ := runtime.Encode(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), expectedObj)
1235 fakeHandler := utiltesting.FakeHandler{
1236 StatusCode: 200,
1237 ResponseBody: string(expectedBody),
1238 T: t,
1239 }
1240 testServer := httptest.NewServer(&fakeHandler)
1241 defer testServer.Close()
1242 c := testRESTClient(t, testServer)
1243 obj, err := c.Verb("POST").
1244 Prefix("foo", "bar").
1245 Suffix("baz").
1246 Timeout(time.Second).
1247 Body([]byte(reqBody)).
1248 Do().Get()
1249 if err != nil {
1250 t.Errorf("Unexpected error: %v %#v", err, err)
1251 return
1252 }
1253 if obj == nil {
1254 t.Error("nil obj")
1255 } else if !apiequality.Semantic.DeepDerivative(expectedObj, obj) {
1256 t.Errorf("Expected: %#v, got %#v", expectedObj, obj)
1257 }
1258 requestURL := defaultResourcePathWithPrefix("foo/bar", "", "", "baz")
1259 requestURL += "?timeout=1s"
1260 fakeHandler.ValidateRequest(t, requestURL, "POST", &reqBody)
1261}
1262
1263// This test assumes that the client implementation backs off exponentially, for an individual request.
1264func TestBackoffLifecycle(t *testing.T) {

Callers

nothing calls this directly

Calls 14

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

Tested by

no test coverage detected