Skip to content

Commit

Permalink
Add unit & acceptance tests around db selection
Browse files Browse the repository at this point in the history
  • Loading branch information
yannh committed Jan 23, 2022
1 parent d6e72f4 commit 24d7a4a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions acceptance-tests/acceptance.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
[ "$status" -eq 1 ]
}

@test "Pass when using a non-default db" {
run tests/select-db.sh
[ "$status" -eq 0 ]
}

# https://github.com/yannh/redis-dump-go/issues/11
# https://github.com/yannh/redis-dump-go/issues/18
@test "Pass when importing a ZSET with 1M entries" {
Expand Down
26 changes: 26 additions & 0 deletions acceptance-tests/tests/select-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh -e

export DB=2

echo "-> Filling Redis with Mock Data..."
redis-cli -h redis -n $DB FLUSHDB
/generator -output resp -type strings -n 100 | redis-cli -h redis -n $DB --pipe
DBSIZE=`redis-cli -h redis -n $DB dbsize`

echo "-> Dumping DB..."
time /redis-dump-go -host redis -n 250 -db $DB -output resp >backup

echo "-> Flushing DB and restoring dump..."
redis-cli -h redis -n $DB FLUSHDB
redis-cli -h redis -n $DB --pipe <backup
NEWDBSIZE=`redis-cli -h redis -n $DB dbsize`
echo "Redis has $DBSIZE entries"

echo "-> Comparing DB sizes..."
if [ $DBSIZE -ne $NEWDBSIZE ]; then
echo "ERROR - restored DB has $NEWDBSIZE elements, expected $DBSIZE"
exit 1
else
echo "OK - $NEWDBSIZE elements"
exit 0
fi
13 changes: 13 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ func TestFromFlags(t *testing.T) {
Output: "resp",
},
},
{
[]string{"-db", "2"},
Config{
Db: 2,
Host: "127.0.0.1",
Port: 6379,
Filter: "*",
BatchSize: 1000,
NWorkers: 10,
WithTTL: true,
Output: "resp",
},
},
{
[]string{"-ttl=false"},
Config{
Expand Down

0 comments on commit 24d7a4a

Please sign in to comment.