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

Function TestRequestDo

rest/request_test.go:1191–1225  ·  rest/request_test.go::TestRequestDo
(t *testing.T)

Source from the content-addressed store, hash-verified

1189}
1190
1191func TestRequestDo(t *testing.T) {
1192 testCases := []struct {
1193 Request *Request
1194 Err bool
1195 }{
1196 {
1197 Request: &Request{err: errors.New("bail")},
1198 Err: true,
1199 },
1200 {
1201 Request: &Request{baseURL: &url.URL{}, pathPrefix: "%"},
1202 Err: true,
1203 },
1204 {
1205 Request: &Request{
1206 client: clientFunc(func(req *http.Request) (*http.Response, error) {
1207 return nil, errors.New("err")
1208 }),
1209 baseURL: &url.URL{},
1210 },
1211 Err: true,
1212 },
1213 }
1214 for i, testCase := range testCases {
1215 testCase.Request.backoffMgr = &NoBackoff{}
1216 body, err := testCase.Request.Do().Raw()
1217 hasErr := err != nil
1218 if hasErr != testCase.Err {
1219 t.Errorf("%d: expected %t, got %t: %v", i, testCase.Err, hasErr, err)
1220 }
1221 if hasErr && body != nil {
1222 t.Errorf("%d: body should be nil when error is returned", i)
1223 }
1224 }
1225}
1226
1227func TestDoRequestNewWay(t *testing.T) {
1228 reqBody := "request body"

Callers

nothing calls this directly

Calls 4

clientFuncFuncType · 0.85
RawMethod · 0.80
DoMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected