MCPcopy Index your code
hub / github.com/kataras/iris / TestClientJSON

Function TestClientJSON

x/client/client_test.go:18–42  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16}
17
18func TestClientJSON(t *testing.T) {
19 expectedJSON := testValue{Firstname: "Makis"}
20
21 app := http.NewServeMux()
22 app.HandleFunc("/send", sendJSON(t, expectedJSON))
23
24 var irisGotJSON testValue
25 app.HandleFunc("/read", readJSON(t, &irisGotJSON, &expectedJSON))
26
27 srv := httptest.NewServer(app)
28 client := New(BaseURL(srv.URL))
29
30 // Test ReadJSON (read from server).
31 var got testValue
32 if err := client.ReadJSON(defaultCtx, &got, http.MethodGet, "/send", nil); err != nil {
33 t.Fatal(err)
34 }
35
36 // Test JSON (send to server).
37 resp, err := client.JSON(defaultCtx, http.MethodPost, "/read", expectedJSON)
38 if err != nil {
39 t.Fatal(err)
40 }
41 client.DrainResponseBody(resp)
42}
43
44func sendJSON(t *testing.T, v interface{}) http.HandlerFunc {
45 return func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 9

readJSONFunction · 0.85
BaseURLFunction · 0.85
FatalMethod · 0.80
DrainResponseBodyMethod · 0.80
sendJSONFunction · 0.70
NewFunction · 0.70
HandleFuncMethod · 0.65
ReadJSONMethod · 0.45
JSONMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…