From 1860e7406b68da6a2519beb645dea8a020e6533c Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Wed, 23 Oct 2024 19:51:26 +0000 Subject: [PATCH] better handles configuration variables --- bin/digifeeds/upload_to_s3.sh | 8 ++++---- bin/digifeeds/upload_to_s3_test.sh | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/bin/digifeeds/upload_to_s3.sh b/bin/digifeeds/upload_to_s3.sh index 75042cb..72dbe37 100755 --- a/bin/digifeeds/upload_to_s3.sh +++ b/bin/digifeeds/upload_to_s3.sh @@ -26,10 +26,10 @@ if [[ $APP_ENV != "test" ]]; then # shellcheck source=/dev/null source "$CONFIG_FILE" fi -${input_directory:?} -${processed_directory:?} -${digifeeds_bucket:?} -${send_metrics:-"true"} +if ! input_directory=${input_directory:?}; then exit 1; fi +if ! processed_directory=${processed_directory:?}; then exit 1; fi +if ! digifeeds_bucket=${digifeeds_bucket:?}; then exit 1; fi +send_metrics=${send_metrics:-"true"} # matches .tif and .jp2 files with 8 digit file names that start with 0 OR # checksum.md5 files diff --git a/bin/digifeeds/upload_to_s3_test.sh b/bin/digifeeds/upload_to_s3_test.sh index 64dfa2f..9657d20 100755 --- a/bin/digifeeds/upload_to_s3_test.sh +++ b/bin/digifeeds/upload_to_s3_test.sh @@ -46,6 +46,22 @@ teardown() { rm -r "$SCRATCH_PATH" } +@test "exits without input_directory" { + unset input_directory + run "${BATS_TEST_DIRNAME}/upload_to_s3.sh" + assert_failure +} +@test "exits without processed_directory" { + unset processed_directory + run "${BATS_TEST_DIRNAME}/upload_to_s3.sh" + assert_failure +} +@test "exits without digifeeds_bucket" { + unset digifeeds_bucket + run "${BATS_TEST_DIRNAME}/upload_to_s3.sh" + assert_failure +} + @test "It Works" { shellmock new rclone shellmock config rclone 0 1:copy regex-3:^digifeeds_bucket: