(t *testing.T)
| 19 | var testDbPath = "./test_db/ip_dns.db" |
| 20 | |
| 21 | func TestResultCount(t *testing.T) { |
| 22 | log.SetOutput(&bytes.Buffer{}) |
| 23 | |
| 24 | reqString := "github.com\none.one.one.one\ngoogle-public-dns-a.google.com" |
| 25 | |
| 26 | req := httptest.NewRequest("POST", |
| 27 | "http://example.org/query", |
| 28 | strings.NewReader(reqString)) |
| 29 | w := httptest.NewRecorder() |
| 30 | queryHandler, err := initQueryHandler(testDbPath, "SELECT * FROM ip_dns WHERE dns = ?", 0) |
| 31 | if err != nil { |
| 32 | t.Fatal(err) |
| 33 | } |
| 34 | queryHandler(w, req) |
| 35 | |
| 36 | resp := w.Result() |
| 37 | defer resp.Body.Close() |
| 38 | |
| 39 | if resp.StatusCode != http.StatusOK { |
| 40 | t.Fatalf(`resp.StatusCode (%d) != http.StatusOK (%d)`, resp.StatusCode, http.StatusOK) |
| 41 | } |
| 42 | |
| 43 | if resp.Header.Get("Content-Type") != "application/json" { |
| 44 | t.Fatalf(`resp.Header.Get("Content-Type") (%s) != "application/json"`, resp.Header.Get("Content-Type")) |
| 45 | } |
| 46 | |
| 47 | var answer []interface{} |
| 48 | decoder := json.NewDecoder(resp.Body) |
| 49 | err = decoder.Decode(&answer) |
| 50 | if err != nil { |
| 51 | t.Fatal(err) |
| 52 | } |
| 53 | |
| 54 | if len(answer) != 3 { |
| 55 | t.Fatal(`len(answer) != 3`) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | func TestAnswersOrder(t *testing.T) { |
| 60 | log.SetOutput(&bytes.Buffer{}) |
nothing calls this directly
no test coverage detected