| 100 | } |
| 101 | |
| 102 | func TestError(t *testing.T) { |
| 103 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 104 | w.WriteHeader(http.StatusInternalServerError) |
| 105 | w.Write([]byte("500 - error")) |
| 106 | })) |
| 107 | defer ts.Close() |
| 108 | |
| 109 | payload := map[string]interface{}{ |
| 110 | "method": "GET", |
| 111 | "url": ts.URL, |
| 112 | } |
| 113 | response, err := New().Send(context.Background(), payload) |
| 114 | expected := map[string]interface{}{ |
| 115 | "status": 500, |
| 116 | } |
| 117 | if err == nil || err.Error() != "non 200 status" { |
| 118 | log.Fatalf("Unexpected error: %v", err) |
| 119 | } |
| 120 | if !reflect.DeepEqual(response, expected) { |
| 121 | t.Fatalf("Unexpected: %#v", response) |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | func TestErrorDecodingPayload(t *testing.T) { |
| 126 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) |