MCPcopy Create free account
hub / github.com/PuerkitoBio/fetchbot / TestSendVariadic

Function TestSendVariadic

fetch_test.go:218–251  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

216}
217
218func TestSendVariadic(t *testing.T) {
219 // Start a test server
220 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
221 w.Write([]byte("ok"))
222 }))
223 defer srv.Close()
224
225 // Define the raw URLs to enqueue
226 cases := []string{srv.URL + "/a", srv.URL + "/b", "/nohost", ":"}
227 handled := cases[:len(cases)-2]
228
229 // Start the Fetcher
230 sh := &spyHandler{}
231 f := New(sh)
232 f.CrawlDelay = 0
233 q := f.Start()
234 n, err := q.SendStringGet(cases...)
235 if n != 2 {
236 t.Errorf("expected %d URLs enqueued, got %d", 2, n)
237 }
238 if err != ErrEmptyHost {
239 t.Errorf("expected %v, got %v", ErrEmptyHost, err)
240 }
241 // Stop to wait for all commands to be processed
242 q.Close()
243 // Assert that the handler got called with the right values
244 if ok := sh.CalledWithExactly(handled...); !ok {
245 t.Error("expected handler to be called with valid cases")
246 }
247 // Expect no error
248 if cnt := sh.Errors(); cnt != 0 {
249 t.Errorf("expected no error, got %d", cnt)
250 }
251}
252
253func TestUserAgent(t *testing.T) {
254 // Start a test server

Callers

nothing calls this directly

Calls 6

CalledWithExactlyMethod · 0.95
ErrorsMethod · 0.95
NewFunction · 0.85
CloseMethod · 0.80
StartMethod · 0.80
SendStringGetMethod · 0.80

Tested by

no test coverage detected