From: Bastian Dehn Date: Fri, 25 Sep 2026 12:04:26 +0000 (+0200) Subject: add calc checksum X-Git-Tag: v1.0.0^2~7^2~13 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=b4462c71fdb36085d9fc0fe7a5d0a5b0949ec31a;p=albentohandy.git add calc checksum --- diff --git a/src/albentohandy b/src/albentohandy index e315a16..b8e181b 100755 --- a/src/albentohandy +++ b/src/albentohandy @@ -14,6 +14,9 @@ check_programs() command -v rsync > /dev/null \ || errlog "command rsync not found" \ || return $? + command -v sha256sum > /dev/null \ + || errlog "command sha256sum not found" \ + || return $? } load_config() @@ -82,6 +85,15 @@ cleanup_flac() 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" @@ -121,6 +133,7 @@ main() cleanup_flac "$lib" \ || errlog "could not cleanup flac" \ || return $? + calc_checksum } [ "$TEST_MODE" == "ON" ] && return 0 diff --git a/tests/albentohandy.bats b/tests/albentohandy.bats index 47513d2..1ff0cbe 100755 --- a/tests/albentohandy.bats +++ b/tests/albentohandy.bats @@ -39,7 +39,7 @@ teardown() { # bats test_tags=albentohandy:check_programs @test "failed: rsync not found" { command() { - [ "$2" == "rsync" ] && return 1 + [ "$2" != "rsync" ] || return 1 } run main @@ -48,6 +48,18 @@ teardown() { 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" @@ -309,4 +321,22 @@ teardown() { 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