-
Notifications
You must be signed in to change notification settings - Fork 26
docs: DESIGN_GUIDE.md #794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zkraus
wants to merge
4
commits into
Kuadrant:main
Choose a base branch
from
zkraus:design_guide
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,104 @@ | ||
| # The Design Guide - How to design tests, and how to review them | ||
|
|
||
| This is not a rule book, just a compilation of guidelines, tips, and thoughts. | ||
|
|
||
| ## Atomic tests | ||
|
|
||
| While atomic test cases are a great way of designing test at unit test level, | ||
| for End-to-End tests it might not be great Return of Investment. But please consider | ||
| atomic test case design principles in your test design. | ||
|
|
||
| * Is it possible to extract some portion of my test into fixture/setup? | ||
| * Could some of it be reused by multiple test cases? | ||
| * Is that possible to do, while not destroying tests runtime or making complex fixture desing? | ||
|
|
||
| Just considering the principles, might give you an idea of new test cases, that | ||
| might be useful to write. | ||
|
|
||
| ## Fixture Design | ||
|
|
||
| 1. Use simple, descriptive names: `route`, `authorization`, `backend`, `gateway`, `hostname`, `client` | ||
| 1. For multiple instances of the same resource, append a number to secondary resources: `route2`, `backend2`, `authorization2` | ||
| 1. The primary resource always uses the plain name without a number | ||
| 1. Use `blame()` to generate unique, scoped names for Kubernetes resources: `blame("gw")` → `"gw-alice-tc-abc"` | ||
| 1. Choose appropriate fixture scope: | ||
| * `scope="session"` - Created once per test run (e.g., `cluster`, `backend`, `gateway`) | ||
| * `scope="module"` - Created per test module (e.g., `route`, `authorization`, `rate_limit`) | ||
| * `scope="function"` - Created per test (rarely used, only for parametrized or stateful tests) | ||
|
|
||
| ## Code Quality | ||
|
|
||
| 1. **Every module and fixture must have a short, descriptive docstring** | ||
| * Module docstrings describe the test scope | ||
| * Fixture docstrings describe what they create or return, not how | ||
| 1. **Always look for a more correct solution before disabling a pylint warning** | ||
| * Legitimate uses: `# pylint: disable=unused-argument` for pytest dependency ordering | ||
| * Legitimate uses: `# pylint: disable=invalid-name` for Kubernetes API camelCase fields | ||
|
|
||
| ## Commits | ||
|
|
||
| 1. Consider using https://www.conventionalcommits.org/en/v1.0.0/ (.gitmessage) | ||
| 1. Run `make reformat` and `make commit-acceptance` locally to catch code analysis or formatting issues before committing and pushing | ||
| 1. Sign off commits by adding the `-s` flag (`git commit -s`) | ||
| 1. Optionally, sign commits with the `-S` flag (`git commit -S`) if you have a GPG or SSH key configured — this verifies commit authenticity on GitHub | ||
|
|
||
| ## Creating PRs | ||
|
|
||
| 1. To promote quality code, request 2 reviewers | ||
| 1. Link relevant issues, and/or summarize the changes | ||
| 1. Use the `/pr-description` command to generate comprehensive PR descriptions with verification steps | ||
| 1. Ensure CI checks pass before opening a PR (e.g., DCO sign-off, code analysis, GitGuardian) | ||
| 1. Use a draft PR to share work in progress and gather early feedback before marking it ready for review | ||
|
|
||
| ## Reviewing PRs | ||
|
|
||
| 1. Focus on readability | ||
| 1. Is the test placed in correct path? | ||
| 1. Consider test structure and design, can it be improved without impacting runtime? | ||
| 1. Is the test easy to debug on Failure or Error? | ||
|
|
||
| ### precommit hook | ||
|
|
||
| Consider using secret guarding precommit hooks in your git setup to prevent secret leaking: | ||
|
|
||
| 1. Install pre-commit framework: https://pre-commit.com/ | ||
| 1. Use gitleaks (https://github.com/gitleaks/gitleaks) or similar tools to detect hardcoded secrets | ||
| 1. Example `.pre-commit-config.yaml`: | ||
| ```yaml | ||
| repos: | ||
| - repo: https://github.com/gitleaks/gitleaks | ||
| rev: v8.18.2 | ||
| hooks: | ||
| - id: gitleaks | ||
| ``` | ||
| 1. Install hooks: `pre-commit install` | ||
|
|
||
| ### .gitmessage | ||
|
|
||
| Currently optional, you may use a file (conventionally) named `.gitmessage`, | ||
| and configure your git to use it as a commit message template. | ||
|
|
||
| For example `.gitmessage`: | ||
|
|
||
| ```text | ||
| # test: | ||
| # test(): | ||
|
|
||
| # Description: | ||
|
|
||
|
|
||
| # Footer: | ||
|
|
||
|
|
||
| # See also: https://www.conventionalcommits.org/en/v1.0.0/ | ||
| ``` | ||
|
|
||
| And git configuration: | ||
|
|
||
| ```shell | ||
| git config commit.template=.gitmessage | ||
| ``` | ||
|
|
||
| next time you commit, your editor will be prefilled with the templates, and as | ||
| usual, anything that is a comment `#` will be ignored. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.