Skip to content

Commit 7149239

Browse files
committed
docs(contributing): clarify when to use fixtures vs testcontainers-python
Add a Rules-of-Thumb bullet that points new unit tests to `lib.lftest.run()` with fixtures for pure shell-output parsers and to `lib.lftest.run_container()` for checks that need a live service. Call out apache-httpd-status as a candidate for migration.
1 parent c29c036 commit 7149239

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Checklist:
142142
* Return UNKNOWN on missing dependencies or wrong parameters.
143143
* Mainly return WARN. Only return CRIT if the operators want to or have to wake up at night. CRIT means "react immediately".
144144
* EAFP: Easier to ask for forgiveness than permission. This common Python coding style assumes the existence of valid keys or attributes and catches exceptions if the assumption proves false. This clean and fast style is characterized by the presence of many try and except statements.
145+
* **Pick the right unit-test flavor.** If the plugin parses the output of a shell command or an on-disk file, write fixture-based tests driven by `lib.lftest.run()` and a `TESTS` list. They run in a fraction of a second and cover the full `tox` / Python matrix. Only reach for container-based tests (via `lib.lftest.run_container()` and testcontainers-python) when the check has to talk to a live service that cannot realistically be captured as a fixture - a Keycloak API, a Redis instance, a web server. A plugin like [apache-httpd-status](https://github.com/Linuxfabrik/monitoring-plugins/tree/main/check-plugins/apache-httpd-status) is a good candidate for migration, because it currently fakes HTTP responses through fixtures while it could just as well be exercised against an `httpd:alpine` container with the status module enabled.
145146

146147

147148
### Return Codes

0 commit comments

Comments
 (0)