channeldb: applying payment statuses migration to current database
This commit is contained in:
parent
24e3310f13
commit
41e31e0909
@ -67,6 +67,12 @@ var (
|
||||
number: 4,
|
||||
migration: migrateEdgePolicies,
|
||||
},
|
||||
{
|
||||
// The version with added payment statuses
|
||||
// for each existing payment
|
||||
number: 5,
|
||||
migration: paymentStatusesMigration,
|
||||
},
|
||||
}
|
||||
|
||||
// Big endian is the preferred byte order, due to cursor scans over
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/go-errors/errors"
|
||||
)
|
||||
|
||||
func TestOpenWithCreate(t *testing.T) {
|
||||
@ -33,3 +35,56 @@ func TestOpenWithCreate(t *testing.T) {
|
||||
t.Fatalf("channeldb failed to create data directory")
|
||||
}
|
||||
}
|
||||
|
||||
// applyMigration is a helper test function that encapsulates the general steps
|
||||
// which are needed to properly check the result of applying migration function.
|
||||
func applyMigration(t *testing.T, beforeMigration, afterMigration func(d *DB),
|
||||
migrationFunc migration, shouldFail bool) {
|
||||
|
||||
cdb, cleanUp, err := makeTestDB()
|
||||
defer cleanUp()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// beforeMigration usually used for populating the database
|
||||
// with test data.
|
||||
beforeMigration(cdb)
|
||||
|
||||
// Create test meta info with zero database version and put it on disk.
|
||||
// Than creating the version list pretending that new version was added.
|
||||
meta := &Meta{DbVersionNumber: 0}
|
||||
if err := cdb.PutMeta(meta); err != nil {
|
||||
t.Fatalf("unable to store meta data: %v", err)
|
||||
}
|
||||
|
||||
versions := []version{
|
||||
{
|
||||
number: 0,
|
||||
migration: nil,
|
||||
},
|
||||
{
|
||||
number: 1,
|
||||
migration: migrationFunc,
|
||||
},
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = errors.New(r)
|
||||
}
|
||||
|
||||
if err == nil && shouldFail {
|
||||
t.Fatal("error wasn't received on migration stage")
|
||||
} else if err != nil && !shouldFail {
|
||||
t.Fatal("error was received on migration stage")
|
||||
}
|
||||
|
||||
// afterMigration usually used for checking the database state and
|
||||
// throwing the error if something went wrong.
|
||||
afterMigration(cdb)
|
||||
}()
|
||||
|
||||
// Sync with the latest version - applying migration function.
|
||||
err = cdb.syncVersions(versions)
|
||||
}
|
||||
|
@ -118,59 +118,6 @@ func TestGlobalVersionList(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// applyMigration is a helper test function that encapsulates the general steps
|
||||
// which are needed to properly check the result of applying migration function.
|
||||
func applyMigration(t *testing.T, beforeMigration, afterMigration func(d *DB),
|
||||
migrationFunc migration, shouldFail bool) {
|
||||
|
||||
cdb, cleanUp, err := makeTestDB()
|
||||
defer cleanUp()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// beforeMigration usually used for populating the database
|
||||
// with test data.
|
||||
beforeMigration(cdb)
|
||||
|
||||
// Create test meta info with zero database version and put it on disk.
|
||||
// Than creating the version list pretending that new version was added.
|
||||
meta := &Meta{DbVersionNumber: 0}
|
||||
if err := cdb.PutMeta(meta); err != nil {
|
||||
t.Fatalf("unable to store meta data: %v", err)
|
||||
}
|
||||
|
||||
versions := []version{
|
||||
{
|
||||
number: 0,
|
||||
migration: nil,
|
||||
},
|
||||
{
|
||||
number: 1,
|
||||
migration: migrationFunc,
|
||||
},
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = errors.New(r)
|
||||
}
|
||||
|
||||
if err == nil && shouldFail {
|
||||
t.Fatal("error wasn't received on migration stage")
|
||||
} else if err != nil && !shouldFail {
|
||||
t.Fatal("error was received on migration stage")
|
||||
}
|
||||
|
||||
// afterMigration usually used for checking the database state and
|
||||
// throwing the error if something went wrong.
|
||||
afterMigration(cdb)
|
||||
}()
|
||||
|
||||
// Sync with the latest version - applying migration function.
|
||||
err = cdb.syncVersions(versions)
|
||||
}
|
||||
|
||||
func TestMigrationWithPanic(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user