(t *testing.T)
| 317 | } |
| 318 | |
| 319 | func TestBadParamsCount(t *testing.T) { |
| 320 | log.SetOutput(&bytes.Buffer{}) |
| 321 | |
| 322 | reqString := "github.com,1" |
| 323 | |
| 324 | req := httptest.NewRequest("POST", |
| 325 | "http://example.org/query", |
| 326 | strings.NewReader(reqString)) |
| 327 | w := httptest.NewRecorder() |
| 328 | queryHandler, err := initQueryHandler(testDbPath, "SELECT * FROM ip_dns WHERE dns = ?", 0) |
| 329 | if err != nil { |
| 330 | t.Fatal(err) |
| 331 | } |
| 332 | queryHandler(w, req) |
| 333 | |
| 334 | resp := w.Result() |
| 335 | defer resp.Body.Close() |
| 336 | |
| 337 | if resp.StatusCode != http.StatusInternalServerError { |
| 338 | t.Fatalf(`resp.StatusCode (%d) != http.StatusInternalServerError (%d)`, resp.StatusCode, http.StatusInternalServerError) |
| 339 | } |
| 340 | |
| 341 | respBytes, err := ioutil.ReadAll(resp.Body) |
| 342 | if err != nil { |
| 343 | t.Fatal(err) |
| 344 | } |
| 345 | respString := string(respBytes) |
| 346 | |
| 347 | if !strings.Contains(respString, "sql: expected 1 arguments, got 2") { |
| 348 | t.Fatal(`Error string should contain "sql: expected 1 arguments, got 2"`) |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | func TestBadPathRequest(t *testing.T) { |
| 353 | log.SetOutput(&bytes.Buffer{}) |
nothing calls this directly
no test coverage detected