(t *testing.T)
| 57 | } |
| 58 | |
| 59 | func TestAnswersOrder(t *testing.T) { |
| 60 | log.SetOutput(&bytes.Buffer{}) |
| 61 | |
| 62 | reqString := "github.com\none.one.one.one\ngoogle-public-dns-a.google.com" |
| 63 | |
| 64 | req := httptest.NewRequest("POST", |
| 65 | "http://example.org/query", |
| 66 | strings.NewReader(reqString)) |
| 67 | w := httptest.NewRecorder() |
| 68 | queryHandler, err := initQueryHandler(testDbPath, "SELECT * FROM ip_dns WHERE dns = ?", 0) |
| 69 | if err != nil { |
| 70 | t.Fatal(err) |
| 71 | } |
| 72 | queryHandler(w, req) |
| 73 | |
| 74 | resp := w.Result() |
| 75 | defer resp.Body.Close() |
| 76 | |
| 77 | if resp.StatusCode != http.StatusOK { |
| 78 | t.Fatalf(`resp.StatusCode (%d) != http.StatusOK (%d)`, resp.StatusCode, http.StatusOK) |
| 79 | } |
| 80 | |
| 81 | if resp.Header.Get("Content-Type") != "application/json" { |
| 82 | t.Fatalf(`resp.Header.Get("Content-Type") (%s) != "application/json"`, resp.Header.Get("Content-Type")) |
| 83 | } |
| 84 | |
| 85 | var fullResponse []queryResult |
| 86 | decoder := json.NewDecoder(resp.Body) |
| 87 | err = decoder.Decode(&fullResponse) |
| 88 | if err != nil { |
| 89 | t.Fatal(err) |
| 90 | } |
| 91 | |
| 92 | for i := 0; i < 3; i++ { |
| 93 | if len(fullResponse[i].In) != 1 { |
| 94 | t.Fatalf(`len(answer[%d].In) != 1`, i) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | for i, v := range []string{"github.com", "one.one.one.one", "google-public-dns-a.google.com"} { |
| 99 | if fullResponse[i].In[0] != v { |
| 100 | t.Fatalf(`answer[%d].In[0] != "%s"`, i, v) |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | func TestAnswersHeaders(t *testing.T) { |
| 106 | log.SetOutput(&bytes.Buffer{}) |
nothing calls this directly
no test coverage detected