Skip to content

Commit 0bdcaad

Browse files
committed
Return a non 0 exit code when the file does not exist
1 parent 455e49c commit 0bdcaad

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

files/bin/instateEnvironment.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ if [ -z "$1" ]; then
55
exit 1;
66
fi
77

8+
if [ ! -f "$1" ]; then
9+
(>&2 echo "$1 No such file or directory")
10+
exit 2;
11+
fi
12+
813
grep -o "{container.env.[a-zA-Z0-9_]\+}" $1 | while read -r GREPRESULT ; do
914
# Remove the {container.env.} from the grep result
1015
ENVNAME=$(echo $GREPRESULT | cut -c16- | rev | cut -c2- | rev)

test/files/dead_symlink

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/symlinks.bats

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ setup () {
3030

3131
@test "Replacing a dead_symlink" {
3232
FILE=$BATS_RUN_DIR/files/dead_symlink
33+
ln -s $BATS_RUN_DIR/files/does_not_exists $FILE
34+
run /bin/sh $BATS_BINARY_DIR/instateEnvironment.sh $FILE
35+
assert_failure
36+
rm -rf $FILE
37+
}
38+
39+
@test "Replacing a non existing file" {
40+
FILE=$BATS_RUN_DIR/files/does_not_exist
3341
run /bin/sh $BATS_BINARY_DIR/instateEnvironment.sh $FILE
3442
assert_failure
3543
}

0 commit comments

Comments
 (0)