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

Function TestBadBodySendRequest

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

Source from the content-addressed store, hash-verified

400}
401
402func TestBadBodySendRequest(t *testing.T) {
403 log.SetOutput(&bytes.Buffer{})
404
405 var reqBody errReader
406
407 req := httptest.NewRequest("POST",
408 "http://example.org/query",
409 reqBody)
410
411 w := httptest.NewRecorder()
412 queryHandler, err := initQueryHandler(testDbPath, "SELECT * FROM ip_dns WHERE dns = ?", 0)
413 if err != nil {
414 t.Fatal(err)
415 }
416 queryHandler(w, req)
417
418 resp := w.Result()
419 defer resp.Body.Close()
420
421 if resp.StatusCode != http.StatusInternalServerError {
422 t.Fatalf(`resp.StatusCode (%d) != http.StatusInternalServerError (%d)`, resp.StatusCode, http.StatusInternalServerError)
423 }
424
425 respBytes, err := ioutil.ReadAll(resp.Body)
426 if err != nil {
427 t.Fatal(err)
428 }
429 respString := string(respBytes)
430
431 if !strings.Contains(respString, "Error reading request body: test error") {
432 t.Fatal(`Error string should contain "Error reading request body: test error"`)
433 }
434}
435
436func TestMainDbFileNotThere(t *testing.T) {
437 err := cmd([]string{

Callers

nothing calls this directly

Calls 1

initQueryHandlerFunction · 0.85

Tested by

no test coverage detected