Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Bash
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SmartDataLab
public
CI-CD components
Bash
Commits
824fb9c3
Commit
824fb9c3
authored
Feb 22, 2023
by
Pierre Smeyers
Browse files
Options
Downloads
Patches
Plain Diff
chore: add bats test
parent
310a343a
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitlab-ci.yml
+2
-0
2 additions, 0 deletions
.gitlab-ci.yml
tests/bash-scripts.bash
+7
-0
7 additions, 0 deletions
tests/bash-scripts.bash
tests/scoped_variables.bats
+129
-0
129 additions, 0 deletions
tests/scoped_variables.bats
with
138 additions
and
0 deletions
.gitlab-ci.yml
+
2
−
0
View file @
824fb9c3
...
@@ -20,6 +20,8 @@ stages:
...
@@ -20,6 +20,8 @@ stages:
variables
:
variables
:
GITLAB_CI_FILES
:
"
templates/gitlab-ci-bash.yml"
GITLAB_CI_FILES
:
"
templates/gitlab-ci-bash.yml"
BASH_SHELLCHECK_FILES
:
"
*.sh"
BASH_SHELLCHECK_FILES
:
"
*.sh"
BASH_BATS_ENABLED
:
"
true"
BASH_BATS_LIBRARIES
:
"
bats-support@https://github.com/bats-core/bats-support/archive/v0.3.0.zip
bats-assert@https://github.com/bats-core/bats-assert/archive/v2.1.0.zip"
semantic-release
:
semantic-release
:
rules
:
rules
:
...
...
This diff is collapsed.
Click to expand it.
tests/bash-scripts.bash
0 → 100755
+
7
−
0
View file @
824fb9c3
#!/usr/bin/env bash
# load scripts from template
scripts
=
/tmp/bash-scripts.sh
echo
"#!/bin/bash"
>
$scripts
sed
-n
'/BEGSCRIPT/,/ENDSCRIPT/p'
"
$(
dirname
${
BASH_SOURCE
[0]
}
)
/../templates/gitlab-ci-bash.yml"
>>
$scripts
source
$scripts
This diff is collapsed.
Click to expand it.
tests/scoped_variables.bats
0 → 100644
+
129
−
0
View file @
824fb9c3
#!/usr/bin/env bats
load "$BATS_LIBRARIES_DIR/bats-support/load.bash"
load "$BATS_LIBRARIES_DIR/bats-assert/load.bash"
load 'bash-scripts'
function setup() {
export TESTVAR="default"
export scoped__TESTVAR__if__CONDVAR__equals__case1="case1"
export scoped__TESTVAR__if__CONDVAR__startswith__case2="case2"
export scoped__TESTVAR__if__CONDVAR__endswith__case3="case3"
export scoped__TESTVAR__if__CONDVAR__contains__case4="case4"
export scoped__TESTVAR__if__CONDVAR__in__apple__banana__orange="fruit"
}
function unscope_variables_and_check() {
unscope_variables
echo ">>> TESTVAR=$TESTVAR"
}
@test "no scoped var" {
# GIVEN
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=default"
}
@test "equals condition should match" {
# GIVEN
export CONDVAR=case1
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=case1"
}
@test "startswith condition should match" {
# GIVEN
export CONDVAR='case2 and bla bla'
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=case2"
}
@test "startswith condition should not match" {
# GIVEN
export CONDVAR='does not start with case2'
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=default"
}
@test "endswith condition should match" {
# GIVEN
export CONDVAR='ends with case3'
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=case3"
}
@test "endswith condition should not match" {
# GIVEN
export CONDVAR='does not end with case3...'
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=default"
}
@test "contains condition should match" {
# GIVEN
export CONDVAR='contains case4 in the middle'
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=case4"
}
@test "in condition should match 1" {
# GIVEN
export CONDVAR='apple'
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=fruit"
}
@test "in condition should match 2" {
# GIVEN
export CONDVAR='banana'
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=fruit"
}
@test "in condition should match 3" {
# GIVEN
export CONDVAR='orange'
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=fruit"
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment