(t *testing.T)
| 235 | } |
| 236 | |
| 237 | func TestProxyOption(t *testing.T) { |
| 238 | t.Parallel() |
| 239 | |
| 240 | body := []byte("PROXIED!") |
| 241 | server := httptest.NewServer( |
| 242 | http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 243 | w.Write(body) |
| 244 | }), |
| 245 | ) |
| 246 | defer server.Close() |
| 247 | |
| 248 | proxyURL, err := url.Parse(server.URL) |
| 249 | if err != nil { |
| 250 | t.Fatal(err) |
| 251 | } |
| 252 | |
| 253 | atk := NewAttacker(Proxy(func(r *http.Request) (*url.URL, error) { |
| 254 | return proxyURL, nil |
| 255 | })) |
| 256 | |
| 257 | tr := NewStaticTargeter(Target{Method: "GET", URL: "http://127.0.0.2"}) |
| 258 | res := atk.hit(tr, &attack{name: "", began: time.Now()}) |
| 259 | if got, want := res.Error, ""; got != want { |
| 260 | t.Errorf("got error: %q, want %q", got, want) |
| 261 | } |
| 262 | |
| 263 | if got, want := res.Body, body; !bytes.Equal(got, want) { |
| 264 | t.Errorf("got body: %q, want: %q", got, want) |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | func TestMaxBody(t *testing.T) { |
| 269 | t.Parallel() |
nothing calls this directly
no test coverage detected