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

Function TestSendString

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

Source from the content-addressed store, hash-verified

285}
286
287func TestSendString(t *testing.T) {
288 // Start a test server
289 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
290 w.Write([]byte("ok"))
291 }))
292 defer srv.Close()
293
294 // Define the raw URLs to enqueue
295 cases := []string{srv.URL + "/a", srv.URL + "/b", srv.URL + "/c"}
296
297 // Start the Fetcher
298 sh := &spyHandler{}
299 f := New(sh)
300 f.CrawlDelay = 0
301 q := f.Start()
302 for _, c := range cases {
303 _, err := q.SendString("GET", c)
304 if err != nil {
305 t.Fatal(err)
306 }
307 }
308 // Stop to wait for all commands to be processed
309 q.Close()
310 // Assert that the handler got called with the right values
311 if ok := sh.CalledWithExactly(cases...); !ok {
312 t.Error("expected handler to be called with all cases")
313 }
314 // Assert that there was no error
315 if cnt := sh.Errors(); cnt > 0 {
316 t.Errorf("expected no errors, got %d", cnt)
317 }
318}
319
320func TestFetchDisallowed(t *testing.T) {
321 // Start 2 test servers

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected