From 24d7a4a892d943d5cee989058dcb65364733e2c8 Mon Sep 17 00:00:00 2001 From: Yann Hamon Date: Sun, 23 Jan 2022 16:54:13 +0100 Subject: [PATCH] Add unit & acceptance tests around db selection --- acceptance-tests/acceptance.bats | 5 +++++ acceptance-tests/tests/select-db.sh | 26 ++++++++++++++++++++++++++ pkg/config/config_test.go | 13 +++++++++++++ 3 files changed, 44 insertions(+) create mode 100755 acceptance-tests/tests/select-db.sh diff --git a/acceptance-tests/acceptance.bats b/acceptance-tests/acceptance.bats index d517592..d24a430 100644 --- a/acceptance-tests/acceptance.bats +++ b/acceptance-tests/acceptance.bats @@ -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" { diff --git a/acceptance-tests/tests/select-db.sh b/acceptance-tests/tests/select-db.sh new file mode 100755 index 0000000..199376b --- /dev/null +++ b/acceptance-tests/tests/select-db.sh @@ -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 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 diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 8711e51..b6ed098 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -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{