mirror of https://github.com/VinGarcia/ksql.git
Improve code coverage for .Transaction()
parent
a8dcbd1aaa
commit
25e77f3f36
|
@ -12,6 +12,20 @@ func (b mockTxBeginner) BeginTx(ctx context.Context) (Tx, error) {
|
||||||
return b.BeginTxFn(ctx)
|
return b.BeginTxFn(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mockDBAdapter mocks the ksql.DBAdapter interface
|
||||||
|
type mockDBAdapter struct {
|
||||||
|
ExecContextFn func(ctx context.Context, query string, args ...interface{}) (Result, error)
|
||||||
|
QueryContextFn func(ctx context.Context, query string, args ...interface{}) (Rows, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m mockDBAdapter) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error) {
|
||||||
|
return m.ExecContextFn(ctx, query, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m mockDBAdapter) QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error) {
|
||||||
|
return m.QueryContextFn(ctx, query, args...)
|
||||||
|
}
|
||||||
|
|
||||||
// mockTx mocks the ksql.Tx interface
|
// mockTx mocks the ksql.Tx interface
|
||||||
type mockTx struct {
|
type mockTx struct {
|
||||||
DBAdapter
|
DBAdapter
|
||||||
|
|
|
@ -2370,6 +2370,26 @@ func TransactionTest(
|
||||||
})
|
})
|
||||||
tt.AssertErrContains(t, err, "KSQL", "fakeErrMsg")
|
tt.AssertErrContains(t, err, "KSQL", "fakeErrMsg")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("should report error if DBAdapter can't create transactions", func(t *testing.T) {
|
||||||
|
err := createTables(driver, connStr)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("could not create test table!, reason:", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
db, closer := newDBAdapter(t)
|
||||||
|
defer closer.Close()
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
c := newTestDB(db, driver)
|
||||||
|
|
||||||
|
c.db = mockDBAdapter{}
|
||||||
|
|
||||||
|
err = c.Transaction(ctx, func(db Provider) error {
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
tt.AssertErrContains(t, err, "KSQL", "can't start transaction", "DBAdapter", "TxBeginner")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue