forked from NethermindEth/juno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigration_test.go
42 lines (34 loc) · 1.38 KB
/
migration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package migration_test
import (
"context"
"testing"
"github.com/NethermindEth/juno/db/pebble"
"github.com/NethermindEth/juno/migration"
"github.com/NethermindEth/juno/utils"
"github.com/stretchr/testify/require"
)
func TestMigrateIfNeeded(t *testing.T) {
testDB := pebble.NewMemTest(t)
ctx, cancel := context.WithCancel(context.Background())
cancel()
t.Run("Migration should not happen on cancelled ctx", func(t *testing.T) {
require.ErrorIs(t, migration.MigrateIfNeeded(ctx, testDB, &utils.Mainnet, utils.NewNopZapLogger()), ctx.Err())
})
meta, err := migration.SchemaMetadata(testDB)
require.NoError(t, err)
require.Equal(t, uint64(0), meta.Version)
require.Nil(t, meta.IntermediateState)
t.Run("Migration should happen on empty DB", func(t *testing.T) {
require.NoError(t, migration.MigrateIfNeeded(context.Background(), testDB, &utils.Mainnet, utils.NewNopZapLogger()))
})
meta, err = migration.SchemaMetadata(testDB)
require.NoError(t, err)
require.NotEqual(t, uint64(0), meta.Version)
require.Nil(t, meta.IntermediateState)
t.Run("subsequent calls to MigrateIfNeeded should not change the DB version", func(t *testing.T) {
require.NoError(t, migration.MigrateIfNeeded(context.Background(), testDB, &utils.Mainnet, utils.NewNopZapLogger()))
postVersion, postErr := migration.SchemaMetadata(testDB)
require.NoError(t, postErr)
require.Equal(t, meta, postVersion)
})
}