From 32209534a0b8ecaacb5db0bf38c057e576c43d45 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com.> Date: Mon, 27 May 2024 22:30:25 +0100 Subject: [PATCH] gha --- .github/workflows/test.yml | 9 ++++++++ .../api/misc/ExtractImageScansController.java | 9 ++++---- .../controller/api/misc/RepairController.java | 15 ++++++------- test.sh | 22 ++++++++++++++----- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eef33335..0852bcf9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,6 +32,15 @@ jobs: sudo curl -SL "https://github.com/docker/compose/releases/download/v2.26.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose # sudo chmod +x /usr/local/bin/docker-compose + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.7" + + - name: Pip requirements + run: | + pip install -r ./cucumber/requirements.txt + - name: Run Docker Compose Tests run: | chmod +x ./test.sh diff --git a/src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImageScansController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImageScansController.java index 4a6acaee..bda228d0 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImageScansController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImageScansController.java @@ -176,10 +176,11 @@ public class ExtractImageScansController { return WebResponseUtils.bytesToWebResponse( zipBytes, outputZipFilename, MediaType.APPLICATION_OCTET_STREAM); - } if (processedImageBytes.size() == 0) { - throw new IllegalArgumentException("No images detected"); - }else { - + } + if (processedImageBytes.size() == 0) { + throw new IllegalArgumentException("No images detected"); + } else { + // Return the processed image as a response byte[] imageBytes = processedImageBytes.get(0); return WebResponseUtils.bytesToWebResponse( diff --git a/src/main/java/stirling/software/SPDF/controller/api/misc/RepairController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/RepairController.java index 812a8cae..06c652a2 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/misc/RepairController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/RepairController.java @@ -59,18 +59,17 @@ public class RepairController { // Read the optimized PDF file pdfBytes = Files.readAllBytes(tempOutputFile); - - // Return the optimized PDF as a response - String outputFilename = - Filenames.toSimpleFileName(inputFile.getOriginalFilename()) - .replaceFirst("[.][^.]+$", "") - + "_repaired.pdf"; - return WebResponseUtils.bytesToWebResponse(pdfBytes, outputFilename); + + // Return the optimized PDF as a response + String outputFilename = + Filenames.toSimpleFileName(inputFile.getOriginalFilename()) + .replaceFirst("[.][^.]+$", "") + + "_repaired.pdf"; + return WebResponseUtils.bytesToWebResponse(pdfBytes, outputFilename); } finally { // Clean up the temporary files Files.deleteIfExists(tempInputFile); Files.deleteIfExists(tempOutputFile); } - } } diff --git a/test.sh b/test.sh index e771a9b8..bb23d59d 100644 --- a/test.sh +++ b/test.sh @@ -42,11 +42,6 @@ test_compose() { status=1 fi - # Perform additional tests if needed - - # Tear down the service - docker-compose -f "$compose_file" down - return $status } @@ -83,7 +78,20 @@ main() { # Test each configuration run_tests "Stirling-PDF-Ultra-Lite" "./exampleYmlFiles/docker-compose-latest-ultra-lite.yml" + docker-compose -f "./exampleYmlFiles/docker-compose-latest-ultra-lite.yml" down + + run_tests "Stirling-PDF" "./exampleYmlFiles/docker-compose-latest.yml" + if [ $? -eq 0 ]; then + cd cucumber + if behave; then + passed_tests+=("Stirling-PDF-Regression") + else + failed_tests+=("Stirling-PDF-Regression") + fi + cd .. + fi + docker-compose -f "./exampleYmlFiles/docker-compose-latest.yml" down export DOCKER_ENABLE_SECURITY=true # Run the gradlew build command and check if it fails @@ -99,7 +107,9 @@ main() { # Test each configuration with security run_tests "Stirling-PDF-Ultra-Lite-Security" "./exampleYmlFiles/docker-compose-latest-ultra-lite-security.yml" + docker-compose -f "./exampleYmlFiles/docker-compose-latest-ultra-lite-security.yml" down run_tests "Stirling-PDF-Security" "./exampleYmlFiles/docker-compose-latest-security.yml" + docker-compose -f "./exampleYmlFiles/docker-compose-latest-security.yml" down # Report results echo "All tests completed in $SECONDS seconds." @@ -132,4 +142,4 @@ main() { } -main +main \ No newline at end of file