|
|
|
|
@ -258,6 +258,12 @@ func TestClientDoWithBody(t *testing.T) {
|
|
|
|
|
if r.Method != "POST" {
|
|
|
|
|
t.Fatalf("expected POST, got %s", r.Method)
|
|
|
|
|
}
|
|
|
|
|
if got := r.Header.Get("Accept"); got != "application/json" {
|
|
|
|
|
t.Fatalf("Accept = %q, want application/json", got)
|
|
|
|
|
}
|
|
|
|
|
if got := r.Header.Get("Content-Type"); got != "application/json" {
|
|
|
|
|
t.Fatalf("Content-Type = %q, want application/json", got)
|
|
|
|
|
}
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
w.Write([]byte(`{"id":123}`))
|
|
|
|
|
}))
|
|
|
|
|
@ -273,6 +279,25 @@ func TestClientDoWithBody(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestClientDoWithoutBodySetsAcceptOnly(t *testing.T) {
|
|
|
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
if got := r.Header.Get("Accept"); got != "application/json" {
|
|
|
|
|
t.Fatalf("Accept = %q, want application/json", got)
|
|
|
|
|
}
|
|
|
|
|
if got := r.Header.Get("Content-Type"); got != "" {
|
|
|
|
|
t.Fatalf("Content-Type = %q, want empty", got)
|
|
|
|
|
}
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
w.Write([]byte(`{}`))
|
|
|
|
|
}))
|
|
|
|
|
defer server.Close()
|
|
|
|
|
|
|
|
|
|
c := &Client{HTTP: server.Client(), BaseURL: server.URL}
|
|
|
|
|
if _, err := c.Do("GET", "/api/test", nil, nil); err != nil {
|
|
|
|
|
t.Fatalf("unexpected error: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestClientGet(t *testing.T) {
|
|
|
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
if r.Method != "GET" {
|
|
|
|
|
|