Skip to content

Commit 18b98c1

Browse files
authored
refactor: load Bats libraries, add v1.24.2 constraint, fixes #33, fixes #37, fixes #62 (#70)
1 parent 11d5274 commit 18b98c1

7 files changed

+163
-30
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: 🐞 Bug report or Support Request
2+
description: Create a report to help us improve.
3+
labels: [bug]
4+
body:
5+
- type: checkboxes
6+
attributes:
7+
label: Preliminary checklist
8+
description: Please complete the following checks before submitting an issue.
9+
options:
10+
- label: I am using the latest stable version of DDEV
11+
required: true
12+
- label: I am using the latest stable version of this add-on
13+
required: true
14+
- type: textarea
15+
attributes:
16+
label: Expected Behavior
17+
description: What did you expect to happen?
18+
validations:
19+
required: true
20+
- type: textarea
21+
attributes:
22+
label: Actual Behavior
23+
description: What actually happened instead?
24+
validations:
25+
required: true
26+
- type: textarea
27+
attributes:
28+
label: Steps To Reproduce
29+
description: Specific steps to reproduce the behavior.
30+
placeholder: |
31+
1. In this environment...
32+
2. With this config...
33+
3. Run `...`
34+
4. See error...
35+
validations:
36+
required: false
37+
- type: textarea
38+
attributes:
39+
label: Anything else?
40+
description: |
41+
Links? References? Screenshots? Anything that will give us more context about your issue!
42+
43+
💡 Attach images or log files by clicking this area to highlight it and dragging files in.
44+
validations:
45+
required: false
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: 🚀 Feature request
2+
description: Suggest an idea for this project.
3+
labels: [enhancement]
4+
body:
5+
- type: checkboxes
6+
attributes:
7+
label: Is there an existing issue for this?
8+
description: Please search existing issues to see if one already exists for your request.
9+
options:
10+
- label: I have searched the existing issues
11+
required: true
12+
- type: textarea
13+
attributes:
14+
label: Is your feature request related to a problem?
15+
description: Clearly and concisely describe the problem. (Ex. I'm always frustrated when...)
16+
validations:
17+
required: true
18+
- type: textarea
19+
attributes:
20+
label: Describe your solution
21+
description: Clearly and concisely describe what you want to happen.
22+
validations:
23+
required: true
24+
- type: textarea
25+
attributes:
26+
label: Describe alternatives
27+
description: Clearly and concisely describe any alternative solutions or features you've considered.
28+
validations:
29+
required: false
30+
- type: textarea
31+
attributes:
32+
label: Additional context
33+
description: Add any other context or screenshots about the feature request.
34+
validations:
35+
required: false

.github/PULL_REQUEST_TEMPLATE.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## The Issue
2+
3+
- #<issue number>
4+
5+
<!-- Provide a brief description of the issue. -->
6+
7+
## How This PR Solves The Issue
8+
9+
## Manual Testing Instructions
10+
11+
## Automated Testing Overview
12+
13+
<!-- Please describe the tests introduced by this PR, or explain why no tests are needed. -->
14+
15+
## Release/Deployment Notes
16+
17+
<!-- Does this affect anything else or have ramifications for other code? Does anything have to be done on deployment? -->

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ This repository is a quick way to get started. You can create a new repo from th
3636
* You can optionally add files to the `global_files` directive as well, which will cause files to be placed in the global `.ddev` directory, `~/.ddev`.
3737
* Finally, `pre_install_commands` and `post_install_commands` are supported. These can use the host-side environment variables documented [in DDEV docs](https://ddev.readthedocs.io/en/stable/users/extend/custom-commands/#environment-variables-provided).
3838

39-
6. Update `tests/test.bats` to provide a reasonable test for your repository. Tests will run automatically on every push to the repository, and periodically each night. Please make sure to address test failures when they happen. Others will be depending on you. Bats is a testing framework that just uses Bash. To run a Bats test locally, you have to [install bats-core](https://bats-core.readthedocs.io/en/stable/installation.html) first. Then you download your add-on, and finally run `bats ./tests/test.bats` within the root of the uncompressed directory. To learn more about Bats see the [documentation](https://bats-core.readthedocs.io/en/stable/).
39+
6. Update `tests/test.bats` to provide a reasonable test for your repository. Tests will run automatically on every push to the repository, and periodically each night. Please make sure to address test failures when they happen. Others will be depending on you. Bats is a testing framework that just uses Bash. To run a Bats test locally, you have to install [bats-core](https://bats-core.readthedocs.io/en/stable/installation.html) and its [libraries](https://github.com/ztombol/bats-docs) first. Then you download your add-on, and finally run `bats ./tests/test.bats` within the root of the uncompressed directory. To learn more about Bats see the [documentation](https://bats-core.readthedocs.io/en/stable/).
4040
7. When everything is working, including the tests, you can push the repository to GitHub.
4141
8. Create a [release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) on GitHub.
4242
9. Test manually with `ddev add-on get <owner/repo>`.
43-
10. You can test PRs with `ddev add-on get https://github.com/<user>/<repo>/tarball/<branch>`
44-
11. Update the `README.md` header, adding the machine name of the add-on, for example `# ddev-redis`, not `# DDEV Redis`.
45-
12. Update the `README.md` to describe the add-on, how to use it, and how to contribute. If there are any manual actions that have to be taken, please explain them. If it requires special configuration of the using project, please explain how to do those. Examples in [ddev/ddev-solr](https://github.com/ddev/ddev-solr), [ddev/ddev-memcached](https://github.com/ddev/ddev-memcached), and (advanced) [ddev-platformsh](https://github.com/ddev/ddev-platformsh).
46-
13. Add a good short description to your repo, and add the [topic](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/classifying-your-repository-with-topics) "ddev-get". It will immediately be added to the list provided by `ddev add-on list --all`.
47-
14. When it has matured you will hopefully want to have it become an "official" maintained add-on. Open an issue in the [DDEV queue](https://github.com/ddev/ddev/issues) for that.
43+
10. You can test PRs with `ddev add-on get https://github.com/<user>/<repo>/tarball/<branch>`.
44+
11. You can test add-ons locally without GitHub by downloading them, making changes and running `ddev add-on get /path/to/add-on-directory`.
45+
12. Update the `README.md` header, adding the machine name of the add-on, for example `# ddev-redis`, not `# DDEV Redis`.
46+
13. Update the `README.md` to describe the add-on, how to use it, and how to contribute. If there are any manual actions that have to be taken, please explain them. If it requires special configuration of the using project, please explain how to do those. Examples in [ddev/ddev-solr](https://github.com/ddev/ddev-solr), [ddev/ddev-memcached](https://github.com/ddev/ddev-memcached), and (advanced) [ddev-platformsh](https://github.com/ddev/ddev-platformsh).
47+
14. Add a good short description to your repo, and add the [topic](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/classifying-your-repository-with-topics) "ddev-get". It will immediately be added to the list provided by `ddev add-on list --all`.
48+
15. When it has matured you will hopefully want to have it become an "official" maintained add-on. Open an issue in the [DDEV queue](https://github.com/ddev/ddev/issues) for that.
4849

4950
Add-ons were covered in [DDEV Add-ons: Creating, maintaining, testing](https://www.youtube.com/watch?v=TmXqQe48iqE) (part of the [DDEV Contributor Live Training](https://ddev.com/blog/contributor-training)).
5051

docker-compose.addon-template.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ services:
66
image: busybox:stable
77
command: tail -f /dev/null
88
restart: "no"
9-
# These labels ensure this service is discoverable by ddev.
9+
# These labels ensure this service is discoverable by DDEV.
1010
labels:
1111
com.ddev.site-name: ${DDEV_SITENAME}
1212
com.ddev.approot: $DDEV_APPROOT
1313

1414
volumes:
15-
- ".:/mnt/ddev_config"
16-
- "ddev-global-cache:/mnt/ddev-global-cache"
15+
- ".:/mnt/ddev_config"
16+
- "ddev-global-cache:/mnt/ddev-global-cache"

install.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ global_files:
8181
# and prevent add-on from being installed if it doesn't validate.
8282
# See https://github.com/Masterminds/semver#checking-version-constraints for constraint rules.
8383
# Available with DDEV v1.23.4+, and works only for DDEV v1.23.4+ binaries
84-
# example: ddev_version_constraint: '>= v1.23.4'
85-
ddev_version_constraint: ''
84+
ddev_version_constraint: '>= v1.24.2'
8685

8786
# List of add-on names that this add-on depends on
8887
dependencies:
@@ -112,7 +111,7 @@ removal_actions:
112111
# Advanced usage - YAML files can be read in and then used as go template actions
113112
# in pre_install_actions and post_install_actions
114113
# See example in
115-
# https://github.com/ddev/ddev/blob/master/cmd/ddev/cmd/testdata/TestCmdAddonComplex/recipe/install.yaml
114+
# https://github.com/ddev/ddev/blob/main/cmd/ddev/cmd/testdata/TestCmdAddonComplex/recipe/install.yaml
116115
yaml_read_files:
117116
# someyaml: someyaml.yaml
118117
# otheryaml: someotheryaml.yaml

tests/test.bats

+54-18
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,80 @@
1+
#!/usr/bin/env bats
2+
3+
# Bats is a testing framework for Bash
4+
# Documentation https://bats-core.readthedocs.io/en/stable/
5+
# Bats libraries documentation https://github.com/ztombol/bats-docs
6+
7+
# For local tests, install bats-core, bats-assert, bats-file, bats-support
8+
# And run this in the add-on root directory:
9+
# bats ./tests/test.bats
10+
# To exclude release tests:
11+
# bats ./tests/test.bats --filter-tags '!release'
12+
# For debugging:
13+
# bats ./tests/test.bats --show-output-of-passing-tests --verbose-run --print-output-on-failure
14+
115
setup() {
216
set -eu -o pipefail
3-
export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.."
4-
export TESTDIR=~/tmp/test-addon-template
5-
mkdir -p $TESTDIR
6-
export PROJNAME=test-addon-template
17+
18+
# Override this variable for your add-on:
19+
export GITHUB_REPO=ddev/ddev-addon-template
20+
21+
TEST_BREW_PREFIX="$(brew --prefix 2>/dev/null || true)"
22+
export BATS_LIB_PATH="${BATS_LIB_PATH}:${TEST_BREW_PREFIX}/lib:/usr/lib/bats"
23+
bats_load_library bats-assert
24+
bats_load_library bats-file
25+
bats_load_library bats-support
26+
27+
export DIR="$(cd "$(dirname "${BATS_TEST_FILENAME}")/.." >/dev/null 2>&1 && pwd)"
28+
export PROJNAME="test-$(basename "${GITHUB_REPO}")"
29+
mkdir -p ~/tmp
30+
export TESTDIR=$(mktemp -d ~/tmp/${PROJNAME}.XXXXXX)
731
export DDEV_NONINTERACTIVE=true
8-
ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true
32+
export DDEV_NO_INSTRUMENTATION=true
33+
ddev delete -Oy "${PROJNAME}" >/dev/null 2>&1 || true
934
cd "${TESTDIR}"
10-
ddev config --project-name=${PROJNAME}
11-
ddev start -y >/dev/null
35+
run ddev config --project-name="${PROJNAME}" --project-tld=ddev.site
36+
assert_success
37+
run ddev start -y
38+
assert_success
1239
}
1340

1441
health_checks() {
1542
# Do something useful here that verifies the add-on
16-
# ddev exec "curl -s elasticsearch:9200" | grep "${PROJNAME}-elasticsearch"
17-
ddev exec "curl -s https://localhost:443/"
43+
44+
# You can check for specific information in headers:
45+
# run curl -sfI https://${PROJNAME}.ddev.site
46+
# assert_output --partial "HTTP/2 200"
47+
# assert_output --partial "test_header"
48+
49+
# Or check if some command gives expected output:
50+
DDEV_DEBUG=true run ddev launch
51+
assert_success
52+
assert_output --partial "FULLURL https://${PROJNAME}.ddev.site"
1853
}
1954

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

2761
@test "install from directory" {
2862
set -eu -o pipefail
29-
cd ${TESTDIR}
30-
echo "# ddev add-on get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
31-
ddev add-on get ${DIR}
32-
ddev restart
63+
echo "# ddev add-on get ${DIR} with project ${PROJNAME} in $(pwd)" >&3
64+
run ddev add-on get "${DIR}"
65+
assert_success
66+
run ddev restart -y
67+
assert_success
3368
health_checks
3469
}
3570

3671
# bats test_tags=release
3772
@test "install from release" {
3873
set -eu -o pipefail
39-
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
40-
echo "# ddev add-on get ddev/ddev-addon-template with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
41-
ddev add-on get ddev/ddev-addon-template
42-
ddev restart >/dev/null
74+
echo "# ddev add-on get ${GITHUB_REPO} with project ${PROJNAME} in $(pwd)" >&3
75+
run ddev add-on get "${GITHUB_REPO}"
76+
assert_success
77+
run ddev restart -y
78+
assert_success
4379
health_checks
4480
}

0 commit comments

Comments
 (0)