(t *testing.T)
| 103 | } |
| 104 | |
| 105 | func TestAnswersHeaders(t *testing.T) { |
| 106 | log.SetOutput(&bytes.Buffer{}) |
| 107 | |
| 108 | reqString := "github.com\none.one.one.one\ngoogle-public-dns-a.google.com" |
| 109 | |
| 110 | req := httptest.NewRequest("POST", |
| 111 | "http://example.org/query", |
| 112 | strings.NewReader(reqString)) |
| 113 | w := httptest.NewRecorder() |
| 114 | queryHandler, err := initQueryHandler(testDbPath, "SELECT * FROM ip_dns WHERE dns = ?", 0) |
| 115 | if err != nil { |
| 116 | t.Fatal(err) |
| 117 | } |
| 118 | queryHandler(w, req) |
| 119 | |
| 120 | resp := w.Result() |
| 121 | defer resp.Body.Close() |
| 122 | |
| 123 | if resp.StatusCode != http.StatusOK { |
| 124 | t.Fatalf(`resp.StatusCode (%d) != http.StatusOK (%d)`, resp.StatusCode, http.StatusOK) |
| 125 | } |
| 126 | |
| 127 | if resp.Header.Get("Content-Type") != "application/json" { |
| 128 | t.Fatalf(`resp.Header.Get("Content-Type") (%s) != "application/json"`, resp.Header.Get("Content-Type")) |
| 129 | } |
| 130 | |
| 131 | var fullResponse []queryResult |
| 132 | decoder := json.NewDecoder(resp.Body) |
| 133 | err = decoder.Decode(&fullResponse) |
| 134 | if err != nil { |
| 135 | t.Fatal(err) |
| 136 | } |
| 137 | |
| 138 | for i := 0; i < 3; i++ { |
| 139 | if len(fullResponse[i].Headers) != 2 { |
| 140 | t.Fatalf(`len(answer[%d].Headers) != 2`, i) |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | for i := 0; i < 3; i++ { |
| 145 | if fullResponse[i].Headers[0] != "ip" { |
| 146 | t.Fatalf(`answer[%d].In[0] != "ip"`, i) |
| 147 | } |
| 148 | if fullResponse[i].Headers[1] != "dns" { |
| 149 | t.Fatalf(`answer[%d].In[1] != "dns"`, i) |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | func TestAnswersRows(t *testing.T) { |
| 155 | log.SetOutput(&bytes.Buffer{}) |
nothing calls this directly
no test coverage detected