MCPcopy
hub / github.com/rqlite/rqlite / Test_SwapSuccess

Function Test_SwapSuccess

db/swappable_db_test.go:58–95  ·  view source on GitHub ↗

Test_SwapSuccess tests that the Swap function successfully swaps the underlying database.

(t *testing.T)

Source from the content-addressed store, hash-verified

56
57// Test_SwapSuccess tests that the Swap function successfully swaps the underlying database.
58func Test_SwapSuccess(t *testing.T) {
59 // Create a new database with content
60 srcPath := mustTempPath()
61 defer os.Remove(srcPath)
62 srcDB, err := Open(srcPath, false, false)
63 if err != nil {
64 t.Fatalf("failed to open source database: %s", err)
65 }
66 defer srcDB.Close()
67 mustExecute(srcDB, "CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name TEXT)")
68 mustExecute(srcDB, `INSERT INTO foo(name) VALUES("test")`)
69
70 // Create a SwappableDB with an empty database
71 swappablePath := mustTempPath()
72 defer os.Remove(swappablePath)
73 swappableDB, err := OpenSwappable(swappablePath, nil, false, false, 0)
74 if err != nil {
75 t.Fatalf("failed to open swappable database: %s", err)
76 }
77 defer swappableDB.Close()
78
79 // Perform the swap
80 if err := srcDB.Close(); err != nil {
81 t.Fatalf("failed to close source database pre-swap: %s", err)
82 }
83 if err := swappableDB.Swap(srcPath, false, false); err != nil {
84 t.Fatalf("failed to swap database: %s", err)
85 }
86
87 // Confirm the SwappableDB contains the data from the source database
88 rows, err := swappableDB.QueryStringStmt("SELECT * FROM foo")
89 if err != nil {
90 t.Fatalf("failed to query swapped database: %s", err)
91 }
92 if exp, got := `[{"columns":["id","name"],"types":["integer","text"],"values":[[1,"test"]]}]`, asJSON(rows); exp != got {
93 t.Fatalf("unexpected results after swap, expected %s, got %s", exp, got)
94 }
95}
96
97func Test_SwapSuccess_Driver(t *testing.T) {
98 // Create a new database and confirm foreign key support is enabled

Callers

nothing calls this directly

Calls 9

mustTempPathFunction · 0.85
OpenFunction · 0.85
OpenSwappableFunction · 0.85
mustExecuteFunction · 0.70
asJSONFunction · 0.70
RemoveMethod · 0.65
CloseMethod · 0.65
SwapMethod · 0.45
QueryStringStmtMethod · 0.45

Tested by

no test coverage detected