Skip to content

Commit 2051e7f

Browse files
feat: run single integration tests from dev mode (#14486)
* feat: allow running single integration tests from dev mode Add integration-tests service with a Docker Compose profile to the dev override, so a single integration test can be run against the running dev stack without switching environments via setEnv.sh. Also ignore the harmless Cross-Origin-Opener-Policy Chrome warning in integration tests (occurs over HTTP) and remove the now-unnecessary DD_SECURE_CROSS_ORIGIN_OPENER_POLICY overrides. Configure logging in the integration test base class so test output is visible. * fix: keep DD_SECURE_CROSS_ORIGIN_OPENER_POLICY in integration tests override The base_test_class.py change to ignore the COOP warning is not yet on the bugfix branch, so the full integration test suite still needs this setting to avoid Chrome SEVERE console errors over HTTP. * fix: add executable bit and platform: linux/amd64 for integration-tests - Set executable bit on run-integration-test-dev.sh - Add platform: "linux/amd64" to integration-tests service in both dev and integration_tests overrides (Chromium doesn't work on aarch64)
1 parent 402b64a commit 2051e7f

5 files changed

Lines changed: 58 additions & 4 deletions

File tree

docker-compose.override.dev.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,22 @@ services:
7373
mode: host
7474
"webhook.endpoint":
7575
image: mccutchen/go-httpbin:2.20.0@sha256:b1620821b6ff191d911629f87a720b88df5397c2554045f1cfb1ffde17c9b898
76+
integration-tests:
77+
platform: "linux/amd64"
78+
profiles:
79+
- integration
80+
build:
81+
context: ./
82+
dockerfile: ${INTEGRATION_TESTS_DOCKERFILE:-Dockerfile.integration-tests-debian}
83+
image: "defectdojo/defectdojo-integration-tests:${INTEGRATION_TESTS_VERSION:-latest}"
84+
depends_on:
85+
- nginx
86+
- uwsgi
87+
entrypoint: ['/wait-for-it.sh', '${DD_DATABASE_HOST:-postgres}:${DD_DATABASE_PORT:-5432}', '-t', '30', '--', '/app/docker/entrypoint-integration-tests.sh']
88+
volumes:
89+
- '.:/app:z'
90+
environment:
91+
DD_BASE_URL: 'http://nginx:8080/'
92+
DD_ADMIN_USER: "${DD_ADMIN_USER:-admin}"
93+
DD_ADMIN_PASSWORD: "${DD_ADMIN_PASSWORD:-admin}"
94+
DD_INTEGRATION_TEST_FILENAME: "${DD_INTEGRATION_TEST_FILENAME:-}"

docker-compose.override.integration_tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
services:
33
integration-tests:
4+
platform: "linux/amd64"
45
build:
56
context: ./
67
dockerfile: ${INTEGRATION_TESTS_DOCKERFILE:-Dockerfile.integration-tests-debian}

readme-docs/DOCKER.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,20 @@ Check the logs with:
353353
docker compose logs -f integration-tests
354354
```
355355

356+
### Running a single integration test from dev mode
357+
358+
If your dev stack is already running (`docker/setEnv.sh dev && docker compose up`), you can run a single integration test without switching environments.
359+
The dev override includes an `integration-tests` service behind a Docker Compose profile, so it won't start during normal `docker compose up`.
360+
361+
Make sure the dev containers are up and healthy before running the test:
362+
363+
```
364+
./run-integration-test-dev.sh tests/finding_test.py
365+
```
366+
367+
This spins up the integration test runner container against your running dev stack and tears it down when done.
368+
Note that test data is created in your dev database — the integration tests attempt to clean up after themselves.
369+
356370
# Checking Docker versions
357371

358372
Run the following to determine the versions for docker and docker compose:

run-integration-test-dev.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# Run a single integration test against the running dev stack.
3+
# Requires dev mode to be active (./docker/setEnv.sh dev && docker compose up).
4+
#
5+
# Usage:
6+
# ./run-integration-test-dev.sh tests/finding_test.py
7+
# ./run-integration-test-dev.sh tests/risk_acceptance_test.py
8+
9+
set -e
10+
11+
TEST_FILE="${1:?Usage: $0 <test-file>}"
12+
13+
docker compose --profile integration run --rm --no-deps \
14+
-e "DD_INTEGRATION_TEST_FILENAME=${TEST_FILE}" \
15+
-e "LOG_LEVEL=${LOG_LEVEL:-INFO}" \
16+
integration-tests

tests/base_test_class.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
from selenium.webdriver.support.ui import WebDriverWait
1414

1515
# import time
16+
logging.basicConfig(
17+
level=os.environ.get("LOG_LEVEL", "WARNING"),
18+
format="%(levelname)s %(name)s: %(message)s",
19+
)
1620
logger = logging.getLogger(__name__)
1721

1822

@@ -403,7 +407,7 @@ def assertNoConsoleErrors(self):
403407
The addition of the trigger exception is due to the Report Builder tests.
404408
The addition of the innerHTML exception is due to the test for quick reports in finding_test.py
405409
"""
406-
accepted_javascript_messages = r"(zoom\-in\.cur.*)404\ \(Not\ Found\)|Uncaught TypeError: Cannot read properties of null \(reading \'trigger\'\)|Uncaught TypeError: Cannot read properties of null \(reading \'innerHTML\'\)"
410+
accepted_javascript_messages = r"(zoom\-in\.cur.*)404\ \(Not\ Found\)|Uncaught TypeError: Cannot read properties of null \(reading \'trigger\'\)|Uncaught TypeError: Cannot read properties of null \(reading \'innerHTML\'\)|Cross-Origin-Opener-Policy header has been ignored"
407411

408412
if entry["level"] == "SEVERE":
409413
# TODO: actually this seems to be the previous url
@@ -420,12 +424,12 @@ def assertNoConsoleErrors(self):
420424
+ self.driver.current_url,
421425
)
422426
if self.accept_javascript_errors:
423-
logger.warning(
427+
logger.debug(
424428
"skipping SEVERE javascript error because accept_javascript_errors is True!",
425429
)
426430
elif re.search(accepted_javascript_messages, entry["message"]):
427-
logger.warning(
428-
"skipping javascript errors related to known issues images, see https://github.com/DefectDojo/django-DefectDojo/blob/master/tests/base_test_class.py#L324",
431+
logger.debug(
432+
"skipping javascript errors related to known issues, see https://github.com/DefectDojo/django-DefectDojo/blob/master/tests/base_test_class.py#L324",
429433
)
430434
else:
431435
self.assertNotEqual(entry["level"], "SEVERE")

0 commit comments

Comments
 (0)