Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic tests #8

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 10 additions & 65 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,84 +5,29 @@ on:
branches: [ main ]

schedule:
- cron: '25 08 * * *'
- cron: '25 10 * * *'

workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: Debug with tmate
description: 'Debug with tmate set "debug_enabled"'
required: false
default: false

defaults:
run:
shell: bash

env:
NIGHTLY_DDEV_PR_URL: "https://nightly.link/ddev/ddev/actions/runs/1720215802/ddev-linux-amd64.zip"
# Allow ddev get to use a github token to prevent rate limiting by tests
DDEV_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Allow `--HEAD` flag when running tests against HEAD
HOMEBREW_NO_INSTALL_FROM_API: 1
default: "false"

jobs:
tests:
defaults:
run:
shell: bash

strategy:
matrix:
ddev_version: [stable, HEAD]
# ddev_version: [stable, edge, HEAD, PR]
fail-fast: false

runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Environment setup
run: |
brew install bats-core mkcert
mkcert -install

- name: Use ddev stable
if: matrix.ddev_version == 'stable'
run: brew install ddev/ddev/ddev

- name: Use ddev edge
if: matrix.ddev_version == 'edge'
run: brew install ddev/ddev-edge/ddev

- name: Use ddev HEAD
if: matrix.ddev_version == 'HEAD'
run: brew install --HEAD ddev/ddev/ddev

- name: Use ddev PR
if: matrix.ddev_version == 'PR'
run: |
curl -sSL -o ddev_linux.zip ${NIGHTLY_DDEV_PR_URL}
unzip ddev_linux.zip
mv ddev /usr/local/bin/ddev && chmod +x /usr/local/bin/ddev

- name: Download docker images
run: mkdir junk && pushd junk && ddev config --auto && ddev debug download-images >/dev/null

- name: tmate debugging session
uses: mxschmitt/action-tmate@v3
- uses: ddev/github-action-add-on-test@v0
with:
limit-access-to-actor: true
github-token: ${{ secrets.GITHUB_TOKEN }}
if: github.event.inputs.debug_enabled == 'true'

- name: tests
run: bats tests

# keepalive-workflow adds a dummy commit if there's no other action here, keeps
# GitHub from turning off tests after 60 days
- uses: gautamkrishnar/keepalive-workflow@v1
if: matrix.ddev_version == 'stable'
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 }}
33 changes: 20 additions & 13 deletions tests/test.bats
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
setup() {
set -eu -o pipefail

export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.."
export TESTDIR=~/tmp/test-addon-template
export TESTDIR=~/tmp/ddev-xhgui
mkdir -p $TESTDIR
export PROJNAME=test-addon-template
export PROJNAME=ddev-xhgui
export DDEV_NON_INTERACTIVE=true
ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true
ddev delete -Oy ${PROJNAME} || true
cd "${TESTDIR}"
ddev config --project-name=${PROJNAME}
ddev start -y >/dev/null
ddev start -y
echo "# ddev started at $(date)" >&3
}

teardown() {
set -eu -o pipefail
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
ddev delete -Oy ${PROJNAME} >/dev/null 2>&1
ddev delete -Oy ${PROJNAME}
[ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR}
}

health_checks() {
ddev exec "curl -s xhgui:80" | grep "XHGui - Run list"
}

@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
# Do something here to verify functioning extra service
# For extra credit, use a real CMS with actual config.
# ddev exec "curl -s elasticsearch:9200" | grep "${PROJNAME}-elasticsearch"

# Check service works
health_checks
}

@test "install from release" {
set -eu -o pipefail
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
echo "# ddev get ddev/ddev-addon-template with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
ddev get ddev/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"
echo "# ddev get tyler36/ddev-xhgui with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
ddev get tyler36/ddev-xhgui
ddev restart

# Check service works
health_checks
}