MCPcopy
hub / github.com/OJ/gobuster / TestRequest

Function TestRequest

libgobuster/http_test.go:49–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

47}
48
49func TestRequest(t *testing.T) {
50 t.Parallel()
51 ret, err := randomString(100)
52 if err != nil {
53 t.Fatal(err)
54 }
55 h := httpServerT(t, ret)
56 defer h.Close()
57 var o HTTPOptions
58 log := NewLogger(false)
59 c, err := NewHTTPClient(&o, log)
60 if err != nil {
61 t.Fatalf("Got Error: %v", err)
62 }
63 u, err := url.Parse(h.URL)
64 if err != nil {
65 t.Fatalf("could not parse URL %v: %v", h.URL, err)
66 }
67 status, length, _, body, err := c.Request(t.Context(), *u, RequestOptions{ReturnBody: true})
68 if err != nil {
69 t.Fatalf("Got Error: %v", err)
70 }
71 if status != 200 {
72 t.Fatalf("Invalid status returned: %d", status)
73 }
74 if length != int64(len(ret)) {
75 t.Fatalf("Invalid length returned: %d", length)
76 }
77 if body == nil || !bytes.Equal(body, []byte(ret)) {
78 t.Fatalf("Invalid body returned: %d", body)
79 }
80}
81
82func BenchmarkRequestWithoutBody(b *testing.B) {
83 r, err := randomString(10000)

Callers

nothing calls this directly

Calls 7

RequestMethod · 0.95
randomStringFunction · 0.85
httpServerTFunction · 0.85
NewLoggerFunction · 0.85
NewHTTPClientFunction · 0.85
FatalMethod · 0.80
FatalfMethod · 0.80

Tested by

no test coverage detected