MCPcopy
hub / github.com/go-kit/kit / TestSetClient

Function TestSetClient

transport/http/client_test.go:265–300  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

263}
264
265func TestSetClient(t *testing.T) {
266 var (
267 encode = func(context.Context, *http.Request, interface{}) error { return nil }
268 decode = func(_ context.Context, r *http.Response) (interface{}, error) {
269 t, err := ioutil.ReadAll(r.Body)
270 if err != nil {
271 return nil, err
272 }
273 return string(t), nil
274 }
275 )
276
277 testHttpClient := httpClientFunc(func(req *http.Request) (*http.Response, error) {
278 return &http.Response{
279 StatusCode: http.StatusOK,
280 Request: req,
281 Body: ioutil.NopCloser(bytes.NewBufferString("hello, world!")),
282 }, nil
283 })
284
285 client := httptransport.NewClient(
286 "GET",
287 &url.URL{},
288 encode,
289 decode,
290 httptransport.SetClient(testHttpClient),
291 ).Endpoint()
292
293 resp, err := client(context.Background(), nil)
294 if err != nil {
295 t.Fatal(err)
296 }
297 if r, ok := resp.(string); !ok || r != "hello, world!" {
298 t.Fatal("Expected response to be 'hello, world!' string")
299 }
300}
301
302func TestNewExplicitClient(t *testing.T) {
303 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 3

httpClientFuncFuncType · 0.85
EndpointMethod · 0.65
clientStruct · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…