(t *testing.T)
| 253 | } |
| 254 | |
| 255 | func TestZeroParams(t *testing.T) { |
| 256 | log.SetOutput(&bytes.Buffer{}) |
| 257 | |
| 258 | req := httptest.NewRequest("GET", |
| 259 | "http://example.org/query", |
| 260 | nil) |
| 261 | w := httptest.NewRecorder() |
| 262 | queryHandler, err := initQueryHandler(testDbPath, "SELECT * FROM ip_dns", 0) |
| 263 | if err != nil { |
| 264 | t.Fatal(err) |
| 265 | } |
| 266 | queryHandler(w, req) |
| 267 | |
| 268 | resp := w.Result() |
| 269 | defer resp.Body.Close() |
| 270 | |
| 271 | if resp.StatusCode != http.StatusOK { |
| 272 | t.Fatalf(`resp.StatusCode (%d) != http.StatusOK (%d)`, resp.StatusCode, http.StatusOK) |
| 273 | } |
| 274 | |
| 275 | if resp.Header.Get("Content-Type") != "application/json" { |
| 276 | t.Fatalf(`resp.Header.Get("Content-Type") (%s) != "application/json"`, resp.Header.Get("Content-Type")) |
| 277 | } |
| 278 | |
| 279 | var answer []queryResult |
| 280 | decoder := json.NewDecoder(resp.Body) |
| 281 | err = decoder.Decode(&answer) |
| 282 | if err != nil { |
| 283 | t.Fatal(err) |
| 284 | } |
| 285 | |
| 286 | expectedResponse := []queryResult{ |
| 287 | queryResult{ |
| 288 | Out: [][]interface{}{ |
| 289 | []interface{}{"1.1.1.1", "one.one.one.one"}, |
| 290 | []interface{}{"8.8.8.8", "google-public-dns-a.google.com"}, |
| 291 | []interface{}{"192.30.253.112", "github.com"}, |
| 292 | []interface{}{"192.30.253.113", "github.com"}, |
| 293 | }}, |
| 294 | } |
| 295 | |
| 296 | compare(t, answer, expectedResponse) |
| 297 | } |
| 298 | |
| 299 | func compare(t *testing.T, answer []queryResult, expectedResponse []queryResult) { |
| 300 | for i, v := range expectedResponse { |
nothing calls this directly
no test coverage detected