MCPcopy Index your code
hub / github.com/assafmo/SQLiteQueryServer / TestBadParamsCount

Function TestBadParamsCount

main_test.go:319–350  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

317}
318
319func TestBadParamsCount(t *testing.T) {
320 log.SetOutput(&bytes.Buffer{})
321
322 reqString := "github.com,1"
323
324 req := httptest.NewRequest("POST",
325 "http://example.org/query",
326 strings.NewReader(reqString))
327 w := httptest.NewRecorder()
328 queryHandler, err := initQueryHandler(testDbPath, "SELECT * FROM ip_dns WHERE dns = ?", 0)
329 if err != nil {
330 t.Fatal(err)
331 }
332 queryHandler(w, req)
333
334 resp := w.Result()
335 defer resp.Body.Close()
336
337 if resp.StatusCode != http.StatusInternalServerError {
338 t.Fatalf(`resp.StatusCode (%d) != http.StatusInternalServerError (%d)`, resp.StatusCode, http.StatusInternalServerError)
339 }
340
341 respBytes, err := ioutil.ReadAll(resp.Body)
342 if err != nil {
343 t.Fatal(err)
344 }
345 respString := string(respBytes)
346
347 if !strings.Contains(respString, "sql: expected 1 arguments, got 2") {
348 t.Fatal(`Error string should contain "sql: expected 1 arguments, got 2"`)
349 }
350}
351
352func TestBadPathRequest(t *testing.T) {
353 log.SetOutput(&bytes.Buffer{})

Callers

nothing calls this directly

Calls 1

initQueryHandlerFunction · 0.85

Tested by

no test coverage detected