(t *testing.T)
| 285 | } |
| 286 | |
| 287 | func 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 | |
| 320 | func TestFetchDisallowed(t *testing.T) { |
| 321 | // Start 2 test servers |
nothing calls this directly
no test coverage detected