(t *testing.T)
| 204 | } |
| 205 | |
| 206 | func TestMoreThanOneParam(t *testing.T) { |
| 207 | log.SetOutput(&bytes.Buffer{}) |
| 208 | |
| 209 | reqString := "github.com,192.30.253.112\none.one.one.one,1.1.1.1" |
| 210 | |
| 211 | req := httptest.NewRequest("POST", |
| 212 | "http://example.org/query", |
| 213 | strings.NewReader(reqString)) |
| 214 | w := httptest.NewRecorder() |
| 215 | queryHandler, err := initQueryHandler(testDbPath, |
| 216 | "SELECT * FROM ip_dns WHERE dns = ? AND ip = ?", |
| 217 | 0) |
| 218 | if err != nil { |
| 219 | t.Fatal(err) |
| 220 | } |
| 221 | queryHandler(w, req) |
| 222 | |
| 223 | resp := w.Result() |
| 224 | defer resp.Body.Close() |
| 225 | |
| 226 | if resp.StatusCode != http.StatusOK { |
| 227 | t.Fatalf(`resp.StatusCode (%d) != http.StatusOK (%d)`, resp.StatusCode, http.StatusOK) |
| 228 | } |
| 229 | |
| 230 | if resp.Header.Get("Content-Type") != "application/json" { |
| 231 | t.Fatalf(`resp.Header.Get("Content-Type") (%s) != "application/json"`, resp.Header.Get("Content-Type")) |
| 232 | } |
| 233 | |
| 234 | var fullResponse []queryResult |
| 235 | decoder := json.NewDecoder(resp.Body) |
| 236 | err = decoder.Decode(&fullResponse) |
| 237 | if err != nil { |
| 238 | t.Fatal(err) |
| 239 | } |
| 240 | |
| 241 | expectedResponse := []queryResult{ |
| 242 | queryResult{ |
| 243 | Out: [][]interface{}{ |
| 244 | []interface{}{"192.30.253.112", "github.com"}, |
| 245 | }}, |
| 246 | queryResult{ |
| 247 | Out: [][]interface{}{ |
| 248 | []interface{}{"1.1.1.1", "one.one.one.one"}, |
| 249 | }}, |
| 250 | } |
| 251 | |
| 252 | compare(t, fullResponse, expectedResponse) |
| 253 | } |
| 254 | |
| 255 | func TestZeroParams(t *testing.T) { |
| 256 | log.SetOutput(&bytes.Buffer{}) |
nothing calls this directly
no test coverage detected