(t *testing.T)
| 16 | } |
| 17 | |
| 18 | func 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 | |
| 44 | func sendJSON(t *testing.T, v interface{}) http.HandlerFunc { |
| 45 | return func(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…