Skip to content

Commit

Permalink
Add acceptance tests of the demo application, document the workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Jul 2, 2022
1 parent 68588cb commit a634593
Show file tree
Hide file tree
Showing 14 changed files with 381 additions and 157 deletions.
7 changes: 5 additions & 2 deletions ci/create-new-project
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash -eux

echo ::group::Create the project

TAG=$(scripts/get-version --major)
DOCKER_TAG=${TAG} make build-tools
DOCKER_TAG=${TAG} make build-runner
Expand Down Expand Up @@ -37,8 +39,6 @@ if [ $BASE_APP != true ]; then
mv ${WORKSPACE}/${PACKAGE}/geoportal/vars.yaml ${WORKSPACE}/${PACKAGE}/geoportal/vars_origin.yaml
cp ci/vars.yaml ${WORKSPACE}/${PACKAGE}/geoportal/
mkdir -p ${WORKSPACE}/${PACKAGE}/geoportal/ci
cp ci/waitwsgi ${WORKSPACE}/${PACKAGE}/geoportal/ci
cp ci/test-new-project ${WORKSPACE}/${PACKAGE}/geoportal/ci
mkdir -p ${WORKSPACE}/${PACKAGE}/ci
echo "PGSSLMODE=prefer" >> ${WORKSPACE}/${PACKAGE}/env.project
fi
Expand Down Expand Up @@ -75,12 +75,15 @@ git add --all
git commit --quiet --message='Initial commit'

mv ci/config.yaml{,_}
echo ::endgroup::
c2cciutils-checks --fix --check=isort
c2cciutils-checks --fix --check=black
c2cciutils-checks --fix --check=prettier
mv ci/config.yaml{_,}

echo ::group::Diff
git --no-pager diff
echo ::endgroup::
git add --all
git commit --quiet --message='Format'
git clean -fX
138 changes: 102 additions & 36 deletions ci/test-app
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
rm -rf "${HOME}/workspace/testgeomapfishapp"

ci/create-new-project "${HOME}/workspace"

# Copy the files needed to run the tests
cp ci/docker-compose.override.yaml "${HOME}/workspace/testgeomapfishapp/"
cp ci/waitwsgi "${HOME}/workspace/testgeomapfishapp/ci/"
cp ci/empty.qgz "${HOME}/workspace/testgeomapfishapp/qgisserver/project.qgz"
cp -r ci/test-app-db "${HOME}/workspace/testgeomapfishapp/ci/"
cp -r ci/test-external-db "${HOME}/workspace/testgeomapfishapp/ci/"
Expand All @@ -14,12 +15,21 @@ cd "${HOME}/workspace/testgeomapfishapp/"

folder=geoportal/interfaces
cp -r CONST_create_template/${folder} ${folder}
file=tests/test_testapp.py
cp CONST_create_template/${file} ${file}

# Check if the `c2cciutils-checks` pass
c2cciutils-checks
cp "${PROJECT_DIR}/ci/project-config.yaml" ci/config.yaml
c2cciutils-checks

# Build
echo ::group::Build
CI=true ./build
echo ::endgroup::

# Lint
echo ::group::Lint
docker-compose run --entrypoint= --no-deps --rm --volume=$(pwd)/geoportal:/app geoportal \
prospector --output-format=pylint --die-on-tool-error
docker-compose run --entrypoint= --no-deps --rm --volume=$(pwd)/geoportal:/app geoportal \
Expand All @@ -28,69 +38,125 @@ docker-compose run --entrypoint= --no-deps --rm --volume=$(pwd)/geoportal:/app g
eslint $(find testgeomapfishapp -type f -name '*.ts' -print 2> /dev/null)

docker-compose down --volumes
echo ::endgroup::

# Start
echo ::group::Start
docker-compose up -d
docker-compose exec -T geoportal bash -c 'PGHOST=externaldb PGDATABASE=test wait-db;'
docker-compose exec -T geoportal wait-db
docker-compose ps
echo ::endgroup::
c2cciutils-docker-logs

# Run alembic
echo ::group::Run alembic
docker-compose exec -T geoportal alembic --config=alembic.ini --name=main upgrade head
docker-compose exec -T geoportal alembic --config=alembic.ini --name=static upgrade head
docker-compose start alembic
sleep 10
echo ::endgroup::
c2cciutils-docker-logs

# Create the Theme
echo ::group::Create the Theme
docker-compose exec -T geoportal create-demo-theme
echo ::endgroup::
c2cciutils-docker-logs

# Test `theme2fts`
echo ::group::Test theme2fts
docker-compose exec -T geoportal theme2fts
echo ::endgroup::

# Test `update-po`
echo ::group::Test update-po
make update-po
echo ::endgroup::

docker-compose exec -T geoportal ci/waitwsgi https://front/themes
for path in c2c/health_check c2c/health_check?max_level=9 c2c/health_check?checks=check_collector "layers/test/values/type enum" admin/layertree admin/layertree/children; do
docker-compose exec -T geoportal ci/test-new-project https://front/${path}
# Test the checker and QGIS
echo ::group::Test the checker and QGIS
for url in 'https://front/c2c/health_check?max_level=9' 'http://qgisserver:8080/mapserv_proxy?SERVICE=WMS&REQUEST=GetCapabilities'; do
docker-compose exec -T geoportal curl --fail --insecure "${url}" \
|| (docker-compose exec -T geoportal curl --insecure "${url}" && false)
done
docker-compose exec -T geoportal ci/test-new-project 'http://qgisserver:8080/mapserv_proxy?SERVICE=WMS&REQUEST=GetCapabilities'
docker-compose exec -T geoportal curl --insecure https://front/admin/ | grep Login
docker-compose exec -T geoportal curl --insecure 'https://front/dynamic.json?interface=desktop&query=&path=%2F'
docker-compose exec -T geoportal curl --insecure https://front/static-geomapfish/0/locales/fr.json
docker-compose exec -T geoportal curl --insecure https://front/desktop_alt
docker-compose exec -T geoportal curl --insecure https://front/desktop_alt \
| grep '<script src="https://front/static-ngeo-dist/desktop\..*\.js" crossorigin="anonymous"></script>'
docker-compose exec -T geoportal curl --insecure https://front/desktop_alt \
| grep '<html lang="{{mainCtrl.lang}}" '

function test_pot {
docker-compose exec -T geoportal curl --insecure https://front/locale.pot --output /tmp/locale.pot
docker-compose exec -T geoportal cat /tmp/locale.pot > /tmp/locale.pot
if [ "$(wc -l < /tmp/locale.pot)" -eq "$(wc -l < geoportal/testgeomapfishapp_geoportal/locale/testgeomapfishapp_geoportal-client.pot)" ]; then
echo 'View locale.pot match in size with update-po'
else
echo 'Error: View locale.pot does not match in size with update-po'
sed -i 's%/app/%./geoportal/%g' /tmp/locale.pot
diff geoportal/testgeomapfishapp_geoportal/locale/testgeomapfishapp_geoportal-client.pot /tmp/locale.pot
exit 1
fi
}
test_pot
# A second time to check that the initialisation is working
test_pot
echo ::endgroup::

# Test the `proutes` and `pviews` commands
echo ::group::Test the proutes command with development.ini
docker-compose exec -T geoportal proutes c2c://development.ini
echo ::endgroup::
echo ::group::Test the pviews command with development.ini
docker-compose exec -T geoportal pviews c2c://development.ini /
echo ::endgroup::
echo ::group::Test the proutes command with production.ini
docker-compose exec -T geoportal proutes c2c://production.ini
echo ::endgroup::
echo ::group::Test the pviews command with production.ini
docker-compose exec -T geoportal pviews c2c://production.ini /
echo ::endgroup::

docker-compose stop qgisserver
docker-compose exec -T geoportal alembic --config=alembic.ini --name=static downgrade base
docker-compose exec -T geoportal alembic --config=alembic.ini --name=main downgrade base

# Test the `db-backup` and `db-restore` commands
echo ::group::Test the db-backup command
cp .env env.int
echo PGHOST_SLAVE="$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')" >> env.int
echo PGPORT_SLAVE=54321 >> env.int
scripts/db-backup --env=env.int dump.backup
scripts/db-backup --env=env.int --arg=--schema=main dump.backup
scripts/db-backup --env=env.int --arg=--schema=main main-dump.backup
echo ::endgroup::

echo ::group::Test the db-restore command
docker-compose exec -T tools psql --command="ALTER SCHEMA main RENAME TO main_old"
docker-compose exec -T tools psql --command="CREATE SCHEMA main"
scripts/db-restore --arg=--schema=main dump.backup
echo ::endgroup::

# Empty the database
echo ::group::Empty the database
docker-compose exec -T geoportal alembic --config=alembic.ini --name=static downgrade base
docker-compose exec -T geoportal alembic --config=alembic.ini --name=main downgrade base
echo ::endgroup::

# Test the `mappyfile validate` command
echo ::group::Test the mappyfile validate command
docker-compose exec -T tools rm /etc/mapserver/demo.map
docker-compose exec -T tools mappyfile validate --version=7.6 /etc/mapserver/*.map
echo ::endgroup::
c2cciutils-docker-logs

# Run the acceptances tests
echo ::group::Stop
docker-compose down
sudo rm -rf "${HOME}/workspace/testgeomapfishapp"
mv docker-compose.override.yaml docker-compose.test.yaml
echo ::endgroup::

echo ::group::Init acceptance tests
make acceptance-init
docker-compose \
--file=docker-compose.yaml \
--file=docker-compose-db.yaml \
--file=docker-compose.test.yaml up -d
echo ::endgroup::
c2cciutils-docker-logs

echo ::group::Run acceptance tests
make acceptance
echo ::endgroup::
c2cciutils-docker-logs

echo ::group::Run acceptance tests in dev mode
docker-compose \
--file=docker-compose.yaml \
--file=docker-compose-db.yaml \
--file=docker-compose.test.yaml \
--file=docker-compose.override.sample.yaml up -d
make acceptance
echo ::endgroup::
c2cciutils-docker-logs

# Remove the test project
echo ::group::Remove the test project
docker-compose down --remove-orphans
cd -
sudo rm -rf "${HOME}/workspace/testgeomapfishapp"
docker rmi camptocamp/testgeomapfishapp-config:latest
echo ::endgroup::
63 changes: 0 additions & 63 deletions ci/test-new-project

This file was deleted.

51 changes: 0 additions & 51 deletions ci/waitwsgi

This file was deleted.

Loading

0 comments on commit a634593

Please sign in to comment.