(t *testing.T)
| 400 | } |
| 401 | |
| 402 | func TestBadBodySendRequest(t *testing.T) { |
| 403 | log.SetOutput(&bytes.Buffer{}) |
| 404 | |
| 405 | var reqBody errReader |
| 406 | |
| 407 | req := httptest.NewRequest("POST", |
| 408 | "http://example.org/query", |
| 409 | reqBody) |
| 410 | |
| 411 | w := httptest.NewRecorder() |
| 412 | queryHandler, err := initQueryHandler(testDbPath, "SELECT * FROM ip_dns WHERE dns = ?", 0) |
| 413 | if err != nil { |
| 414 | t.Fatal(err) |
| 415 | } |
| 416 | queryHandler(w, req) |
| 417 | |
| 418 | resp := w.Result() |
| 419 | defer resp.Body.Close() |
| 420 | |
| 421 | if resp.StatusCode != http.StatusInternalServerError { |
| 422 | t.Fatalf(`resp.StatusCode (%d) != http.StatusInternalServerError (%d)`, resp.StatusCode, http.StatusInternalServerError) |
| 423 | } |
| 424 | |
| 425 | respBytes, err := ioutil.ReadAll(resp.Body) |
| 426 | if err != nil { |
| 427 | t.Fatal(err) |
| 428 | } |
| 429 | respString := string(respBytes) |
| 430 | |
| 431 | if !strings.Contains(respString, "Error reading request body: test error") { |
| 432 | t.Fatal(`Error string should contain "Error reading request body: test error"`) |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | func TestMainDbFileNotThere(t *testing.T) { |
| 437 | err := cmd([]string{ |
nothing calls this directly
no test coverage detected