Skip to content

Commit 24d7a4a

Browse files
committed
Add unit & acceptance tests around db selection
1 parent d6e72f4 commit 24d7a4a

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

acceptance-tests/acceptance.bats

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
[ "$status" -eq 1 ]
1212
}
1313

14+
@test "Pass when using a non-default db" {
15+
run tests/select-db.sh
16+
[ "$status" -eq 0 ]
17+
}
18+
1419
# https://github.com/yannh/redis-dump-go/issues/11
1520
# https://github.com/yannh/redis-dump-go/issues/18
1621
@test "Pass when importing a ZSET with 1M entries" {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh -e
2+
3+
export DB=2
4+
5+
echo "-> Filling Redis with Mock Data..."
6+
redis-cli -h redis -n $DB FLUSHDB
7+
/generator -output resp -type strings -n 100 | redis-cli -h redis -n $DB --pipe
8+
DBSIZE=`redis-cli -h redis -n $DB dbsize`
9+
10+
echo "-> Dumping DB..."
11+
time /redis-dump-go -host redis -n 250 -db $DB -output resp >backup
12+
13+
echo "-> Flushing DB and restoring dump..."
14+
redis-cli -h redis -n $DB FLUSHDB
15+
redis-cli -h redis -n $DB --pipe <backup
16+
NEWDBSIZE=`redis-cli -h redis -n $DB dbsize`
17+
echo "Redis has $DBSIZE entries"
18+
19+
echo "-> Comparing DB sizes..."
20+
if [ $DBSIZE -ne $NEWDBSIZE ]; then
21+
echo "ERROR - restored DB has $NEWDBSIZE elements, expected $DBSIZE"
22+
exit 1
23+
else
24+
echo "OK - $NEWDBSIZE elements"
25+
exit 0
26+
fi

pkg/config/config_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ func TestFromFlags(t *testing.T) {
2323
Output: "resp",
2424
},
2525
},
26+
{
27+
[]string{"-db", "2"},
28+
Config{
29+
Db: 2,
30+
Host: "127.0.0.1",
31+
Port: 6379,
32+
Filter: "*",
33+
BatchSize: 1000,
34+
NWorkers: 10,
35+
WithTTL: true,
36+
Output: "resp",
37+
},
38+
},
2639
{
2740
[]string{"-ttl=false"},
2841
Config{

0 commit comments

Comments
 (0)