Unit test that pre-existing data is gone
@@ -760,13 +760,20 @@ func Test_SingleNodeLoadBinary(t *testing.T) {
t.Fatalf("Error waiting for leader: %s", err)
}
- err := s.Load(loadRequestFromFile(filepath.Join("testdata", "load.sqlite")))
+ // Load a dataset, to check it's erased by the SQLite file load.
+ dump := `PRAGMA foreign_keys=OFF;
+BEGIN TRANSACTION;
+CREATE TABLE bar (id integer not null primary key, name text);
+INSERT INTO "bar" VALUES(1,'declan');
+COMMIT;
+`
+ _, err := s.Execute(executeRequestFromString(dump, false, false))
if err != nil {
- t.Fatalf("failed to load SQLite file: %s", err.Error())
+ t.Fatalf("failed to load simple dump: %s", err.Error())
}
// Check that data were loaded correctly.
- qr := queryRequestFromString("SELECT * FROM foo WHERE id=2", false, true)
+ qr := queryRequestFromString("SELECT * FROM bar", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err := s.Query(qr)
if err != nil {
@@ -775,6 +782,25 @@ func Test_SingleNodeLoadBinary(t *testing.T) {
if exp, got := `["id","name"]`, asJSON(r[0].Columns); exp != got {
t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got)
}
+ if exp, got := `[[1,"declan"]]`, asJSON(r[0].Values); exp != got {
+ t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got)
+ }
+
+ err = s.Load(loadRequestFromFile(filepath.Join("testdata", "load.sqlite")))
+ if err != nil {
+ t.Fatalf("failed to load SQLite file: %s", err.Error())
+ }
+
+ // Check that data were loaded correctly.
+ qr = queryRequestFromString("SELECT * FROM foo WHERE id=2", false, true)
+ qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
+ r, err = s.Query(qr)
+ if err != nil {
+ t.Fatalf("failed to query single node: %s", err.Error())
+ }
+ if exp, got := `["id","name"]`, asJSON(r[0].Columns); exp != got {
+ t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got)
+ }
if exp, got := `[[2,"fiona"]]`, asJSON(r[0].Values); exp != got {
t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got)
}
@@ -790,6 +816,17 @@ func Test_SingleNodeLoadBinary(t *testing.T) {
if exp, got := `[[3]]`, asJSON(r[0].Values); exp != got {
t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got)
}
+
+ // Check pre-existing data is gone.
+ qr = queryRequestFromString("SELECT * FROM bar", false, true)
+ qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
+ r, err = s.Query(qr)
+ if err != nil {
+ t.Fatalf("failed to query single node: %s", err.Error())
+ }
+ if exp, got := `{"error":"no such table: bar"}`, asJSON(r[0]); exp != got {
+ t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got)
+ }
}
// Test_SingleNodeRecoverNoChange tests a node recovery that doesn't
