(t *testing.T)
| 216 | } |
| 217 | |
| 218 | func 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 | |
| 253 | func TestUserAgent(t *testing.T) { |
| 254 | // Start a test server |
nothing calls this directly
no test coverage detected