prysm-pulse/beacon-chain/db/kv/backup_test.go
Preston Van Loon 7a04ff6368 Add database API for creating backups (#3694)
* Save db backup

* Fix DB backup method

* Add backup db webhook

* gaz

* if err != nil

* more verbose filename

* Don't obliterate everything :)
2019-10-03 17:29:49 +08:00

44 lines
766 B
Go

package kv
import (
"context"
"io/ioutil"
"path"
"testing"
"github.com/prysmaticlabs/go-ssz"
eth "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
)
func TestStore_Backup(t *testing.T) {
db := setupDB(t)
defer teardownDB(t, db)
ctx := context.Background()
head := &eth.BeaconBlock{}
head.Slot = 5000
if err := db.SaveBlock(ctx, head); err != nil {
t.Fatal(err)
}
root, err := ssz.SigningRoot(head)
if err != nil {
t.Fatal(err)
}
if err := db.SaveHeadBlockRoot(ctx, root); err != nil {
t.Fatal(err)
}
if err := db.Backup(ctx); err != nil {
t.Fatal(err)
}
files, err := ioutil.ReadDir(path.Join(db.databasePath, backupsDirectoryName))
if err != nil {
t.Fatal(err)
}
if len(files) == 0 {
t.Fatal("No backups created.")
}
}