Skip to content

Commit

Permalink
install.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
motdotla committed Jun 13, 2024
1 parent 976106c commit c70caa4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 10 deletions.
11 changes: 5 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ VERSION="0.44.1"
DIRECTORY="/usr/local/bin"
RELEASES_URL="https://github.com/dotenvx/dotenvx/releases"

# for testing purposes
TEST_MODE=0

# usage
usage() {
echo "Usage: $0 [options] [command]"
Expand Down Expand Up @@ -177,6 +174,10 @@ is_ci() {
[ -n "$CI" ] && [ $CI != 0 ]
}

is_test_mode() {
[ -n "$TEST_MODE" ] && [ $TEST_MODE != 0 ]
}

progress_bar() {
if $(is_ci); then
echo "--no-progress-meter"
Expand Down Expand Up @@ -333,9 +334,7 @@ main() {
fi
}

if test -n "$TEST_MODE"; then
echo "running in test mode"
else
if ! is_test_mode; then
main "$@"
exit $?
fi
57 changes: 53 additions & 4 deletions spec/install_spec.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export CI=1 # because we are running this on github actions and makes testing output easier
export TEST_MODE=1 # set to test mode in order to not run main() for test purposes

Describe 'install.sh'
# source the script without executing it immediately
. ./install.sh
Include install.sh

setup() {
VERSION="0.44.1"
DIRECTORY="./spec/tmp"
CI=1
TEST_MODE=1
}

# remove the dotenvx binary before each test
Expand Down Expand Up @@ -62,6 +62,55 @@ Describe 'install.sh'
End
End

Describe 'is_ci()'
It 'returns true'
When call is_ci
The status should equal 0
End
End

Describe 'progress_bar()'
It 'returns --no-progress-meter (because is_ci is true)'
When call progress_bar
The status should equal 0
The output should equal "--no-progress-meter"
End

Describe 'when is_ci is true'
mock_is_ci_false() {
CI=0
}

Before 'mock_is_ci_false'

It 'returns --progress-bar'
When call progress_bar
The status should equal 0
The output should equal "--progress-bar"
End
End
End

Describe 'is_test_mode()'
It 'returns true'
When call is_test_mode
The status should equal 0
End

Describe 'typical case when TEST_MODE is false'
mock_is_test_mode_false() {
TEST_MODE=0
}

Before 'mock_is_test_mode_false'

It 'returns false'
When call is_test_mode
The status should equal 1
End
End
End

Describe 'usage()'
It 'displays usage'
When call usage
Expand Down

0 comments on commit c70caa4

Please sign in to comment.