Skip to content

Commit

Permalink
better handles configuration variables
Browse files Browse the repository at this point in the history
  • Loading branch information
niquerio committed Oct 23, 2024
1 parent 10a1dd2 commit de530e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
11 changes: 6 additions & 5 deletions bin/digifeeds/upload_to_s3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ START_TIME=$(date '+%s')
# Directory this script lives in
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

${APP_ENV:-"production"}
APP_ENV=${APP_ENV:-"production"}

if [[ $APP_ENV != "test" ]]; then
# CONFIG
# Variables contained in the config file:
Expand All @@ -26,10 +27,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
Expand Down
16 changes: 16 additions & 0 deletions bin/digifeeds/upload_to_s3_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit de530e4

Please sign in to comment.