MCPcopy Create free account
hub / github.com/bytebase/bytebase / TestTransactionMode

Function TestTransactionMode

backend/tests/transaction_mode_test.go:18–193  ·  view source on GitHub ↗

TestTransactionMode tests the configurable transaction mode feature across different database engines.

(t *testing.T)

Source from the content-addressed store, hash-verified

16
17// TestTransactionMode tests the configurable transaction mode feature across different database engines.
18func TestTransactionMode(t *testing.T) {
19 ctx := context.Background()
20
21 tests := []struct {
22 name string
23 dbType storepb.Engine
24 containerFunc func(context.Context, *testing.T) *testcontainer.Container
25 setupScript string
26 testScriptOn string
27 testScriptOff string
28 expectRollbackOn bool // Whether we expect rollback for transaction mode on
29 skipTransaction bool // Some engines don't support transactions well
30 }{
31 {
32 name: "MySQL",
33 dbType: storepb.Engine_MYSQL,
34 containerFunc: func(ctx context.Context, t *testing.T) *testcontainer.Container {
35 container, err := testcontainer.GetTestMySQLContainer(ctx)
36 if err != nil {
37 t.Fatalf("Failed to get MySQL container: %v", err)
38 }
39 return container
40 },
41 setupScript: `
42 CREATE TABLE test_table (
43 id INT PRIMARY KEY,
44 value VARCHAR(100)
45 );
46 `,
47 testScriptOn: `-- txn-mode = on
48 INSERT INTO test_table (id, value) VALUES (1, 'test1');
49 INSERT INTO test_table (id, value) VALUES (2, 'test2');
50 INSERT INTO test_table (id, value) VALUES (1, 'duplicate'); -- This will fail
51 `,
52 testScriptOff: `-- txn-mode = off
53 INSERT INTO test_table (id, value) VALUES (1, 'test1');
54 INSERT INTO test_table (id, value) VALUES (2, 'test2');
55 INSERT INTO test_table (id, value) VALUES (1, 'duplicate'); -- This will fail
56 `,
57 expectRollbackOn: true,
58 },
59 {
60 name: "PostgreSQL",
61 dbType: storepb.Engine_POSTGRES,
62 containerFunc: func(ctx context.Context, t *testing.T) *testcontainer.Container {
63 return testcontainer.GetTestPgContainer(ctx, t)
64 },
65 setupScript: `
66 CREATE TABLE test_table (
67 id INTEGER PRIMARY KEY,
68 value VARCHAR(100)
69 );
70 `,
71 testScriptOn: `-- txn-mode = on
72 INSERT INTO test_table (id, value) VALUES (1, 'test1');
73 INSERT INTO test_table (id, value) VALUES (2, 'test2');
74 INSERT INTO test_table (id, value) VALUES (1, 'duplicate'); -- This will fail
75 `,

Callers

nothing calls this directly

Calls 14

GetTestMySQLContainerFunction · 0.92
GetTestPgContainerFunction · 0.92
GetTestOracleContainerFunction · 0.92
GetTestMSSQLContainerFunction · 0.92
getDriverFunction · 0.85
getRowCountFunction · 0.85
cleanupTableFunction · 0.85
FatalfMethod · 0.80
CloseMethod · 0.65
GetDBMethod · 0.65
ExecuteMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected