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

Function TestCountParamsHandleDBError

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

Source from the content-addressed store, hash-verified

589}
590
591func TestCountParamsHandleDBError(t *testing.T) {
592 db, err := sql.Open("sqlite3", fmt.Sprintf("file:%s?mode=rw&cache=shared&_journal_mode=WAL", testDbPath))
593 if err != nil {
594 t.Fatalf("Should open testDbPath (%s) just fine", testDbPath)
595 }
596
597 db.SetMaxOpenConns(1)
598
599 queryStmt, err := db.Prepare("select * from ip_dns")
600 if err != nil {
601 t.Fatal("Should prepare query just fine")
602 }
603
604 db.Close()
605
606 count, err := countParams(queryStmt)
607 if count != -1 {
608 t.Fatal("Count should equal -1")
609 }
610 if err == nil || !strings.Contains(err.Error(), "Cannot extract params count from query error") {
611 t.Fatalf(`Should throw a 'syntax error' error: %v`, err)
612 }
613}

Callers

nothing calls this directly

Calls 1

countParamsFunction · 0.85

Tested by

no test coverage detected