2021-06-10 00:44:58 +02:00
|
|
|
common_setup() {
|
|
|
|
load 'node_modules/bats-support/load'
|
|
|
|
load 'node_modules/bats-assert/load'
|
|
|
|
|
|
|
|
# Dagger Binary
|
2021-06-10 12:28:40 +02:00
|
|
|
# FIXME: `command -v` must be wrapped in a sub-bash,
|
|
|
|
# otherwise infinite recursion when DAGGER_BINARY is not set.
|
|
|
|
export DAGGER="${DAGGER_BINARY:-$(bash -c 'command -v dagger')}"
|
2021-06-10 00:44:58 +02:00
|
|
|
|
2021-09-23 20:07:09 +02:00
|
|
|
# Set the project to the universe directory (so tests can run from anywhere)
|
2021-06-10 00:44:58 +02:00
|
|
|
UNIVERSE="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
|
2021-09-23 20:07:09 +02:00
|
|
|
DAGGER_PROJECT="$UNIVERSE"
|
|
|
|
export DAGGER_PROJECT
|
2021-06-10 00:44:58 +02:00
|
|
|
|
2021-10-05 01:42:55 +02:00
|
|
|
# Force plain printing for error reporting
|
|
|
|
DAGGER_LOG_FORMAT="plain"
|
2021-06-10 00:44:58 +02:00
|
|
|
export DAGGER_LOG_FORMAT
|
|
|
|
|
2021-09-23 20:07:09 +02:00
|
|
|
# Sandbox project.
|
|
|
|
DAGGER_SANDBOX="$(mktemp -d -t dagger-project-XXXXXX)"
|
2021-06-10 00:44:58 +02:00
|
|
|
export DAGGER_SANDBOX
|
2021-09-23 20:07:09 +02:00
|
|
|
dagger init --project "$DAGGER_SANDBOX"
|
2021-06-10 00:44:58 +02:00
|
|
|
|
|
|
|
# allows the use of `sops`
|
|
|
|
SOPS_AGE_KEY_FILE=~/.config/dagger/keys.txt
|
|
|
|
export SOPS_AGE_KEY_FILE
|
|
|
|
}
|
|
|
|
|
|
|
|
# dagger helper to execute the right binary
|
|
|
|
dagger() {
|
|
|
|
"${DAGGER}" "$@"
|
|
|
|
}
|
|
|
|
|
2021-09-23 20:07:09 +02:00
|
|
|
# copy an environment from the current project to the sandbox.
|
2021-06-10 00:44:58 +02:00
|
|
|
#
|
|
|
|
# this is needed if the test requires altering inputs without dirtying the
|
|
|
|
# current environment.
|
|
|
|
# Usage:
|
|
|
|
# copy_to_sandbox myenv
|
|
|
|
# dagger input secret -w "$DAGGER_SANDBOX" -e myenv "temporary change"
|
2021-09-23 20:07:09 +02:00
|
|
|
# dagger up --project "$DAGGER_SANDBOX" -e myenv
|
2021-06-18 19:15:48 +02:00
|
|
|
#
|
|
|
|
# To use testdata directory in tests, add the package name as second flag
|
|
|
|
# Usage:
|
|
|
|
# copy_to_sandbox myenv mypackage
|
2021-06-10 00:44:58 +02:00
|
|
|
copy_to_sandbox() {
|
|
|
|
local name="$1"
|
2021-09-23 20:07:09 +02:00
|
|
|
local source="$DAGGER_PROJECT"/.dagger/env/"$name"
|
2021-06-10 00:44:58 +02:00
|
|
|
local target="$DAGGER_SANDBOX"/.dagger/env/"$name"
|
|
|
|
|
|
|
|
cp -a "$source" "$target"
|
2021-06-18 19:15:48 +02:00
|
|
|
|
|
|
|
if [ -d "$2" ]; then
|
|
|
|
local package="$2"
|
2021-09-23 20:07:09 +02:00
|
|
|
local source_package="$DAGGER_PROJECT"/"$package"
|
2021-06-18 19:15:48 +02:00
|
|
|
local target_package="$DAGGER_SANDBOX"/
|
|
|
|
|
|
|
|
cp -a "$source_package" "$target_package"
|
|
|
|
fi
|
2021-06-10 12:28:40 +02:00
|
|
|
}
|
2021-08-30 18:19:00 +02:00
|
|
|
|
2021-08-19 17:11:33 +02:00
|
|
|
# Check if there is a localstack instance.
|
2021-08-18 15:09:28 +02:00
|
|
|
#
|
2021-08-19 17:11:33 +02:00
|
|
|
# This is needed to do docs test in the CI.
|
2021-08-18 15:09:28 +02:00
|
|
|
skip_unless_local_localstack() {
|
2021-08-23 14:42:03 +02:00
|
|
|
if [ "$(curl -s http://localhost:4566)" = '{"status": "running"}' ]; then
|
2021-08-18 15:09:28 +02:00
|
|
|
echo "Localstack available"
|
|
|
|
else
|
|
|
|
skip "Localstack not available"
|
|
|
|
fi
|
|
|
|
}
|
2021-06-18 18:03:59 +02:00
|
|
|
|
|
|
|
# Check if there is a local kubernetes cluster.
|
|
|
|
#
|
|
|
|
# This is need to do kubernetes test in the CI.
|
|
|
|
skip_unless_local_kube() {
|
2021-09-10 10:44:12 +02:00
|
|
|
if [ -f ~/.kube/config ] && grep -q "127.0.0.1" ~/.kube/config &> /dev/null; then
|
2021-06-18 18:03:59 +02:00
|
|
|
echo "Kubernetes available"
|
|
|
|
else
|
|
|
|
skip "local kubernetes cluster not available"
|
|
|
|
fi
|
2021-08-31 14:39:45 +02:00
|
|
|
}
|
|
|
|
|
2021-09-09 13:03:07 +02:00
|
|
|
# Check if there is a local endpoint.
|
|
|
|
#
|
|
|
|
# This is necessary to do test with endpoint.
|
|
|
|
# Usage:
|
|
|
|
# skip_unless_endpoint_available "localhost:8080"
|
|
|
|
skip_unless_endpoint_available() {
|
|
|
|
local endpoint="$1"
|
|
|
|
|
|
|
|
curl "$endpoint"
|
|
|
|
}
|
|
|
|
|
2021-08-31 14:39:45 +02:00
|
|
|
# Cleanup local Localstack instances
|
|
|
|
setup_localstack() {
|
|
|
|
if [ "$(curl -s http://localhost:4566)" = '{"status": "running"}' ] && \
|
|
|
|
[ "$GITHUB_ACTIONS" != "true" ]; then
|
|
|
|
echo "Cleanup local LOCALSTACK"
|
2021-10-05 01:42:55 +02:00
|
|
|
|
2021-08-31 14:39:45 +02:00
|
|
|
# S3 buckets cleanup
|
|
|
|
aws --endpoint-url=http://localhost:4566 s3 rm s3://dagger-ci || true
|
|
|
|
aws --endpoint-url=http://localhost:4566 s3 mb s3://dagger-ci || true
|
2021-10-05 01:42:55 +02:00
|
|
|
|
2021-08-31 14:39:45 +02:00
|
|
|
# ECR repositories cleanup
|
|
|
|
aws --endpoint-url=http://localhost:4566 ecr delete-repository --repository-name dagger-ci || true
|
|
|
|
aws --endpoint-url=http://localhost:4566 ecr create-repository --repository-name dagger-ci || true
|
|
|
|
fi
|
2021-06-18 18:03:59 +02:00
|
|
|
}
|