MCPcopy
hub / github.com/tsenart/vegeta / TestProxyOption

Function TestProxyOption

lib/attack_test.go:237–266  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

235}
236
237func 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
268func TestMaxBody(t *testing.T) {
269 t.Parallel()

Callers

nothing calls this directly

Calls 7

hitMethod · 0.95
NewAttackerFunction · 0.85
ProxyFunction · 0.85
NewStaticTargeterFunction · 0.85
WriteMethod · 0.80
CloseMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected