-
Notifications
You must be signed in to change notification settings - Fork 11
/
migrate_test.go
107 lines (82 loc) · 2.09 KB
/
migrate_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"fmt"
"testing"
"github.com/garyburd/redigo/redis"
)
func Test_MigrateAllKeysWithAPrefix(t *testing.T) {
ClearRedis()
config = Config{
Source: sourceServer.url,
Dest: destServer.url,
Workers: 1,
Batch: 10,
Prefix: "bar",
}
for i := 0; i < 100; i++ {
key := fmt.Sprintf("bar:%d", i)
sourceServer.conn.Do("SET", key, i)
}
sourceServer.conn.Do("SET", "baz:foo", "yolo")
RunAction(migrateKeys)
for i := 0; i < 100; i++ {
key := fmt.Sprintf("bar:%d", i)
exists, _ := redis.Bool(destServer.conn.Do("EXISTS", key))
if !exists {
t.Errorf("Could not find a key %s that should have been migrated", key)
}
}
exists, _ := redis.Bool(destServer.conn.Do("EXISTS", "baz:foo"))
if exists {
t.Errorf("Found a key %s that should not have been migrated", "baz:foo")
}
}
func Test_MigrateAllKeysWithTTLs(t *testing.T) {
ClearRedis()
config = Config{
Source: sourceServer.url,
Dest: destServer.url,
Workers: 1,
Batch: 10,
Prefix: "bar",
}
for i := 0; i < 100; i++ {
key := fmt.Sprintf("bar:%d", i)
sourceServer.conn.Do("SET", key, i, "EX", 600)
}
RunAction(migrateKeys)
for i := 0; i < 100; i++ {
key := fmt.Sprintf("bar:%d", i)
exists, _ := redis.Bool(destServer.conn.Do("EXISTS", key))
if !exists {
t.Errorf("Could not find a key %s that should have been migrated", key)
}
ttl, _ := redis.Int64(destServer.conn.Do("PTTL", key))
if ttl < 1 || ttl > 600000 {
t.Errorf("Could not find a TTL for key %s that should have been migrated", key)
}
}
}
func Test_DoesNothingInDryRunModeForMigrate(t *testing.T) {
ClearRedis()
config = Config{
Source: sourceServer.url,
Workers: 1,
Batch: 10,
Prefix: "bar",
DryRun: true,
Dest: destServer.url,
}
for i := 0; i < 100; i++ {
key := fmt.Sprintf("bar:%d", i)
sourceServer.conn.Do("SET", key, i)
}
RunAction(migrateKeys)
for i := 0; i < 100; i++ {
key := fmt.Sprintf("bar:%d", i)
exists, _ := redis.Bool(destServer.conn.Do("EXISTS", key))
if exists {
t.Errorf("In DryRun mode, but found a key %s that was actually migrated", key)
}
}
}