Add more tests

This commit is contained in:
Lukáš Kucharczyk 2022-11-16 12:16:28 +01:00
parent d77349ce50
commit 76b490bc83
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
1 changed files with 22 additions and 5 deletions

View File

@ -25,32 +25,49 @@ testDbCreated() {
testTagAdded() {
tag --db "$DB_FILE" add tag hello >/dev/null
RESULT=$(sqlite3 "$DB_FILE" "SELECT label from tags WHERE label = 'hello'")
assertEquals $RESULT "hello"
assertEquals "hello" "$RESULT"
}
testFailAddingNonexistentFile() {
tag --db "$DB_FILE" import "$FILENAME" 2>/dev/null
assertEquals "$?" 1
assertEquals 1 "$?"
}
testFilenameAdded() {
touch "$FILENAME"
tag --db "$DB_FILE" add path "$FILENAME" >/dev/null
RESULT=$(sqlite3 "$DB_FILE" "SELECT filename from files WHERE filename = '$FILENAME'")
assertEquals "$RESULT" "$FILENAME"
assertEquals "$FILENAME" "$RESULT"
}
testHashAdded() {
local HASH="fbe2153ce0614d76a378b2e6fe07cc9e"
tag --db "$DB_FILE" add hash "$FILENAME" "$HASH" >/dev/null
RESULT=$(sqlite3 "$DB_FILE" "SELECT md5 from hashes WHERE md5 = '$HASH'")
assertEquals "$RESULT" "$HASH"
assertEquals "$HASH" "$RESULT"
}
testFailAddingHashOnNonexistentFile() {
local HASH="fbe2153ce0614d76a378b2e6fe07cc9e"
tag --db "$DB_FILE" add hash "nonexistentfile" "$HASH" 2>/dev/null
assertEquals "$?" 1
assertEquals 1 "$?"
}
testTagFile() {
tag --db "$DB_FILE" tag "$FILENAME" hello >/dev/null
RESULT=$(sqlite3 "$DB_FILE" "SELECT label FROM tags WHERE id = (SELECT tid from tags_ties WHERE fid = (SELECT id FROM files WHERE filename = '$FILENAME'))")
assertEquals "hello" "$RESULT"
}
testListingTags() {
tag --db "$DB_FILE" listtags "$FILENAME" | grep -q "^$FILENAME|hello$"
assertEquals "$?" 0
}
testAddingMultipleTags() {
tag --db "$DB_FILE" add tag more more2 >/dev/null
RESULT=$(sqlite3 -list "$DB_FILE" "SELECT COUNT(*) from tags WHERE label IN ('hello', 'more', 'more2')")
assertEquals 3 "$RESULT"
}
. ../shunit2/shunit2