-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathcmd_migrate_db_sqlite_test.go
60 lines (48 loc) · 1.26 KB
/
cmd_migrate_db_sqlite_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//go:build kvdb_sqlite
package main
import (
"fmt"
"testing"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/kvdb/sqlite"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/stretchr/testify/require"
)
// TestMigrateDBSqlite tests the migration of a database from Bolt to SQLite.
func TestMigrateDBSqlite(t *testing.T) {
t.Parallel()
// Create temp dir for test databases.
tempDir := setupTestData(t)
fmt.Println("tempDir", tempDir)
// Copy entire test directory structure.
err := copyTestDataDir("testdata/data", tempDir)
require.NoError(t, err, "failed to copy test data")
// Set up source DB config (bolt).
sourceDB := &SourceDB{
Backend: lncfg.BoltBackend,
Bolt: &Bolt{
DBTimeout: kvdb.DefaultDBTimeout,
DataDir: tempDir,
TowerDir: tempDir,
},
}
// Set up destination DB config (sqlite).
destDB := &DestDB{
Backend: lncfg.SqliteBackend,
Sqlite: &Sqlite{
DataDir: tempDir,
TowerDir: tempDir,
Config: &sqlite.Config{},
},
}
// Create and run migration command.
cmd := &migrateDBCommand{
Source: sourceDB,
Dest: destDB,
Network: "regtest",
// Select a small chunk size to test the chunking.
ChunkSize: 1024,
}
err = cmd.Execute(nil)
require.NoError(t, err, "migration failed")
}