Skip to content

Commit

Permalink
sqlite: extend backup test
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Sep 11, 2024
1 parent 391a7ba commit 74ca3dc
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions persist/sqlite/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,33 +231,45 @@ func TestBackup(t *testing.T) {
t.Fatal(err)
}

// backup the database
destPath := filepath.Join(t.TempDir(), "backup.db")
if err := Backup(context.Background(), srcPath, destPath); err != nil {
t.Fatal(err)
} else if err := db.Close(); err != nil {
t.Fatal(err)
}
checkDatabase := func(t *testing.T, fp string) {
// open the backup database
backup, err := OpenDatabase(fp, zaptest.NewLogger(t))
if err != nil {
t.Fatal(err)
}
defer backup.Close()

// open the backup database
backup, err := OpenDatabase(destPath, zaptest.NewLogger(t))
if err != nil {
t.Fatal(err)
}
defer backup.Close()
// check that the data was backed up correctly
restoredVolume, err := backup.Volume(id)
if err != nil {
t.Fatal(err)
} else if !reflect.DeepEqual(volume, restoredVolume) {
t.Fatalf("expected volume %v, got %v", volume, restoredVolume)
}

// check that the data was backed up correctly
restoredVolume, err := backup.Volume(id)
if err != nil {
t.Fatal(err)
} else if !reflect.DeepEqual(volume, restoredVolume) {
t.Fatalf("expected volume %v, got %v", volume, restoredVolume)
restoredSettings, err := backup.Settings()
if err != nil {
t.Fatal(err)
} else if !reflect.DeepEqual(newSettings, restoredSettings) {
t.Fatalf("expected settings %v, got %v", newSettings, restoredSettings)
}
}

restoredSettings, err := backup.Settings()
if err != nil {
t.Fatal(err)
} else if !reflect.DeepEqual(newSettings, restoredSettings) {
t.Fatalf("expected settings %v, got %v", newSettings, restoredSettings)
}
t.Run("Store.Backup", func(t *testing.T) {
destPath := filepath.Join(t.TempDir(), "backup.db")
if err := Backup(context.Background(), srcPath, destPath); err != nil {
t.Fatal(err)
}

checkDatabase(t, destPath)
})

t.Run("Backup", func(t *testing.T) {
destPath := filepath.Join(t.TempDir(), "backup.db")
if err := db.Backup(context.Background(), destPath); err != nil {
t.Fatal(err)
}

checkDatabase(t, destPath)
})
}

0 comments on commit 74ca3dc

Please sign in to comment.