| 37 | } |
| 38 | |
| 39 | func TestPost(t *testing.T) { |
| 40 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 41 | if r.Method != "POST" { |
| 42 | t.Errorf("Unexpected method: %s", r.Method) |
| 43 | } |
| 44 | b, err := ioutil.ReadAll(r.Body) |
| 45 | if err != nil { |
| 46 | t.Error(err) |
| 47 | } |
| 48 | if string(b) != "abc" { |
| 49 | t.Errorf("Unexpected body: %s", string(b)) |
| 50 | } |
| 51 | })) |
| 52 | defer ts.Close() |
| 53 | |
| 54 | payload := map[string]interface{}{ |
| 55 | "method": "POST", |
| 56 | "url": ts.URL, |
| 57 | "body": "abc", |
| 58 | } |
| 59 | response, err := New().Send(context.Background(), payload) |
| 60 | expected := map[string]interface{}{ |
| 61 | "status": 200, |
| 62 | } |
| 63 | if err != nil { |
| 64 | log.Fatal(err) |
| 65 | } |
| 66 | if !reflect.DeepEqual(response, expected) { |
| 67 | t.Fatalf("Unexpected: %#v", response) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | func TestHeaders(t *testing.T) { |
| 72 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |