command -v rsync > /dev/null \
|| errlog "command rsync not found" \
|| return $?
+ command -v sha256sum > /dev/null \
+ || errlog "command sha256sum not found" \
+ || return $?
}
load_config()
find "$OUTPUT_PATH" -name '*.flac' -exec rm {} \;
}
+calc_checksum()
+{
+ cd "$OUTPUT_PATH" || return $?
+ find . -type f \
+ | sort \
+ | sed '/checksum/d' \
+ | xargs sha256sum > checksum.sha256
+}
+
main()
{
local albumlist="albumlist"
cleanup_flac "$lib" \
|| errlog "could not cleanup flac" \
|| return $?
+ calc_checksum
}
[ "$TEST_MODE" == "ON" ] && return 0
# bats test_tags=albentohandy:check_programs
@test "failed: rsync not found" {
command() {
- [ "$2" == "rsync" ] && return 1
+ [ "$2" != "rsync" ] || return 1
}
run main
assert_line --index 0 "❌ ERROR: command rsync not found"
}
+# bats test_tags=albentohandy:check_programs
+@test "failed: sha256sum not found" {
+ command() {
+ [ "$2" != "sha256sum" ] || return 1
+ }
+
+ run main
+
+ assert_failure
+ assert_line --index 0 "❌ ERROR: command sha256sum not found"
+}
+
# bats test_tags=albentohandy:load_config
@test "failed: missing albumtohandy.conf" {
CONFIG_FILE="build/tests/nothing.conf"
assert_failure
assert_line --index 0 "❌ ERROR: could not cleanup flac"
+}
+
+# bats test_tags=albentohandy:checksum
+@test "success: create checksum" {
+ 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"
+ echo "testfile1" > "build/tests/output/Artist1/Album1/01.ogg"
+ echo "testfile4" > "build/tests/output/Artist1/Album1/bla.ogg"
+
+ run main -i "build/tests/albumlist"
+
+ assert_success
+ [ -f "build/tests/output/checksum.sha256" ]
+ assert_equal "$(awk 'NR==1 {print; exit}' "build/tests/output/checksum.sha256")" "49057fb3e3bffe69b082e78550da731593c75bf19b4ba76c44a722defe4393f5 ./Artist1/Album1/01.ogg"
+ assert_equal "$(awk 'NR==2 {print; exit}' "build/tests/output/checksum.sha256")" "5ca47f5787b6cba8809184876e8557f8650d92c2b7c63a03d1a9b9aa352f7aae ./Artist1/Album1/02.ogg"
+ assert_equal "$(awk 'NR==3 {print; exit}' "build/tests/output/checksum.sha256")" "1aaea6c72ae66ce6bd36cd08fb511565a34179780d68166515a9f045652088c2 ./Artist1/Album1/bla.ogg"
+ assert_equal "$(awk 'NR==4 {print; exit}' "build/tests/output/checksum.sha256")" "96af1c6d5c863aef68cabe54aefc2342e66a9cf6b5663660f2ea8cea86e9f5ce ./Artist1/Album1/blub.ogg"
}
\ No newline at end of file