forked from ckan/ckan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ckan#7099 from EricSoroos/local-testing
Local Testing Infrastructure
- Loading branch information
Showing
12 changed files
with
228 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Refactor CircleCI testing to allow for local test runs in docker with the same images as CircleCI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Local testing | ||
|
||
This is a set of scripts that replicate the contents of `/.circleci/config.yml`, enabling testing on the local machine with the same setup as circleci. It requires docker with the compose plugin to be installed and on the path, as well as the `sh` shell. It should work out of the box on linux/mac, Windows is unknown. | ||
|
||
NOTE: This is not intended to be a pattern for running anything other than tests. This is not a deployment template. | ||
|
||
|
||
## To Run. | ||
|
||
``` | ||
$ cd test-infrastructure | ||
test-infrastructure$ ./setup.sh | ||
[[ | ||
* docker composee downloads images and starts the stack | ||
* System level dependencies (psql) are installed | ||
* Python dependencies are installed, ckan is installed in edit mode | ||
* Database creation and database initialization are done | ||
]] | ||
test-infrastructure$ ./execute.sh | ||
$ ./execute.sh | ||
2022-09-22 14:42:28,959 INFO [ckan.cli] Using configuration file /usr/src/test-core-circle-ci.ini | ||
2022-09-22 14:42:28,960 INFO [ckan.config.environment] Loading static files from public | ||
2022-09-22 14:42:29,371 WARNI [ckan.common] Option ckan.plugins is not declared | ||
2022-09-22 14:42:29,618 INFO [ckan.config.environment] Loading templates from /usr/src/ckan/templates | ||
2022-09-22 14:42:30,381 INFO [ckan.config.environment] Loading templates from /usr/src/ckan/templates | ||
2022-09-22 14:42:30,534 CRITI [ckan.lib.uploader] Please specify a ckan.storage_path in your config | ||
for your uploads | ||
2022-09-22 14:42:30,708 WARNI [ckan.config.middleware.flask_app] Extensions are excluded from CSRF protection! We allow extensions to run without CSRF protection but it will be forced future releases. Read the documentation for more information on how to add CSRF protection to your extension. | ||
============================================================================== test session starts ============================================================================== | ||
platform linux -- Python 3.7.14, pytest-7.1.3, pluggy-1.0.0 -- /usr/local/bin/python | ||
cachedir: .pytest_cache | ||
rootdir: /usr/src, configfile: pyproject.toml, testpaths: ckan, ckanext | ||
plugins: freezegun-0.4.2, split-0.8.0, test-groups-1.0.3, factoryboy-2.4.0, Faker-14.2.0, rerunfailures-10.2, cov-3.0.0 | ||
collected 2883 items | ||
2022-09-22 14:42:45,763 INFO [ckan.config.environment] Loading templates from /usr/src/ckan/templates | ||
2022-09-22 14:42:46,353 INFO [ckan.config.environment] Loading templates from /usr/src/ckan/templates | ||
ckan/tests/test_authz.py::test_config_overrides_default PASSED [ 0%] | ||
ckan/tests/test_authz.py::test_config_override_also_works_with_prefix PASSED [ 0%] | ||
ckan/tests/test_authz.py::test_unknown_permission_returns_false PASSED [ 0%] | ||
ckan/tests/test_authz.py::test_unknown_permission_not_in_config_returns_false PASSED [ 0%] | ||
ckan/tests/test_authz.py::test_default_roles_`that_cascade`_to_sub_groups_is_a_list PASSED [ 0%] | ||
...: | ||
test-infrastructure$ ./teardown.sh | ||
``` | ||
|
||
If you wish to run individual tests, it can be done with: | ||
``` | ||
docker compose exec ckan pytest -vv --ckan-ini=test-core-circle-ci.ini ckan/tests/lib/test_helpers.py::test_get_translated | ||
``` | ||
|
||
## Known issues | ||
|
||
* pytest-split causes testing errors. | ||
* Windows | ||
* Run as something other than root in the container |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
version: "3" | ||
networks: | ||
default: | ||
volumes: | ||
postgres-db-volume: | ||
|
||
services: | ||
ckan-postgres: | ||
networks: | ||
- default | ||
image: "postgres:10" | ||
environment: | ||
POSTGRES_USER: ckan | ||
POSTGRES_PASSWORD: ckan | ||
|
||
ckan-redis: | ||
networks: | ||
- default | ||
image: "redis:3" | ||
|
||
ckan-solr: | ||
networks: | ||
- default | ||
image: "ckan/ckan-solr:master" | ||
|
||
ckan: | ||
image: python:3.8-bullseye | ||
networks: | ||
- default | ||
environment: | ||
HOME: /usr/src | ||
CKAN_DATASTORE_POSTGRES_DB: datastore_test | ||
CKAN_DATASTORE_POSTGRES_READ_USER: datastore_read | ||
CKAN_DATASTORE_POSTGRES_READ_PWD: pass | ||
CKAN_DATASTORE_POSTGRES_WRITE_USER: datastore_write | ||
CKAN_DATASTORE_POSTGRES_WRITE_PWD: pass | ||
CKAN_POSTGRES_DB: ckan_test | ||
CKAN_POSTGRES_USER: ckan_default | ||
CKAN_POSTGRES_PWD: pass | ||
PGPASSWORD: ckan | ||
PYTEST_COMMON_OPTIONS: -v --ckan-ini=test-core-circle-ci.ini --cov=ckan --cov=ckanext --junitxml=~/junit/junit.xml | ||
working_dir: "/usr/src" | ||
volumes: | ||
- "../:/usr/src" | ||
command: | ||
['tail', '-f', '/etc/debian_version'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
docker compose exec ckan test-infrastructure/run_tests.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
|
||
# Database Creation | ||
psql --host=ckan-postgres --username=ckan --command="CREATE USER ${CKAN_POSTGRES_USER} WITH PASSWORD '${CKAN_POSTGRES_PWD}' NOSUPERUSER NOCREATEDB NOCREATEROLE;" | ||
createdb --encoding=utf-8 --host=ckan-postgres --username=ckan --owner=${CKAN_POSTGRES_USER} ${CKAN_POSTGRES_DB} | ||
psql --host=ckan-postgres --username=ckan --command="CREATE USER ${CKAN_DATASTORE_POSTGRES_READ_USER} WITH PASSWORD '${CKAN_DATASTORE_POSTGRES_READ_PWD}' NOSUPERUSER NOCREATEDB NOCREATEROLE;" | ||
psql --host=ckan-postgres --username=ckan --command="CREATE USER ${CKAN_DATASTORE_POSTGRES_WRITE_USER} WITH PASSWORD '${CKAN_DATASTORE_POSTGRES_WRITE_PWD}' NOSUPERUSER NOCREATEDB NOCREATEROLE;" | ||
createdb --encoding=utf-8 --host=ckan-postgres --username=ckan --owner=${CKAN_DATASTORE_POSTGRES_WRITE_USER} ${CKAN_DATASTORE_POSTGRES_DB} | ||
|
||
# Database Initialization | ||
ckan -c test-core-circle-ci.ini datastore set-permissions | psql --host=ckan-postgres --username=ckan | ||
psql --host=ckan-postgres --username=ckan --dbname=${CKAN_DATASTORE_POSTGRES_DB} --command="CREATE extension tablefunc;" | ||
ckan -c test-core-circle-ci.ini db init | ||
gunzip .test_durations.gz | ||
|
||
# git doesn't like having the directory owned by a different user, and | ||
# we're mounting this in from external, so we don't know the uid/gid. | ||
# this is required to build the docs | ||
git config --global --add safe.directory /usr/src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
|
||
# OS Dependencies | ||
apt update | ||
apt install -y postgresql-client | ||
|
||
#Python Dependencies | ||
pip install -r requirements.txt | ||
pip install -r dev-requirements.txt | ||
python setup.py develop | ||
pip check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
|
||
mkdir -p ~/junit | ||
python -m pytest $PYTEST_COMMON_OPTIONS | ||
|
||
# to split work across containers and run tests in parallel like circleci use commands like: | ||
# note that this requires multiple databases to run without data race collisions, | ||
#python -m pytest $PYTEST_COMMON_OPTIONS --splits 2 --group 1 --splitting-algorithm least_duration & | ||
#python -m pytest $PYTEST_COMMON_OPTIONS --splits 2 --group 2 --splitting-algorithm least_duration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
|
||
|
||
docker compose up -d | ||
docker compose exec ckan test-infrastructure/install_deps.sh | ||
docker compose exec ckan test-infrastructure/init_environment.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
|
||
|
||
docker compose down |