diff --git a/.gitignore b/.gitignore index 01a319f..7c839d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -/bin/ *.tar.gz /test/extracted/ /test/example/ diff --git a/Dockerfile b/Dockerfile index 9bf28d9..bd24f73 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ -FROM golang:1.20-alpine AS builder +FROM golang:1.20-alpine # Install build dependencies -RUN apk add --no-cache git +RUN apk add --no-cache git tar gzip # Set up the working directory WORKDIR /app @@ -21,26 +21,12 @@ RUN GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -o tarballer-darwin -ldflags # Build Linux binary for testing in container RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o tarballer-linux -ldflags="-s -w" -# Second stage for testing -FROM alpine:latest AS tester - -# Install required tools for testing -RUN apk add --no-cache tar gzip - -WORKDIR /workdir - # Copy Linux binary for use in the container -COPY --from=builder /app/tarballer-linux /bin/tarballer - -# Also copy the FreeBSD and Darwin binaries for extraction -COPY --from=builder /app/tarballer-freebsd /bin/ -COPY --from=builder /app/tarballer-darwin /bin/ - -# Make binaries executable -RUN chmod +x /bin/tarballer /bin/tarballer-freebsd /bin/tarballer-darwin +RUN cp tarballer-linux /bin/tarballer && chmod +x /bin/tarballer # Copy test script COPY test/test.sh /bin/test.sh +RUN chmod +x /bin/test.sh -# Make test script executable -RUN chmod +x /bin/test.sh \ No newline at end of file +# Default working directory for running tests +WORKDIR /workdir \ No newline at end of file diff --git a/bin/tarballer-darwin b/bin/tarballer-darwin new file mode 100755 index 0000000..00d89e9 Binary files /dev/null and b/bin/tarballer-darwin differ diff --git a/bin/tarballer-freebsd b/bin/tarballer-freebsd new file mode 100755 index 0000000..1eca1bd Binary files /dev/null and b/bin/tarballer-freebsd differ diff --git a/bin/tarballer-linux b/bin/tarballer-linux new file mode 100755 index 0000000..a88966b Binary files /dev/null and b/bin/tarballer-linux differ diff --git a/docker-compose.yml b/docker-compose.yml index 21fd305..f66bf2e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,47 +1,10 @@ services: - build: + tarballer: build: context: . - target: builder - volumes: - - ./bin:/output - command: sh -c "cp /app/tarballer-freebsd /output/ && cp /app/tarballer-darwin /output/ && cp /app/tarballer-linux /output/ && chmod +x /output/tarballer-freebsd /output/tarballer-darwin /output/tarballer-linux" - - test: - build: - context: . - target: tester volumes: - ./bin:/output - ./test:/test - .:/workdir working_dir: /workdir - depends_on: - - build - command: /bin/test.sh all - - basic-test: - build: - context: . - target: tester - volumes: - - ./bin:/output - - ./test:/test - - .:/workdir - working_dir: /workdir - depends_on: - - build - command: /bin/test.sh basic - - tar-test: - build: - context: . - target: tester - volumes: - - ./bin:/output - - ./test:/test - - .:/workdir - working_dir: /workdir - depends_on: - - build - command: /bin/test.sh tar \ No newline at end of file + command: sh -c "cp /app/tarballer-freebsd /output/ && cp /app/tarballer-darwin /output/ && cp /app/tarballer-linux /output/ && chmod +x /output/tarballer-* && /bin/test.sh all" \ No newline at end of file diff --git a/test/complex-extracted-md5.txt b/test/complex-extracted-md5.txt deleted file mode 100644 index d17ba7b..0000000 --- a/test/complex-extracted-md5.txt +++ /dev/null @@ -1,6 +0,0 @@ -fe910f3824aa56f69e6c5cfcaa617841 /test/complex-extracted/complex-app/dir1/file1.txt -65836cb8234924d22c1e383e4ddce797 /test/complex-extracted/complex-app/dir1/subdir1/file3.txt -03fc5818d2424dc1820fec5b6d3ba1ff /test/complex-extracted/complex-app/dir1/subdir1/subsubdir1/file5.txt -d4b7a1f50b3302d9523c0dba53f490fc /test/complex-extracted/complex-app/dir1/subdir2/file4.txt -604e0b2e70ef84a95fdc3dd6ca2d2d09 /test/complex-extracted/complex-app/dir2/file2.txt -788c8c79dbab5ef7507344254f0be0cb /test/complex-extracted/complex-app/rootfile.txt diff --git a/test/complex-original-md5.txt b/test/complex-original-md5.txt deleted file mode 100644 index 08d76be..0000000 --- a/test/complex-original-md5.txt +++ /dev/null @@ -1,6 +0,0 @@ -fe910f3824aa56f69e6c5cfcaa617841 /test/complex/dir1/file1.txt -65836cb8234924d22c1e383e4ddce797 /test/complex/dir1/subdir1/file3.txt -03fc5818d2424dc1820fec5b6d3ba1ff /test/complex/dir1/subdir1/subsubdir1/file5.txt -d4b7a1f50b3302d9523c0dba53f490fc /test/complex/dir1/subdir2/file4.txt -604e0b2e70ef84a95fdc3dd6ca2d2d09 /test/complex/dir2/file2.txt -788c8c79dbab5ef7507344254f0be0cb /test/complex/rootfile.txt diff --git a/test/test.sh b/test/test.sh index bf08d83..af02b7c 100755 --- a/test/test.sh +++ b/test/test.sh @@ -3,11 +3,29 @@ # Determine which test to run TEST_TYPE=${1:-"all"} +# Set to 1 to keep temporary files, 0 to clean them up +KEEP_TEMP_FILES=${2:-0} + +cleanup_files() { + if [ "$KEEP_TEMP_FILES" -eq 0 ]; then + echo "=== CLEANING UP TEMPORARY FILES ===" + rm -rf /test/complex /test/complex-extracted + rm -f /test/complex-original-md5.txt /test/complex-extracted-md5.txt + rm -rf /test/standard-test /test/standard-extracted /test/reference-extracted + rm -f /test/original-checksums.txt /test/standard-checksums.txt /test/reference-checksums.txt + rm -f /workdir/complex.tar.gz /workdir/standard.tar.gz /workdir/reference.tar.gz + echo "Temporary files cleaned up" + else + echo "Keeping temporary files for inspection" + fi +} + run_basic_test() { echo "=== RUNNING BASIC TEST ===" # Clean up existing test directories rm -rf /test/complex /test/complex-extracted + rm -f /test/complex-original-md5.txt /test/complex-extracted-md5.txt # Create complex directory structure mkdir -p /test/complex/dir1/subdir1/subsubdir1 @@ -91,6 +109,7 @@ run_tar_comparison_test() { # Clean up test directories rm -rf /test/standard-test /test/standard-extracted /test/reference-extracted + rm -f /test/original-checksums.txt /test/standard-checksums.txt /test/reference-checksums.txt # Create a diverse test directory structure mkdir -p /test/standard-test/config/settings @@ -193,11 +212,15 @@ run_tar_comparison_test() { case "$TEST_TYPE" in "basic") run_basic_test - exit $? + RESULT=$? + [ "$RESULT" -eq 0 ] && cleanup_files + exit $RESULT ;; "tar") run_tar_comparison_test - exit $? + RESULT=$? + [ "$RESULT" -eq 0 ] && cleanup_files + exit $RESULT ;; "all") echo "=== RUNNING ALL TESTS ===" @@ -208,15 +231,21 @@ case "$TEST_TYPE" in if [ $BASIC_RESULT -eq 0 ] && [ $TAR_RESULT -eq 0 ]; then echo "✅ ALL TESTS PASSED SUCCESSFULLY!" + cleanup_files exit 0 else echo "❌ SOME TESTS FAILED!" exit 1 fi ;; + "clean") + cleanup_files + exit 0 + ;; *) echo "Unknown test type: $TEST_TYPE" - echo "Usage: $0 [basic|tar|all]" + echo "Usage: $0 [basic|tar|all|clean] [keep_temp_files]" + echo " keep_temp_files: 0 (clean up, default) or 1 (keep temp files)" exit 1 ;; esac \ No newline at end of file