-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2cb0245
commit 411a6db
Showing
12 changed files
with
315 additions
and
13 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
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 |
---|---|---|
|
@@ -73,7 +73,6 @@ Ssl | |
Suboptimal | ||
TBD | ||
Terminalizer | ||
Twig CS Fixer | ||
UAT | ||
UI | ||
UUID | ||
|
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
vendor | ||
node_modules | ||
!package-lock.json |
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 |
---|---|---|
|
@@ -136,7 +136,7 @@ build() { | |
echo "Copy combined dir into the container." | ||
docker compose cp "${combined_repo_dir}/." mkdocs:"/tmp/build" | ||
docker compose exec mkdocs git config --global --add safe.directory "/tmp/build" | ||
# The credentials below are only used to produce some entermediate commits | ||
# The credentials below are only used to produce some intermediate commits | ||
# while building the docs. They are not used to push the code. | ||
docker compose exec mkdocs git config --global user.name "Deployment robot" | ||
docker compose exec mkdocs git config --global user.email "[email protected]" | ||
|
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,40 @@ | ||
#!/usr/bin/env bash | ||
## | ||
# Run DrevOps docs tests in CI. | ||
# | ||
# LCOV_EXCL_START | ||
|
||
set -eu | ||
[ "${DREVOPS_DEBUG-}" = "1" ] && set -x | ||
|
||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" | ||
|
||
SCRIPTS_DIR="${ROOT_DIR}/docs/.utils" | ||
|
||
TEST_DIR="${ROOT_DIR}/docs/.utils/tests" | ||
|
||
# ------------------------------------------------------------------------------ | ||
|
||
# Configure git username and email if it is not set. | ||
[ "$(git config --global user.name)" = "" ] && echo "==> Configuring global git user name" && git config --global user.name "Test user" | ||
[ "$(git config --global user.email)" = "" ] && echo "==> Configuring global git user email" && git config --global user.email "[email protected]" | ||
|
||
# Create stub of local framework. | ||
docker network create amazeeio-network 2>/dev/null || true | ||
|
||
echo "==> Run docs tests." | ||
|
||
[ ! -d "${TEST_DIR}/node_modules" ] && echo " > Installing test Node dependencies into ${TEST_DIR}." && npm --prefix="${TEST_DIR}" ci | ||
|
||
bats() { | ||
pushd "${ROOT_DIR}" >/dev/null || exit 1 | ||
if [ -n "${DREVOPS_DEV_TEST_COVERAGE_DIR:-}" ]; then | ||
mkdir -p "${DREVOPS_DEV_TEST_COVERAGE_DIR}" | ||
kcov --include-pattern=.sh,.bash --bash-parse-files-in-dir="${SCRIPTS_DIR}","${TEST_DIR}" --exclude-pattern=vendor,node_modules "${DREVOPS_DEV_TEST_COVERAGE_DIR}" "${TEST_DIR}/node_modules/.bin/bats" "$@" | ||
else | ||
"${TEST_DIR}/node_modules/.bin/bats" "$@" | ||
fi | ||
popd >/dev/null || exit 1 | ||
} | ||
|
||
bats "${TEST_DIR}/bats/docs.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,164 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Helpers related to DrevOps common testing functionality. | ||
# | ||
# In some cases, shell may report platform incorrectly. Run with forced platform: | ||
# DOCKER_DEFAULT_PLATFORM=linux/amd64 bats --tap tests/bats/test.bats | ||
# | ||
# shellcheck disable=SC2155,SC2119,SC2120,SC2044,SC2294 | ||
# | ||
|
||
################################################################################ | ||
# BATS HOOK IMPLEMENTATIONS # | ||
################################################################################ | ||
|
||
setup() { | ||
# The root directory of the project. | ||
export ROOT_DIR="$(dirname "$(cd "$(dirname "${BATS_TEST_DIRNAME}")/../../.." && pwd)")" | ||
|
||
[ ! -d "${ROOT_DIR}/.drevops" ] && echo 'ERROR: The test should be run from the ".drevops" directory.' && exit 1 | ||
|
||
# Register a path to libraries. | ||
export BATS_LIB_PATH="${BATS_TEST_DIRNAME}/../node_modules" | ||
bats_load_library bats-helpers | ||
|
||
## | ||
## Application test directories structure setup. | ||
## | ||
|
||
# To run installation tests, several fixture directories are required. | ||
# They are defined and created in setup() test method. | ||
# | ||
# Root build directory where the rest of fixture directories located. | ||
# The "build" in this context is a place to store assets produced by the | ||
# installer script during the test. | ||
export BUILD_DIR="${BUILD_DIR:-"${BATS_TEST_TMPDIR//\/\//\/}/drevops-$(date +%s)"}" | ||
|
||
# Directory where the installer script is executed. | ||
# May have existing project files (e.g. from previous installations) or be | ||
# empty (to facilitate brand-new install). | ||
export CURRENT_PROJECT_DIR="${BUILD_DIR}/star_wars" | ||
|
||
# Directory where the installer script will be sourcing the instance of DrevOps. | ||
# As a part of test setup, the local copy of DrevOps at the last commit is | ||
# copied to this location. This means that during development of tests local | ||
# changes need to be committed. | ||
export LOCAL_REPO_DIR="${BUILD_DIR}/local_repo" | ||
|
||
fixture_prepare_dir "${BUILD_DIR}" | ||
fixture_prepare_dir "${CURRENT_PROJECT_DIR}" | ||
fixture_prepare_dir "${LOCAL_REPO_DIR}" | ||
|
||
# Allow to override debug variables from environment when developing tests. | ||
export DREVOPS_DEBUG="${TEST_DREVOPS_DEBUG:-}" | ||
|
||
## | ||
## SUT files setup. | ||
## | ||
|
||
# Copy DrevOps at the last commit. | ||
fixture_export_codebase "${LOCAL_REPO_DIR}" "${ROOT_DIR}" >/dev/null | ||
|
||
# Prepare global git config and ignore files required for testing cleanup scenarios. | ||
prepare_global_gitconfig | ||
prepare_global_gitignore | ||
|
||
## | ||
## Setting debug mode. | ||
## | ||
|
||
# Print debug if "--verbose-run" is passed or TEST_DREVOPS_DEBUG is set to "1". | ||
if [ "${BATS_VERBOSE_RUN:-}" = "1" ] || [ "${TEST_DREVOPS_DEBUG:-}" = "1" ]; then | ||
echo "Verbose run enabled." >&3 | ||
echo "BUILD_DIR: ${BUILD_DIR}" >&3 | ||
export RUN_STEPS_DEBUG=1 | ||
fi | ||
|
||
# Change directory to the current project directory for each test. Tests | ||
# requiring to operate outside of CURRENT_PROJECT_DIR (like deployment tests) | ||
# should change directory explicitly within their tests. | ||
pushd "${CURRENT_PROJECT_DIR}" >/dev/null || exit 1 | ||
} | ||
|
||
teardown() { | ||
restore_global_gitignore | ||
popd >/dev/null || cd "${ROOT_DIR}" || exit 1 | ||
} | ||
|
||
# Print step. | ||
step() { | ||
# Using prefix different from command prefix in SUT for easy debug. | ||
echo "**> STEP: ${1}" >&3 | ||
} | ||
|
||
# Print sub-step. | ||
substep() { | ||
echo " > ${1}" >&3 | ||
} | ||
|
||
git_init() { | ||
local allow_receive_update="${1:-0}" | ||
local dir="${2:-$(pwd)}" | ||
|
||
assert_not_git_repo "${dir}" | ||
git --work-tree="${dir}" --git-dir="${dir}/.git" init >/dev/null | ||
|
||
if [ "${allow_receive_update:-}" -eq 1 ]; then | ||
git --work-tree="${dir}" --git-dir="${dir}/.git" config receive.denyCurrentBranch updateInstead >/dev/null | ||
fi | ||
} | ||
|
||
git_add_all_commit() { | ||
local message="${1}" | ||
local dir="${2:-$(pwd)}" | ||
|
||
assert_git_repo "${dir}" | ||
|
||
git --work-tree="${dir}" --git-dir="${dir}/.git" add -A | ||
git --work-tree="${dir}" --git-dir="${dir}/.git" commit -m "${message}" >/dev/null | ||
commit=$(git --work-tree="${dir}" --git-dir="${dir}/.git" rev-parse HEAD) | ||
echo "${commit}" | ||
} | ||
|
||
|
||
prepare_global_gitconfig() { | ||
git config --global init.defaultBranch >/dev/null || git config --global init.defaultBranch "main" | ||
} | ||
|
||
prepare_global_gitignore() { | ||
filename="${HOME}/.gitignore" | ||
filename_backup="${filename}".bak | ||
|
||
if git config --global --list | grep -q core.excludesfile; then | ||
git config --global core.excludesfile >/tmp/git_config_global_exclude | ||
fi | ||
|
||
[ -f "${filename}" ] && cp "${filename}" "${filename_backup}" | ||
|
||
cat <<EOT >"${filename}" | ||
## | ||
## Temporary files generated by various OSs and IDEs | ||
## | ||
Thumbs.db | ||
._* | ||
.DS_Store | ||
.idea | ||
.idea/* | ||
*.sublime* | ||
.project | ||
.netbeans | ||
.vscode | ||
.vscode/* | ||
nbproject | ||
nbproject/* | ||
EOT | ||
|
||
git config --global core.excludesfile "${filename}" | ||
} | ||
|
||
restore_global_gitignore() { | ||
filename=${HOME}/.gitignore | ||
filename_backup="${filename}".bak | ||
[ -f "${filename_backup}" ] && cp "${filename_backup}" "${filename}" | ||
[ -f "/tmp/git_config_global_exclude" ] && git config --global core.excludesfile "$(cat /tmp/git_config_global_exclude)" | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
{ | ||
"name": "drevops-tests", | ||
"version": "1.0.0", | ||
"description": "Packages used for testing of DrevOps", | ||
"license": "GPL-2.0-or-later", | ||
"devDependencies": { | ||
"bats-helpers": "npm:@drevops/bats-helpers@^1.3.1" | ||
} | ||
} |
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
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
Oops, something went wrong.