From a1f66b36d91f84fc768d79d31457fc5f84f1b1f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20L=C3=B3pez?= Date: Fri, 30 Aug 2024 15:01:08 +0200 Subject: [PATCH] Added basic tests --- .github/workflows/tests.yml | 43 ++++++++++++++++++++++++++ commands/host/includes/aljibe_includes | 1 - tests/test.bats | 40 ++++++++++++++++++++++++ tests/testdata/.gitmanaged | 0 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/tests.yml create mode 100644 tests/test.bats create mode 100644 tests/testdata/.gitmanaged diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..f8c42b3 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,43 @@ +name: tests +on: + pull_request: + push: + branches: [ main ] + + schedule: + - cron: '00 07 * * *' + + workflow_dispatch: + inputs: + debug_enabled: + type: boolean + description: Debug with tmate + required: false + default: false + +# This is required for "gautamkrishnar/keepalive-workflow", see "ddev/github-action-add-on-test" +permissions: + actions: write + +jobs: + tests: + strategy: + matrix: + ddev_version: [stable, HEAD] + fail-fast: false + + runs-on: ubuntu-latest + + steps: + - name: Run ShellCheck + uses: azohra/shell-linter@latest + with: + path: "scripts,commands" + + - uses: ddev/github-action-add-on-test@v2 + with: + ddev_version: ${{ matrix.ddev_version }} + token: ${{ secrets.GITHUB_TOKEN }} + debug_enabled: ${{ github.event.inputs.debug_enabled }} + addon_repository: ${{ env.GITHUB_REPOSITORY }} + addon_ref: ${{ env.GITHUB_REF }} diff --git a/commands/host/includes/aljibe_includes b/commands/host/includes/aljibe_includes index b432147..c42c9d8 100644 --- a/commands/host/includes/aljibe_includes +++ b/commands/host/includes/aljibe_includes @@ -26,7 +26,6 @@ extract_argument() { run_commands() { local CMDS=("$@") if [ ${#CMDS[@]} -gt 0 ]; then - echo echo -e "\033[32mRunning commands: \033[0m\n" for cmd in "${CMDS[@]}"; do echo "- running $cmd ... " diff --git a/tests/test.bats b/tests/test.bats new file mode 100644 index 0000000..a231687 --- /dev/null +++ b/tests/test.bats @@ -0,0 +1,40 @@ +setup() { + set -eu -o pipefail + export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.." + export TESTDIR=~/tmp/test-addon-backstopjs + mkdir -p $TESTDIR + export PROJNAME=test-addon-backstopjs + export DDEV_NON_INTERACTIVE=true + ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true + cd "${TESTDIR}" + ddev config --project-name=${PROJNAME} + ddev start -y >/dev/null +} + +teardown() { + set -eu -o pipefail + cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 ) + ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 + [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} +} + +@test "install from directory" { + set -eu -o pipefail + cd ${TESTDIR} + echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 + ddev get ${DIR} + ddev restart + + ddev aljibe-assistant --auto + +} + +@test "install from release" { + set -eu -o pipefail + cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 ) + echo "# ddev get drud/ddev-addon-template with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 + ddev get drud/ddev-addon-template + ddev restart >/dev/null + # Do something useful here that verifies the add-on + # ddev exec "curl -s elasticsearch:9200" | grep "${PROJNAME}-elasticsearch" +} diff --git a/tests/testdata/.gitmanaged b/tests/testdata/.gitmanaged new file mode 100644 index 0000000..e69de29