From f8b75eb91b8ae0962b2113b9d0ba76377e155c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Wed, 16 Nov 2022 07:58:58 +0100 Subject: [PATCH] Add more tests --- tests/one.sh | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/tests/one.sh b/tests/one.sh index 9d207e3..a062d6d 100755 --- a/tests/one.sh +++ b/tests/one.sh @@ -2,19 +2,42 @@ set -ueo pipefail SCRIPT_DIR=$(dirname $(readlink -f "$0")) -DB_FILE="${SCRIPT_DIR}/test.db" +DB_FILE="test.db" -setUp() { - tag init "$DB_FILE" +oneTimeSetUp() { + tag --db "$DB_FILE" init >/dev/null } -tearDown() { +oneTimeTearDown() { + # need to check if file exists + # because of bug in shunit2 that + # runs one-time teardown two times + # see https://github.com/kward/shunit2/issues/112 [ -f "$DB_FILE" ] && rm "$DB_FILE" } - testDbCreated() { assertTrue "[[ -f \"$DB_FILE\" ]]" } -. ../../shunit2/shunit2 \ No newline at end of file +testTagAdded() { + tag --db "$DB_FILE" add tag hello >/dev/null + RESULT=$(sqlite3 "$DB_FILE" "SELECT label from tags WHERE label = 'hello'") + assertEquals $RESULT "hello" +} + +testFilenameAdded() { + local FILENAME="test.mp4" + tag --db "$DB_FILE" add path "$FILENAME" >/dev/null + RESULT=$(sqlite3 "$DB_FILE" "SELECT filename from files WHERE filename = '$FILENAME'") + assertEquals "$RESULT" "$FILENAME" +} + +testHashAdded() { + local HASH="fbe2153ce0614d76a378b2e6fe07cc9e" + tag --db "$DB_FILE" add hash "$HASH" >/dev/null + RESULT=$(sqlite3 "$DB_FILE" "SELECT md5 from hashes WHERE hash = '$HASH'") + assertEquals "$RESULT" "$HASH" +} + +. ../shunit2/shunit2 \ No newline at end of file