]> gitweb.hhaalo.de Git - albentohandy.git/commitdiff
add calc checksum
authorBastian Dehn <hhaalo@arcor.de>
Fri, 25 Sep 2026 12:04:26 +0000 (14:04 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Fri, 25 Sep 2026 12:04:26 +0000 (14:04 +0200)
src/albentohandy
tests/albentohandy.bats

index e315a16ee60b2da53b10876444d4f5f6f858e00d..b8e181bfe286469a3c571b5f622b9d92b4bb9282 100755 (executable)
@@ -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
index 47513d2028bfd98d2a22c9aa537c30dfb608ccaf..1ff0cbea9c682b73a380e4ab1a8ab82c6c24b627 100755 (executable)
@@ -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