Skip to content

Commit ba45357

Browse files
committed
Add basic tests.
1 parent 20a3459 commit ba45357

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

.github/workflows/tests.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
name: Tests
3+
4+
on:
5+
pull_request:
6+
push:
7+
branches: [ main, wip ]
8+
9+
schedule:
10+
# Daily at 00:00:00 UTC.
11+
# @see https://crontab.cronhub.io/
12+
- cron: "0 0 * * *"
13+
14+
workflow_dispatch:
15+
inputs:
16+
debug_enabled:
17+
type: boolean
18+
description: Debug with tmate
19+
required: false
20+
default: false
21+
22+
concurrency:
23+
group: ${{ github.workflow }}-${{ github.ref }}
24+
cancel-in-progress: true
25+
26+
# This is required for "gautamkrishnar/keepalive-workflow", see "ddev/github-action-add-on-test".
27+
permissions:
28+
actions: write
29+
30+
jobs:
31+
tests:
32+
strategy:
33+
matrix:
34+
ddev_version: [ stable, HEAD ]
35+
fail-fast: false
36+
37+
runs-on: ubuntu-latest
38+
39+
steps:
40+
- uses: ddev/github-action-add-on-test@v2 # https://github.com/marketplace/actions/ddev-add-on-test
41+
with:
42+
ddev_version: ${{ matrix.ddev_version }}
43+
token: ${{ secrets.GITHUB_TOKEN }}
44+
debug_enabled: ${{ github.event.inputs.debug_enabled }}
45+
addon_repository: ${{ env.GITHUB_REPOSITORY }}
46+
addon_ref: ${{ env.GITHUB_REF }}

tests/test.bats

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
setup() {
2+
set -eu -o pipefail
3+
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.."
4+
export DIR
5+
export TESTDIR=~/tmp/drupal-xb-dev
6+
mkdir -p $TESTDIR
7+
export PROJNAME=drupal-xb-dev
8+
export DDEV_NONINTERACTIVE=true
9+
ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true
10+
cd "${TESTDIR}"
11+
ddev config --project-name=${PROJNAME}
12+
ddev start -y >/dev/null
13+
}
14+
15+
check_commands_installed() {
16+
# Get the available commands.
17+
ddev_help_output=$(ddev help)
18+
# Find command files in the add-on.
19+
cd ${TESTDIR}
20+
tmp_file=$(mktemp)
21+
find "$GITHUB_WORKSPACE/commands" -name 'xb-*' -exec basename {} \; > "$tmp_file"
22+
# Check that all the command files got copied to the project upon installation.
23+
errors=""
24+
while read -r command_name; do
25+
# Skip xb-cypress since it's expected not to be installed on CI.
26+
if [ "$command_name" = "xb-cypress" ]; then
27+
continue
28+
fi
29+
if ! echo "$ddev_help_output" | grep -q "$command_name"; then
30+
errors="${errors}Error: ${command_name} is not installed.\n"
31+
fi
32+
done < "$tmp_file"
33+
rm -f "$tmp_file"
34+
# Display errors and fail, if any.
35+
if [ -n "$errors" ]; then
36+
printf "%b" "$errors"
37+
return 1
38+
fi
39+
echo "All commands were installed."
40+
}
41+
42+
health_checks() {
43+
check_commands_installed
44+
ddev exec "curl -s https://localhost:443/"
45+
}
46+
47+
teardown() {
48+
set -eu -o pipefail
49+
cd ${TESTDIR} || ( printf "unable to cd to %s\n" ${TESTDIR} && exit 1 )
50+
ddev delete -Oy ${PROJNAME} >/dev/null 2>&1
51+
[ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR}
52+
}
53+
54+
@test "install from directory" {
55+
set -eu -o pipefail
56+
cd ${TESTDIR}
57+
echo "# ddev add-on get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
58+
ddev add-on get "${DIR}"
59+
ddev restart
60+
health_checks
61+
}
62+
63+
# bats test_tags=release
64+
@test "install from release" {
65+
set -eu -o pipefail
66+
cd ${TESTDIR} || ( printf "unable to cd to %s\n" ${TESTDIR} && exit 1 )
67+
echo "# ddev add-on get TravisCarden/ddev-drupal-xb-dev with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
68+
ddev add-on get TravisCarden/ddev-drupal-xb-dev
69+
ddev restart >/dev/null
70+
health_checks
71+
}

0 commit comments

Comments
 (0)