Skip to content

Commit

Permalink
#5 add a new example
Browse files Browse the repository at this point in the history
add Testing-Bash-with-BATS/requires-CI_COMMIT_REF_SLUG-environment-variable/
  • Loading branch information
xuyuji9000 committed Oct 23, 2021
1 parent 251e64f commit 393a95f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Testing-Bash-with-BATS/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ This folder trys to document the learning about article [Testing Bash with BATS]
- [compare-script-execution-and-source-execution](./compare-script-execution-and-source-execution/Readme.md)

- [annotate-refactored-build.sh](./annotate-refactored-build.sh/Readme.md)

- [requires-CI_COMMIT_REF_SLUG-environment-variable](requires-CI_COMMIT_REF_SLUG-environment-variable/Readme.md)
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
```
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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "Hello $1"
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"
}
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
}

0 comments on commit 393a95f

Please sign in to comment.