MCPcopy Index your code
hub / github.com/coder/coder / expectDB

Function expectDB

coderd/wsbuilder/wsbuilder_test.go:1239–1260  ·  view source on GitHub ↗
(t *testing.T, opts ...txExpect)

Source from the content-addressed store, hash-verified

1237type txExpect func(mTx *dbmock.MockStore)
1238
1239func 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
1262func withTemplate(mTx *dbmock.MockStore) {
1263 mTx.EXPECT().GetTemplateByID(gomock.Any(), templateID).

Calls 4

EXPECTMethod · 0.95
NewMockStoreFunction · 0.92
HelperMethod · 0.65
InTxMethod · 0.65

Tested by

no test coverage detected