Skip to content

Commit

Permalink
fix: add run in TeamCity check and add bats-file missing fct (#73)
Browse files Browse the repository at this point in the history
# Description
### Summary:

Add logic to check if docker run is done on a teamcity server. Also add
the missing bats-file function which was merged in PR #61 at
bats-core/bats-file#61

---

# Checklist:

### Code related
- [ ] I have made corresponding changes to the documentation (i.e.:
function/class, script header, README.md)
- [x] I have commented hard-to-understand code 
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] All tests pass locally with my changes (Check `tests/README.md`
for local testing procedure)
- [x] My commit messages follow the [conventional
commits](https://www.conventionalcommits.org) specification. See
`commit_msg_reference.md` in the repository root for details

### PR creation related 
- [x] My pull request `base ref` branch is set to the `dev` branch (the
_build-system_ won't be triggered otherwise)
- [x] My pull request branch is up-to-date with the `dev` branch (the
_build-system_ will reject it otherwise)

### PR description related 
- [x] I have included a quick summary of the changes
- [x] I have indicated the related issue's id with `# <issue-id>` if
changes are of type `fix`

 ## Note for repository admins
 ### Release PR related
- Only repository admins have the privilege to `push/merge` on the
default branch (ie: `main`) and the `release` branch.
- Keep PR in `draft` mode until all the release reviewers are ready to
push the release.
- Once a PR from `release` -> `main` branch is created (not in draft
mode), it triggers the _build-system_ test
- On merge to the `main` branch, it triggers the _semantic-release
automation_
  • Loading branch information
RedLeader962 authored Jan 22, 2024
2 parents c28acaa + 52e0575 commit f9726fe
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ ENV SRC_CODE_PATH="/code/${CONTAINER_PROJECT_ROOT_NAME}"
ARG N2ST_BATS_TESTING_TOOLS_RELATIVE_PATH
ENV N2ST_BATS_TESTING_TOOLS_RELATIVE_PATH=${N2ST_BATS_TESTING_TOOLS_RELATIVE_PATH:?'Build argument needs to be set and non-empty.'}

ARG TEAMCITY_VERSION
ENV TEAMCITY_VERSION=${TEAMCITY_VERSION}

ENV TERM=${TERM:-"xterm-256color"}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ ENV SRC_CODE_PATH="/code/${CONTAINER_PROJECT_ROOT_NAME}"
ARG N2ST_BATS_TESTING_TOOLS_RELATIVE_PATH
ENV N2ST_BATS_TESTING_TOOLS_RELATIVE_PATH=${N2ST_BATS_TESTING_TOOLS_RELATIVE_PATH:?'Build argument needs to be set and non-empty.'}

ARG TEAMCITY_VERSION
ENV TEAMCITY_VERSION=${TEAMCITY_VERSION}

LABEL org.opencontainers.image.authors="luc.coupal.1@ulaval.ca"

SHELL ["/bin/bash", "-e", "-c"]
Expand Down
43 changes: 43 additions & 0 deletions tests/bats_testing_tools/bats_helper_functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,46 @@ function fake_IS_TEAMCITY_RUN() {
TEAMCITY_VERSION=fake
fi
}

# ====bats-file utility============================================================================

# Temporary workaround for missing implementation of "assert_file_not_contains"
# ToDo: remove when bats-file PR #61 is merge
# - PR #61 at https://github.com/bats-core/bats-file/pull/61
#
# Credit https://github.com/bats-core/bats-file/pull/61
#
# Fail and display path of the file (or directory) if it does contain a string.
# This function is the logical complement of `assert_file_contains'.
#
# Globals:
# BATSLIB_FILE_PATH_REM
# BATSLIB_FILE_PATH_ADD
# Arguments:
# $1 - path
# $2 - regex
# Returns:
# 0 - file does not contain regex
# 1 - otherwise
# Outputs:
# STDERR - details, on failure
assert_file_not_contains() {
local -r file="$1"
local -r regex="$2"

if [[ ! -f "$file" ]]; then
local -r rem="${BATSLIB_FILE_PATH_REM-}"
local -r add="${BATSLIB_FILE_PATH_ADD-}"
batslib_print_kv_single 4 'path' "${file/$rem/$add}" 'regex' "$regex" \
| batslib_decorate 'file does not exist' \
| fail

elif grep -q "$regex" "$file"; then
local -r rem="${BATSLIB_FILE_PATH_REM-}"
local -r add="${BATSLIB_FILE_PATH_ADD-}"
batslib_print_kv_single 4 'path' "${file/$rem/$add}" 'regex' "$regex" \
| batslib_decorate 'file contains regex' \
| fail

fi
}
1 change: 1 addition & 0 deletions tests/bats_testing_tools/run_bats_tests_in_docker.bash
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ docker build \
--build-arg "CONTAINER_PROJECT_ROOT_NAME=${PROJECT_GIT_NAME}" \
--build-arg BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 \
--build-arg N2ST_BATS_TESTING_TOOLS_RELATIVE_PATH="$N2ST_BATS_TESTING_TOOLS_RELATIVE_PATH" \
--build-arg "TEAMCITY_VERSION=${TEAMCITY_VERSION}" \
--file "${N2ST_BATS_TESTING_TOOLS_ABS_PATH}/Dockerfile.bats-core-code-isolation.${BATS_DOCKERFILE_DISTRO}" \
--tag n2st-bats-test-code-isolation/"${PROJECT_GIT_NAME}" \
.
Expand Down

0 comments on commit f9726fe

Please sign in to comment.