我能夠成功模擬查詢以從一張表中進行選擇,如下所示:sqlMock.ExpectQuery("^SELECT DISTINCT (.+) FROM myTable1, myTable2"). WillReturnRows(myResultRows)但我無法模擬以下查詢來檢查我的 postgres 數(shù)據(jù)庫中是否存在該表:SELECT EXISTS ( SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'myTable3' );組合: existsRows := sqlmock.NewRows([]string{"exists"}). AddRow(true)和 slMock.ExpectQuery("^SELECT EXISTS"). WillReturnRows(existsRows)我SELECT 1也嘗試過嘲笑,但得到了完全相同的錯誤:time="2019-09-27T15:49:41-07:00" level=panic msg="db query" error="call to Query 'SELECT EXISTS\n\t\t( SELECT 1\n\t\tFROM information_schema.tables\n\t\tWHERE table_schema = 'public'\n\t\t AND table_name = 'myTable3' );' with args [], was not expected, next expectation is: ExpectedExec => expecting Exec or ExecContext which......我正在使用的包:import ( "database/sql" "db" "os" "testing" // not explicitly called _ "github.com/denisenkom/go-mssqldb" _ "github.com/lib/pq" "github.com/DATA-DOG/go-sqlmock" "github.com/sirupsen/logrus")任何想法或指示表示贊賞。我在網上找不到相關的例子
對于復合 SQL 查詢,go-sqlmock 中不需要使用 args [] 調用查詢
慕碼人2483693
2023-07-26 17:15:29