Skip to content

Commit c843a73

Browse files
committed
feat(script): add steps-lib, is_env_var_set & test
1 parent 3aa780f commit c843a73

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

ci/steps/steps-lib.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
# This is a library which contains functions used inside ci/steps
4+
#
5+
# We separated it into it's own file so that we could easily unit test
6+
# these functions and helpers
7+
8+
# Checks whether and environment variable is set.
9+
# Source: https://stackoverflow.com/a/62210688/3015595
10+
is_env_var_set() {
11+
local name="${1:-}"
12+
if test -n "${!name:-}"; then
13+
echo 0
14+
else
15+
echo 1
16+
fi
17+
}

test/scripts/steps-lib.bats

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bats
2+
3+
SCRIPT_NAME="steps-lib.sh"
4+
SCRIPT="$BATS_TEST_DIRNAME/../../ci/steps/$SCRIPT_NAME"
5+
6+
source "$SCRIPT"
7+
8+
@test "is_env_var_set should return false if env var is not set" {
9+
run is_env_var_set "ASDF_TEST_SET"
10+
[ "$output" = 1 ]
11+
}
12+
13+
@test "is_env_var_set should return true if env var is set" {
14+
ASDF_TEST_SET="test" run is_env_var_set "ASDF_TEST_SET"
15+
[ "$output" = 0 ]
16+
}

0 commit comments

Comments
 (0)