Skip to content

Commit

Permalink
[QOLDEV-1014] sync test config with other repos
Browse files Browse the repository at this point in the history
- Add report-only testing of CKAN 2.11
- Replace obsolete test containers
- Add more regression scenario tests
  • Loading branch information
ThrawnCA committed Dec 16, 2024
1 parent c908a82 commit 721ce2a
Show file tree
Hide file tree
Showing 23 changed files with 251 additions and 1,068 deletions.
23 changes: 12 additions & 11 deletions .ahoy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ commands:
ahoy title "Building and starting Docker containers"
sh bin/docker-compose.sh up -d "$@"
echo "Initialising database schema"
ahoy cli '$APP_DIR/bin/init.sh'
ahoy cli '"${APP_DIR}"/bin/init.sh'
echo "Waiting for containers to start listening..."
ahoy cli "dockerize -wait tcp://ckan:5000 -timeout 1m"
if sh bin/docker-compose.sh logs | grep -q "\[Error\]"; then exit 1; fi
Expand Down Expand Up @@ -79,9 +79,9 @@ commands:
cmd: |
CKAN_CONTAINER=$(sh bin/docker-compose.sh ps -q ckan)
if [ "${#}" -ne 0 \]; then
docker exec $CKAN_CONTAINER sh -c '. ${APP_DIR}/bin/activate; cd $APP_DIR;'" $*"
docker exec $CKAN_CONTAINER sh -c '. "${APP_DIR}"/bin/activate; cd $APP_DIR;'" $*"
else
docker exec $CKAN_CONTAINER sh -c '. ${APP_DIR}/bin/activate && cd $APP_DIR && sh'
docker exec $CKAN_CONTAINER sh -c '. "${APP_DIR}"/bin/activate && cd $APP_DIR && sh'
fi
doctor:
Expand All @@ -92,7 +92,7 @@ commands:
usage: Install test site data.
cmd: |
ahoy title "Installing a fresh site"
ahoy cli '$APP_DIR/bin/init.sh && $APP_DIR/bin/create-test-data.sh'
ahoy cli '"${APP_DIR}"/bin/init.sh && "${APP_DIR}"/bin/create-test-data.sh'
clean:
usage: Remove containers and all build files.
Expand Down Expand Up @@ -128,13 +128,13 @@ commands:
cmd: |
docker cp . $(sh bin/docker-compose.sh ps -q ckan):/srv/app/
docker cp bin/ckan_cli $(sh bin/docker-compose.sh ps -q ckan):/usr/bin/
ahoy cli 'chmod -v u+x /usr/bin/ckan_cli $APP_DIR/bin/*; cp -v .docker/test.ini $CKAN_INI; $APP_DIR/bin/process-config.sh'
ahoy cli 'chmod -v u+x /usr/bin/ckan_cli "${APP_DIR}"/bin/*; cp -v .docker/test.ini $CKAN_INI; "${APP_DIR}"/bin/process-config.sh'
test-unit:
usage: Run unit tests.
cmd: |
ahoy title 'Run unit tests'
ahoy cli 'pytest --ckan-ini=${CKAN_INI} $APP_DIR/ckanext' || \
ahoy cli 'pytest --ckan-ini=${CKAN_INI} --cov=ckanext "${APP_DIR}"/ckanext --junit-xml=test/junit/results.xml' || \
[ "${ALLOW_UNIT_FAIL:-0}" -eq 1 ]
test-bdd:
Expand All @@ -145,21 +145,22 @@ commands:
ahoy start-ckan-job-workers
ahoy start-mailmock &
sleep 5
JUNIT_OUTPUT="--junit --junit-directory=test/junit/"
if [ "$BEHAVE_TAG" = "" ]; then
# no tag specified, probably running locally
(ahoy cli "behave -k ${*:-test/features} --tags=smoke" \
&& ahoy cli "behave -k ${*:-test/features} --tags=-smoke" \
(ahoy cli "behave $JUNIT_OUTPUT -k ${*:-test/features} --tags=smoke" \
&& ahoy cli "behave $JUNIT_OUTPUT -k ${*:-test/features} --tags=-smoke"
) || [ "${ALLOW_BDD_FAIL:-0}" -eq 1 ]
elif [ "$BEHAVE_TAG" = "authenticated" ]; then
# run any tests that don't have a specific tag
ahoy cli "behave -k ${*:-test/features} --tags=-unauthenticated --tags=-smoke --tags=-OpenData --tags=-multi_plugin" \
ahoy cli "behave $JUNIT_OUTPUT -k ${*:-test/features} --tags=-unauthenticated --tags=-smoke --tags=-OpenData --tags=-multi_plugin" \
|| [ "${ALLOW_BDD_FAIL:-0}" -eq 1 ]
else
if [ "$BEHAVE_TAG" != "multi_plugin" ]; then
BEHAVE_TAG="$BEHAVE_TAG --tags=-multi_plugin"
fi
# run tests with the specified tag
ahoy cli "behave -k ${*:-test/features} --tags=$BEHAVE_TAG" \
ahoy cli "behave $JUNIT_OUTPUT -k ${*:-test/features} --tags=$BEHAVE_TAG" \
|| [ "${ALLOW_BDD_FAIL:-0}" -eq 1 ]
fi
ahoy stop-mailmock
Expand All @@ -169,7 +170,7 @@ commands:
usage: Starts email mock server used for email BDD tests
cmd: |
ahoy title 'Starting mailmock'
ahoy cli 'mailmock -p 8025 -o ${APP_DIR}/test/emails' # for debugging mailmock email output remove --no-stdout
ahoy cli 'mailmock -p 8025 -o "${APP_DIR}"/test/emails' # for debugging mailmock email output remove --no-stdout
stop-mailmock:
usage: Stops email mock server used for email BDD tests
Expand Down
33 changes: 21 additions & 12 deletions .docker/Dockerfile-template.ckan
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
FROM openknowledge/ckan-dev:{CKAN_VERSION}
FROM ckan/ckan-dev:{CKAN_VERSION}

# swap between root and unprivileged user
ARG ORIGINAL_USER
RUN ORIGINAL_USER=$(id -un)

ARG SITE_URL=http://ckan:5000/
ENV PYTHON_VERSION={PYTHON_VERSION}
Expand All @@ -8,11 +12,22 @@ ENV PYTHON={PYTHON}

WORKDIR "${APP_DIR}"

ENV DOCKERIZE_VERSION v0.6.1
RUN apk add --no-cache build-base \
&& curl -sL https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-alpine-linux-amd64-${DOCKERIZE_VERSION}.tar.gz \
COPY .docker/test.ini $CKAN_INI

COPY . "${APP_DIR}"/

USER root

COPY bin/ckan_cli /usr/bin/

RUN chmod +x "${APP_DIR}"/bin/*.sh /usr/bin/ckan_cli

ENV DOCKERIZE_VERSION=v0.6.1
RUN wget -O - https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-linux-amd64-${DOCKERIZE_VERSION}.tar.gz \
| tar -C /usr/local/bin -xzvf -

RUN which ps || apt-get install -y procps

# Install CKAN.

RUN cd $SRC_DIR/ckan \
Expand All @@ -22,15 +37,9 @@ RUN cd $SRC_DIR/ckan \
&& git reset --hard && git clean -f \
&& git checkout '{CKAN_GIT_VERSION}'

COPY .docker/test.ini $CKAN_INI

COPY . ${APP_DIR}/

COPY bin/ckan_cli /usr/bin/

RUN chmod +x ${APP_DIR}/bin/*.sh /usr/bin/ckan_cli
USER "$ORIGINAL_USER"

# Init current extension.
RUN ${APP_DIR}/bin/init-ext.sh
RUN "${APP_DIR}"/bin/init-ext.sh

CMD ["/srv/app/bin/serve.sh"]
22 changes: 3 additions & 19 deletions .docker/test.ini
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
#
# CKAN - Pylons configuration
#
# These are some of the configuration options available for your CKAN
# instance. Check the documentation in 'doc/configuration.rst' or at the
# following URL for a description of what they do and the full list of
# available options:
#
# http://docs.ckan.org/en/latest/maintaining/configuration.html
#
# The %(here)s variable will be replaced with the parent directory of this file
#

[DEFAULT]
debug = false
smtp_server = localhost:8025
Expand All @@ -30,13 +17,9 @@ full_stack = true
cache_dir = /tmp/%(ckan.site_id)s/
beaker.session.key = ckan

# This is the secret token that the beaker library uses to hash the cookie sent
# to the client. `paster make-config` generates a unique value for this each
# time it generates a config file.
SECRET_KEY = bSmgPpaxg2M+ZRes3u1TXwIcE
beaker.session.secret = bSmgPpaxg2M+ZRes3u1TXwIcE

# `paster make-config` generates a unique value for this each time it generates
# a config file.
app_instance_uuid = 6e3daf8e-1c6b-443b-911f-c7ab4c5f9605

# repoze.who config
Expand Down Expand Up @@ -71,6 +54,7 @@ ckan.auth.create_user_via_api = false
ckan.auth.create_user_via_web = true
ckan.auth.roles_that_cascade_to_sub_groups = admin
ckan.auth.public_user_details = False
ckan.auth.reveal_private_datasets = True


## Search Settings
Expand Down Expand Up @@ -250,7 +234,7 @@ ckanext-archiver.cache_url_root = http://dataqld-ckan.docker.amazee.io/resources
# QA
qa.resource_format_openness_scores_json = /srv/app/src/ckanext-data-qld/ckanext/data_qld/resource_format_openness_scores.json

# Logging configuration
## Logging configuration
[loggers]
keys = root, ckan, ckanext

Expand Down
24 changes: 22 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ jobs:
matrix:
ckan-version: ["2.10", 2.9]
behave-tag: [smoke, unauthenticated, multi_plugin, OpenData, authenticated]
experimental: [false]
include:
- ckan-version: '2.11'
experimental: true
- ckan-version: 'master'
experimental: true #master is unstable, good to know if we are compatible or not

name: Run ${{ matrix.behave-tag }} tests on CKAN ${{ matrix.ckan-version }}
runs-on: ubuntu-latest
Expand All @@ -42,34 +48,48 @@ jobs:
run: echo HOME=/root >> "$GITHUB_ENV"

- uses: actions/checkout@v4
continue-on-error: ${{ matrix.experimental }}
timeout-minutes: 2

- name: Build
continue-on-error: ${{ matrix.experimental }}
run: bin/build.sh
timeout-minutes: 15

- name: Unit tests
continue-on-error: ${{ matrix.experimental }}
if: ${{ matrix.behave-tag == 'smoke' }}
run: bin/test.sh
timeout-minutes: 15

- name: Test ${{ matrix.behave-tag }} BDD
continue-on-error: ${{ matrix.experimental }}
run: bin/test-bdd.sh
timeout-minutes: 45

- name: Retrieve logs
if: always()
run: ahoy logs
continue-on-error: ${{ matrix.experimental }}
timeout-minutes: 1

- name: Retrieve screenshots
- name: Retrieve results
if: always()
run: bin/process-artifacts.sh
continue-on-error: ${{ matrix.experimental }}
timeout-minutes: 1

- name: Test Summary
uses: test-summary/action@v2
continue-on-error: ${{ matrix.experimental }}
with:
paths: "/tmp/artifacts/junit/*.xml"
if: always()

- name: Upload screenshots
if: failure()
if: always()
uses: actions/upload-artifact@v4
continue-on-error: ${{ matrix.experimental }}
with:
name: CKAN ${{ matrix.ckan-version }} ${{ matrix.behave-tag }} screenshots
path: /tmp/artifacts/behave/screenshots
Expand Down
15 changes: 5 additions & 10 deletions bin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,18 @@ sed -i -e "s/##//" docker-compose.yml
# Pull the latest images.
ahoy pull

PYTHON=python
PYTHON=python3
PYTHON_VERSION=py3

CKAN_GIT_VERSION=$CKAN_VERSION
CKAN_GIT_ORG=qld-gov-au

if [ "$CKAN_VERSION" = "2.10" ]; then
if [ "$CKAN_VERSION" = "2.11" ]; then
CKAN_GIT_VERSION=ckan-2.11.1
elif [ "$CKAN_VERSION" = "2.10" ]; then
CKAN_GIT_VERSION=ckan-2.10.5-qgov.4
PYTHON_VERSION=py3
PYTHON="${PYTHON}3"
else
CKAN_GIT_VERSION=ckan-2.9.9-qgov.3
if [ "$CKAN_VERSION" = "2.9-py2" ]; then
PYTHON_VERSION=py2
else
PYTHON_VERSION=py3
PYTHON="${PYTHON}3"
fi
fi

sed "s|{CKAN_VERSION}|$CKAN_VERSION|g" .docker/Dockerfile-template.ckan \
Expand Down
Loading

0 comments on commit 721ce2a

Please sign in to comment.