(t *testing.T, opts ...txExpect)
| 1237 | type txExpect func(mTx *dbmock.MockStore) |
| 1238 | |
| 1239 | func expectDB(t *testing.T, opts ...txExpect) *dbmock.MockStore { |
| 1240 | t.Helper() |
| 1241 | ctrl := gomock.NewController(t) |
| 1242 | mDB := dbmock.NewMockStore(ctrl) |
| 1243 | mTx := dbmock.NewMockStore(ctrl) |
| 1244 | |
| 1245 | // we expect to be run in a transaction; we use mTx to record the |
| 1246 | // "in transaction" calls. |
| 1247 | mDB.EXPECT().InTx( |
| 1248 | gomock.Any(), gomock.Eq(&database.TxOptions{Isolation: sql.LevelRepeatableRead}), |
| 1249 | ). |
| 1250 | DoAndReturn(func(f func(database.Store) error, _ *database.TxOptions) error { |
| 1251 | err := f(mTx) |
| 1252 | return err |
| 1253 | }) |
| 1254 | |
| 1255 | // txExpect args set up the expectations for what happens in the transaction. |
| 1256 | for _, o := range opts { |
| 1257 | o(mTx) |
| 1258 | } |
| 1259 | return mDB |
| 1260 | } |
| 1261 | |
| 1262 | func withTemplate(mTx *dbmock.MockStore) { |
| 1263 | mTx.EXPECT().GetTemplateByID(gomock.Any(), templateID). |
no test coverage detected