-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Testing-Bash-with-BATS/requires-CI_COMMIT_REF_SLUG-environment-variable/
- Loading branch information
1 parent
251e64f
commit 393a95f
Showing
6 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
Testing-Bash-with-BATS/requires-CI_COMMIT_REF_SLUG-environment-variable/Readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
This folder contains a test example "requires CI_COMMIT_REF_SLUG environment variable" | ||
|
||
# Commands | ||
|
||
- Run test | ||
|
||
``` shell | ||
export LIBRARY_PATH="../../test/libs" | ||
|
||
${LIBRARY_PATH}/bats/bin/bats test.bats | ||
``` |
9 changes: 9 additions & 0 deletions
9
Testing-Bash-with-BATS/requires-CI_COMMIT_REF_SLUG-environment-variable/hello.bats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env "${LIBRARY_PATH}/bats/bin/bats" | ||
|
||
load "${LIBRARY_PATH}/bats-support/load" | ||
load "${LIBRARY_PATH}/bats-assert/load" | ||
|
||
@test "hello.sh should great the user" { | ||
run ./hello.sh John | ||
assert_output "Hello John" | ||
} |
3 changes: 3 additions & 0 deletions
3
Testing-Bash-with-BATS/requires-CI_COMMIT_REF_SLUG-environment-variable/hello.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
echo "Hello $1" |
16 changes: 16 additions & 0 deletions
16
Testing-Bash-with-BATS/requires-CI_COMMIT_REF_SLUG-environment-variable/test.bats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env "${LIBRARY_PATH}/bats/bin/bats" | ||
|
||
load "${LIBRARY_PATH}/bats-support/load" | ||
load "${LIBRARY_PATH}/bats-assert/load" | ||
|
||
|
||
|
||
@test "requires CI_COMMIT_REF_SLUG environment variable" { | ||
unset CI_COMMIT_REF_SLUG | ||
[ -z "${CI_COMMIT_REF_SLUG}" ] | ||
|
||
source ./test.sh | ||
run check_required_environment | ||
assert_failure | ||
assert_output --partial "CI_COMMIT_REF_SLUG" | ||
} |
21 changes: 21 additions & 0 deletions
21
Testing-Bash-with-BATS/requires-CI_COMMIT_REF_SLUG-environment-variable/test.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
# This script builds the nodejs image for the application | ||
# with its devDependencies as ${application}-candidate:${environment} | ||
# so that it can be used for testing in later pipeline stages | ||
raise() | ||
{ | ||
echo "${1}" >&2 | ||
} | ||
|
||
check_required_environment() { | ||
local required_env="CI_COMMIT_REF_SLUG CI_PROJECT_NAME" | ||
|
||
for reqvar in $required_env | ||
do | ||
if [ -z ${!reqvar} ] | ||
then | ||
raise "missing ENVIRONMENT ${reqvar}!" | ||
return 1 | ||
fi | ||
done | ||
} |