From ec5cb5bb17d501c2a1fcc4b017a61b7669893e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Wed, 16 Nov 2022 08:56:15 +0100 Subject: [PATCH] Add hash test --- tests/basic.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/basic.sh b/tests/basic.sh index a062d6d..d00a04e 100755 --- a/tests/basic.sh +++ b/tests/basic.sh @@ -3,6 +3,7 @@ set -ueo pipefail SCRIPT_DIR=$(dirname $(readlink -f "$0")) DB_FILE="test.db" +FILENAME="test.mp4" oneTimeSetUp() { tag --db "$DB_FILE" init >/dev/null @@ -27,7 +28,6 @@ testTagAdded() { } 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" @@ -35,9 +35,15 @@ testFilenameAdded() { testHashAdded() { local HASH="fbe2153ce0614d76a378b2e6fe07cc9e" - tag --db "$DB_FILE" add hash "$HASH" >/dev/null - RESULT=$(sqlite3 "$DB_FILE" "SELECT md5 from hashes WHERE hash = '$HASH'") + tag --db "$DB_FILE" add hash "$FILENAME" "$HASH" >/dev/null + RESULT=$(sqlite3 "$DB_FILE" "SELECT md5 from hashes WHERE md5 = '$HASH'") assertEquals "$RESULT" "$HASH" } +testFailAddingHashOnNonexistentFile() { + local HASH="fbe2153ce0614d76a378b2e6fe07cc9e" + tag --db "$DB_FILE" add hash "nonexistentfile" "$HASH" 2>/dev/null + assertEquals "$?" 1 +} + . ../shunit2/shunit2 \ No newline at end of file