Skip to content

Commit 9833e6f

Browse files
authored
test: update bats, remove images, use #!/usr/bin/env bash (#11)
1 parent 7025724 commit 9833e6f

File tree

4 files changed

+62
-28
lines changed

4 files changed

+62
-28
lines changed

commands/web/ibexa_cloud

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
#ddev-generated
44
## Description: Run ibexa_cloud CLI inside the web container

images/gh-tmate.jpg

-53.9 KB
Binary file not shown.

images/template-button.png

-20 KB
Binary file not shown.

tests/test.bats

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
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() {
2-
# set -u does not work with bats-assert
3-
set -e -o pipefail
4-
TEST_BREW_PREFIX="$(brew --prefix)"
5-
load "${TEST_BREW_PREFIX}/lib/bats-support/load.bash"
6-
load "${TEST_BREW_PREFIX}/lib/bats-assert/load.bash"
7-
load "${TEST_BREW_PREFIX}/lib/bats-file/load.bash"
8-
9-
10-
export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.."
11-
export TESTDIR=~/tmp/test-ibexa-cloud
12-
mkdir -p $TESTDIR
13-
export PROJNAME=test-ibexa-cloud
16+
set -eu -o pipefail
17+
18+
# Override this variable for your add-on:
19+
export GITHUB_REPO=ddev/ddev-ibexa-cloud
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)
1431
export DDEV_NONINTERACTIVE=true
15-
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
1634
cd "${TESTDIR}"
17-
ddev config --project-name=${PROJNAME}
35+
run ddev config --project-name="${PROJNAME}" --project-tld=ddev.site
36+
assert_success
37+
1838
cp -r ${DIR}/tests/testdata/.platform.app.yaml ${DIR}/tests/testdata/.platform ${TESTDIR}
39+
40+
run ddev start -y
41+
assert_success
1942
}
2043

2144
pull_health_checks() {
@@ -29,6 +52,7 @@ pull_health_checks() {
2952
ddev mutagen sync
3053
assert_file_exist "${TESTDIR}/var/encore/ibexa.richtext.config.manager.js"
3154
}
55+
3256
push_health_checks() {
3357
# set -x
3458
# Add a new value into local database so we can test it arrives in push environment
@@ -62,35 +86,45 @@ push_health_checks() {
6286

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

7093
@test "install from directory" {
71-
# bats-assert doesn't work with set -u
72-
set -e -o pipefail
73-
cd ${TESTDIR}
74-
echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
75-
ddev get ${DIR}
76-
ddev config --web-environment=IBEXA_CLI_TOKEN=${IBEXA_CLI_TOKEN},IBEXA_PROJECT=${IBEXA_PROJECT},IBEXA_ENVIRONMENT=pull
77-
ddev restart >/dev/null
94+
set -eu -o pipefail
95+
echo "# ddev add-on get ${DIR} with project ${PROJNAME} in $(pwd)" >&3
96+
run ddev add-on get "${DIR}"
97+
assert_success
98+
99+
run ddev config --web-environment=IBEXA_CLI_TOKEN=${IBEXA_CLI_TOKEN},IBEXA_PROJECT=${IBEXA_PROJECT},IBEXA_ENVIRONMENT=pull
100+
assert_success
101+
102+
run ddev restart -y
103+
assert_success
104+
78105
echo "# pull health checks" >&3
79106
pull_health_checks
107+
80108
echo "# push health checks" >&3
81109
push_health_checks
82110
}
83111

84112
# bats test_tags=release
85113
@test "install from release" {
86114
set -eu -o pipefail
87-
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
88-
echo "# ddev get ddev/ddev-ibexa-cloud with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
89-
ddev get ddev/ddev-ibexa-cloud
90-
ddev config --web-environment=IBEXA_CLI_TOKEN=${IBEXA_CLI_TOKEN},IBEXA_PROJECT=${IBEXA_PROJECT:-},IBEXA_ENVIRONMENT=pull
91-
ddev restart >/dev/null
115+
echo "# ddev add-on get ${GITHUB_REPO} with project ${PROJNAME} in $(pwd)" >&3
116+
run ddev add-on get "${GITHUB_REPO}"
117+
assert_success
118+
119+
run ddev config --web-environment=IBEXA_CLI_TOKEN=${IBEXA_CLI_TOKEN},IBEXA_PROJECT=${IBEXA_PROJECT},IBEXA_ENVIRONMENT=pull
120+
assert_success
121+
122+
run ddev restart -y
123+
assert_success
124+
92125
echo "# pull health checks" >&3
93126
pull_health_checks
127+
94128
echo "# push health checks" >&3
95129
push_health_checks
96130
}

0 commit comments

Comments
 (0)