2022-11-15 21:36:11 +00:00
#!/usr/bin/env bash
set -ueo pipefail
SCRIPT_DIR = $( dirname $( readlink -f " $0 " ) )
2022-11-16 06:58:58 +00:00
DB_FILE = "test.db"
2022-11-16 07:56:15 +00:00
FILENAME = "test.mp4"
2022-11-15 21:36:11 +00:00
2022-11-16 06:58:58 +00:00
oneTimeSetUp( ) {
tag --db " $DB_FILE " init >/dev/null
2022-11-15 21:36:11 +00:00
}
2022-11-16 06:58:58 +00:00
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
2022-11-15 21:36:11 +00:00
[ -f " $DB_FILE " ] && rm " $DB_FILE "
2022-11-16 10:54:52 +00:00
[ -f " $FILENAME " ] && rm " $FILENAME "
2022-11-15 21:36:11 +00:00
}
testDbCreated( ) {
assertTrue " [[ -f \" $DB_FILE \" ]] "
}
2022-11-16 06:58:58 +00:00
testTagAdded( ) {
tag --db " $DB_FILE " add tag hello >/dev/null
RESULT = $( sqlite3 " $DB_FILE " "SELECT label from tags WHERE label = 'hello'" )
2022-11-16 11:16:28 +00:00
assertEquals "hello" " $RESULT "
2022-11-16 06:58:58 +00:00
}
2022-11-16 10:53:25 +00:00
testFailAddingNonexistentFile( ) {
tag --db " $DB_FILE " import " $FILENAME " 2>/dev/null
2022-11-16 11:16:28 +00:00
assertEquals 1 " $? "
2022-11-16 10:53:25 +00:00
}
2022-11-16 06:58:58 +00:00
testFilenameAdded( ) {
2022-11-16 10:53:25 +00:00
touch " $FILENAME "
2022-11-16 06:58:58 +00:00
tag --db " $DB_FILE " add path " $FILENAME " >/dev/null
RESULT = $( sqlite3 " $DB_FILE " " SELECT filename from files WHERE filename = ' $FILENAME ' " )
2022-11-16 11:16:28 +00:00
assertEquals " $FILENAME " " $RESULT "
2022-11-16 06:58:58 +00:00
}
testHashAdded( ) {
local HASH = "fbe2153ce0614d76a378b2e6fe07cc9e"
2022-11-16 07:56:15 +00:00
tag --db " $DB_FILE " add hash " $FILENAME " " $HASH " >/dev/null
RESULT = $( sqlite3 " $DB_FILE " " SELECT md5 from hashes WHERE md5 = ' $HASH ' " )
2022-11-16 11:16:28 +00:00
assertEquals " $HASH " " $RESULT "
2022-11-16 06:58:58 +00:00
}
2022-11-16 07:56:15 +00:00
testFailAddingHashOnNonexistentFile( ) {
local HASH = "fbe2153ce0614d76a378b2e6fe07cc9e"
tag --db " $DB_FILE " add hash "nonexistentfile" " $HASH " 2>/dev/null
2022-11-16 11:16:28 +00:00
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 "
2022-11-16 07:56:15 +00:00
}
2022-11-16 06:58:58 +00:00
. ../shunit2/shunit2