Add another preupdate hook unit test

This commit is contained in:
Philip O'Toole
2025-04-03 13:17:58 -04:00
parent 7d4f759563
commit 668e4ec445

View File

@@ -413,6 +413,33 @@ func Test_Preupdate_Multi(t *testing.T) {
wg.Wait()
}
// Test_Preupdate_Tx demostrates that the preupdate hook is called for
// transactions which is rolled back.
func Test_Preupdate_Tx(t *testing.T) {
path := mustTempPath()
defer os.Remove(path)
db, err := Open(path, false, false)
if err != nil {
t.Fatalf("error opening database")
}
defer db.Close()
mustExecute(db, "CREATE TABLE foo (id INTEGER PRIMARY KEY, name TEXT)")
var wg sync.WaitGroup
hook := func(got *command.CDCEvent) error {
defer wg.Done()
return nil
}
if err := db.RegisterPreUpdateHook(hook, false); err != nil {
t.Fatalf("error registering preupdate hook")
}
wg.Add(1)
mustExecute(db, "BEGIN")
mustExecute(db, "INSERT INTO foo(id, name) VALUES(1, 'fiona')")
mustExecute(db, "ROLLBACK")
wg.Wait()
}
func compareEvents(t *testing.T, exp, got *command.CDCEvent) {
t.Helper()
if exp, got := exp.Table, got.Table; exp != got {