setup() {
bats_load_library 'bats-support'
bats_load_library 'bats-assert'
- mkdir --parents "build/tests/lib"
- mkdir --parents "build/tests/music/Alben/Artist1"
- mkdir --parents "build/tests/output"
- touch "build/tests/lib/vorbis.sh"
- echo "Alben/Artist1" > "build/tests/albumlist"
- echo "testfile" > "build/tests/music/Alben/Artist1/file.flac"
- echo "cover" > "build/tests/music/Alben/Artist1/cover.jpg"
- export TEST_MODE="ON"
LIB_PATH="build/tests/lib"
+ export TEST_MODE="ON"
export CONFIG_FILE="tests/test.conf"
export ENCODE_COUNT=0
export ENCODE_LOG="build/tests/encode.log"
+ export MUSIC_PATH="build/tests/music"
+ export OUTPUT_PATH="build/tests/output"
source src/albentohandy
encode() {
((ENCODE_COUNT--))
unset LIB_PATH
unset ENCODE_COUNT
unset ENCODE_LOG
+ unset MUSIC_PATH
+ unset OUTPUT_PATH
}
# bats test_tags=albentohandy:check_programs
# bats test_tags=albentohandy:load_config
@test "failed: missing MUSIC_PATH" {
+ unset MUSIC_PATH
+ mkdir --parents "build/tests"
CONFIG_FILE="build/tests/albentohandy.conf"
echo "" > "$CONFIG_FILE"
# bats test_tags=albentohandy:load_config
@test "failed: directory MUSIC_PATH does not exists" {
+ mkdir --parents "build/tests"
CONFIG_FILE="build/tests/albentohandy.conf"
echo "MUSIC_PATH=build/tests/not_exists" > "$CONFIG_FILE"
# bats test_tags=albentohandy:load_library,albentohandy:options
@test "failed: lib vorbis.sh not found" {
+ load_config() {
+ :
+ }
LIB_PATH="build/tests/lib1"
run main
# bats test_tags=albentohandy:load_library,albentohandy:options
@test "failed: lib mp3.sh not found" {
+ load_config() {
+ :
+ }
LIB_PATH="build/tests/lib"
run main -3
# bats test_tags=albentohandy:load_library,albentohandy:options
@test "failed: lib flac.sh not found" {
+ load_config() {
+ :
+ }
LIB_PATH="build/tests/lib"
run main -f
# bats test_tags=albentohandy:load_library,albentohandy:options
@test "failed: lib opus.sh not found" {
+ load_config() {
+ :
+ }
LIB_PATH="build/tests/lib"
run main -o
# bats test_tags=albentohandy:options
@test "failed: unknown option" {
+ load_config() {
+ :
+ }
+
run main -x
assert_failure
# bats test_tags=albentohandy:load_library
@test "failed: could not load library" {
- MUSIC_PATH="build/tests/music"
- OUTPUT_PATH="build/tests/output"
+ mkdir --parents "build/tests/lib"
+ touch "build/tests/lib/vorbis.sh"
load_config() {
:
}
# bats test_tags=albentohandy:input
@test "failed: albumlist not found" {
+ load_config() {
+ :
+ }
+ load_library() {
+ :
+ }
+
run main
assert_failure
# bats test_tags=albentohandy:input
@test "failed: input file asdf not found" {
+ load_config() {
+ :
+ }
+ load_library() {
+ :
+ }
+
run main -i "asdf"
assert_failure
# bats test_tags=albentohandy:output
@test "success: create output path" {
+ load_config() {
+ :
+ }
+ load_library() {
+ :
+ }
make_symlinks_to_work() {
:
}
+ check_albumlist() {
+ :
+ }
run main -i "build/tests/albumlist"
# bats test_tags=albentohandy:input
@test "failed: directory build/tests/music/Alben/Artist2 does not exists" {
+ mkdir --parents "build/tests"
echo "Alben/Artist2" > "build/tests/albumlist"
+ load_config() {
+ :
+ }
+ load_library() {
+ :
+ }
run main -i "build/tests/albumlist"
cleanup_flac() {
:
}
+ load_config() {
+ MUSIC_PATH=$(realpath "$MUSIC_PATH")
+ }
+ load_library() {
+ :
+ }
+ mkdir --parents "build/tests/music/Artist1"
+ echo "testfile" > "build/tests/music/Artist1/file.flac"
+ echo "Artist1" > "build/tests/albumlist"
run main -i "build/tests/albumlist"
# bats test_tags=albentohandy:copy
@test "failed: create symlink for Alben/Artist1/file.flac" {
+ load_config() {
+ :
+ }
+ load_library() {
+ :
+ }
cp() {
return 1
}
+ mkdir --parents "build/tests/music/Alben/Artist1"
+ echo "Alben/Artist1" > "build/tests/albumlist"
run main -i "build/tests/albumlist"
cleanup_flac() {
:
}
+ load_config() {
+ MUSIC_PATH=$(realpath "$MUSIC_PATH")
+ }
+ load_library() {
+ :
+ }
+ mkdir --parents "build/tests/music/Alben/Artist1"
+ echo "testfile" > "build/tests/music/Alben/Artist1/file.flac"
+ echo "coverfile" > "build/tests/music/Alben/Artist1/cover.jpg"
+ echo "Alben/Artist1" > "build/tests/albumlist"
run main -i "build/tests/albumlist"
# bats test_tags=albentohandy:copy
@test "failed: copy cover.jpg for Alben/Artist1" {
+ cleanup_cover() {
+ :
+ }
+ cleanup_flac() {
+ :
+ }
+ load_config() {
+ MUSIC_PATH=$(realpath "$MUSIC_PATH")
+ }
+ load_library() {
+ :
+ }
rsync() {
return 1
}
+ mkdir --parents "build/tests/music/Alben/Artist1"
+ echo "testfile" > "build/tests/music/Alben/Artist1/file.flac"
+ echo "Alben/Artist1" > "build/tests/albumlist"
run main -i "build/tests/albumlist"
# bats test_tags=albentohandy:encode
@test "success: call encode" {
+ load_config() {
+ :
+ }
+ load_library() {
+ :
+ }
+ check_albumlist() {
+ :
+ }
+ make_symlinks_to_work() {
+ :
+ }
+
ENCODE_COUNT=1
run main -i "build/tests/albumlist"
# bats test_tags=albentohandy:encode
@test "failed: could not encode" {
+ load_config() {
+ :
+ }
+ load_library() {
+ :
+ }
+ check_albumlist() {
+ :
+ }
+ make_symlinks_to_work() {
+ :
+ }
encode() {
return 1
}
# bats test_tags=albentohandy:cleanup
@test "success: cleanup cover" {
+ load_config() {
+ :
+ }
+ load_library() {
+ :
+ }
+ check_albumlist() {
+ :
+ }
+ make_symlinks_to_work() {
+ :
+ }
+ encode() {
+ :
+ }
mkdir --parents "build/tests/output/Artist1/"
echo "metadatacover" > "build/tests/output/Artist1/cover.txt"
+ echo "metadatacover" > "build/tests/output/Artist1/cover.jpg"
run main -i "build/tests/albumlist"
# bats test_tags=albentohandy:cleanup
@test "failed: cleanup cover" {
+ load_config() {
+ :
+ }
+ load_library() {
+ :
+ }
+ check_albumlist() {
+ :
+ }
+ make_symlinks_to_work() {
+ :
+ }
+ encode() {
+ :
+ }
cleanup_cover() {
return 1
}
# bats test_tags=albentohandy:cleanup
@test "success: cleanup flac" {
+ load_config() {
+ :
+ }
+ load_library() {
+ :
+ }
+ check_albumlist() {
+ :
+ }
+ make_symlinks_to_work() {
+ :
+ }
+ encode() {
+ :
+ }
+ cleanup_cover() {
+ :
+ }
+ mkdir --parents "build/tests/output/Artist1"
+ echo "testfile" > "build/tests/output/Artist1/file.flac"
+
run main -i "build/tests/albumlist"
assert_success
# bats test_tags=albentohandy:cleanup
@test "success: not cleanup flac with flac lib" {
+ load_config() {
+ :
+ }
load_library() {
:
}
+ check_albumlist() {
+ :
+ }
+ make_symlinks_to_work() {
+ :
+ }
+ encode() {
+ :
+ }
+ cleanup_cover() {
+ :
+ }
+ mkdir --parents "build/tests/output/Artist1"
+ echo "testfile" > "build/tests/output/Artist1/file.flac"
run main -i "build/tests/albumlist" -f
# bats test_tags=albentohandy:cleanup
@test "failed: could not cleanup flac" {
+ load_config() {
+ :
+ }
load_library() {
:
}
+ check_albumlist() {
+ :
+ }
+ make_symlinks_to_work() {
+ :
+ }
+ encode() {
+ :
+ }
+ cleanup_cover() {
+ :
+ }
cleanup_flac() {
return 1
}
# bats test_tags=albentohandy:checksum
@test "success: create checksum" {
+ load_config() {
+ :
+ }
+ load_library() {
+ :
+ }
+ check_albumlist() {
+ :
+ }
+ make_symlinks_to_work() {
+ :
+ }
+ encode() {
+ :
+ }
+ cleanup_cover() {
+ :
+ }
+ cleanup_flac() {
+ :
+ }
mkdir --parents "build/tests/output/Artist1/Album1"
echo "testfile3" > "build/tests/output/Artist1/Album1/blub.ogg"
echo "testfile2" > "build/tests/output/Artist1/Album1/02.ogg"
# bats test_tags=albentohandy:usage
@test "success: print usage" {
+ load_config() {
+ :
+ }
+
run main -h
assert_success
# bats test_tags=albentohandy:usage
@test "failure: print usage by unknown command" {
+ load_config() {
+ :
+ }
+
run main -x
assert_failure