MCPcopy
hub / github.com/rqlite/rqlite / Test_SingleNodeBackupBinaryVacuum

Function Test_SingleNodeBackupBinaryVacuum

store/store_vacuum_test.go:18–96  ·  view source on GitHub ↗

Test_SingleNodeBackupBinary tests that requesting a binary-formatted backup works as expected.

(t *testing.T)

Source from the content-addressed store, hash-verified

16// Test_SingleNodeBackupBinary tests that requesting a binary-formatted
17// backup works as expected.
18func Test_SingleNodeBackupBinaryVacuum(t *testing.T) {
19 s, ln := mustNewStore(t)
20 defer ln.Close()
21
22 if err := s.Open(); err != nil {
23 t.Fatalf("failed to open single-node store: %s", err.Error())
24 }
25 if err := s.Bootstrap(NewServer(s.ID(), s.Addr(), true)); err != nil {
26 t.Fatalf("failed to bootstrap single-node store: %s", err.Error())
27 }
28 defer s.Close(true)
29 if _, err := s.WaitForLeader(10 * time.Second); err != nil {
30 t.Fatalf("Error waiting for leader: %s", err)
31 }
32
33 dump := `PRAGMA foreign_keys=OFF;
34BEGIN TRANSACTION;
35CREATE TABLE foo (id integer not null primary key, name text);
36INSERT INTO "foo" VALUES(1,'fiona');
37COMMIT;
38`
39 _, _, err := s.Execute(context.Background(), executeRequestFromString(dump, false, false))
40 if err != nil {
41 t.Fatalf("failed to load simple dump: %s", err.Error())
42 }
43
44 checkDB := func(path string) {
45 t.Helper()
46 // Open the backup file using the DB layer and check the data.
47 dstDB, err := db.Open(path, false, false)
48 if err != nil {
49 t.Fatalf("unable to open backup database, %s", err.Error())
50 }
51 defer dstDB.Close()
52 qr := queryRequestFromString("SELECT * FROM foo", false, false, false)
53 qr.Level = proto.ConsistencyLevel_NONE
54 r, _, _, err := s.Query(context.Background(), qr)
55 if err != nil {
56 t.Fatalf("failed to query single node: %s", err.Error())
57 }
58 if exp, got := `[{"columns":["id","name"],"types":["integer","text"],"values":[[1,"fiona"]]}]`, asJSON(r); exp != got {
59 t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got)
60 }
61 }
62
63 /////////////////////////////////////////////////////////////////////
64 // Vacuumed backup, database may be not be bit-for-bit identical, but
65 // records should be OK.
66 vf, err := os.CreateTemp("", "rqlite-baktest-")
67 if err != nil {
68 t.Fatalf("Backup Failed: unable to create temp file, %s", err.Error())
69 }
70 defer os.Remove(vf.Name())
71 defer vf.Close()
72 if err := s.Backup(context.Background(), backupRequestBinary(true, true, false), vf); err != nil {
73 t.Fatalf("Backup failed %s", err.Error())
74 }
75 checkDB(vf.Name())

Callers

nothing calls this directly

Calls 15

OpenFunction · 0.92
GunzipFunction · 0.92
mustNewStoreFunction · 0.85
NewServerFunction · 0.85
BootstrapMethod · 0.80
NameMethod · 0.80
executeRequestFromStringFunction · 0.70
queryRequestFromStringFunction · 0.70
asJSONFunction · 0.70
backupRequestBinaryFunction · 0.70
CloseMethod · 0.65
OpenMethod · 0.65

Tested by

no test coverage detected