-
Notifications
You must be signed in to change notification settings - Fork 567
NO-JIRA: chore: add unit test naming and placement conventions #8722
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,8 @@ description: "MANDATORY: When writing Go tests, you MUST use 'When...it should.. | |
|
|
||
| ## Test Conventions - MANDATORY | ||
|
|
||
| ### Test naming | ||
|
|
||
| **NON-NEGOTIABLE RULE**: Every Go test name MUST follow this exact format: | ||
| ```go | ||
| name: "When <condition>, it should <expected behavior>" | ||
|
|
@@ -35,7 +37,30 @@ name: "When encryption is enabled, it should configure disk encryption set" | |
| - ✅ "When NodePool has ImageID, it should create basic Azure machine template" | ||
| - ✅ "When subnet ID is invalid, it should return error with subnet parse message" | ||
|
|
||
| ### Unit test function naming | ||
|
|
||
| Unit test functions MUST be named after the function they test, using the standard Go `Test<FunctionName>` convention: | ||
|
|
||
| ```go | ||
| // Testing function ReconcileNodePool | ||
| func TestReconcileNodePool(t *testing.T) { ... } | ||
|
|
||
| // Testing function buildAzureMachineTemplate | ||
| func TestBuildAzureMachineTemplate(t *testing.T) { ... } | ||
| ``` | ||
|
|
||
| **NEVER use generic or disconnected test function names like:** | ||
| - ❌ `TestNodePoolFeatures` | ||
| - ❌ `TestAzureIntegration` | ||
| - ❌ `TestVariousCases` | ||
|
|
||
| Each test function should map 1:1 to the function under test. If a function is complex enough to warrant many test cases, use table-driven tests within a single `Test<FunctionName>` function with the "When...it should..." naming for each case. | ||
|
|
||
| ### Unit test placement | ||
|
|
||
| - **Always include unit tests** when creating new functions or modifying existing ones | ||
| - **Place unit tests next to the code they test** — in the same package directory, in a `_test.go` file | ||
| - **Do NOT place new tests in `test/integration/`** — this is a legacy directory. New unit tests go alongside the code under test. New integration-style tests that require a cluster should use `test/e2e/` or `test/envtest/` | ||
|
Comment on lines
+59
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: Check for references to test/integration/ in documentation and guidance files
# Find documentation files that mention test/integration/
rg -n -C3 'test/integration' --type=md --glob '!.claude/**'
# Also check if test/integration/ directory exists and contains active tests
if [ -d "test/integration" ]; then
echo "=== test/integration directory exists ==="
fd -e go . test/integration | head -20
fiRepository: openshift/hypershift Length of output: 9461 🏁 Script executed: #!/bin/bash
# Show the relevant lines in the skill file for exact wording/context
sed -n '45,90p' .claude/skills/code-formatting/SKILL.md | nl -ba | sed -n '1,120p'Repository: openshift/hypershift Length of output: 105 🏁 Script executed: #!/bin/bash
# Show the relevant lines in the skill file for exact wording/context
sed -n '45,90p' .claude/skills/code-formatting/SKILL.md | nl -ba | sed -n '1,120p'Repository: openshift/hypershift Length of output: 105 🏁 Script executed: #!/bin/bash
# Show the relevant lines in the skill file for exact wording/context
sed -n '45,90p' .claude/skills/code-formatting/SKILL.md | nl -ba | sed -n '1,120p'Repository: openshift/hypershift Length of output: 105 Resolve conflicting
🤖 Prompt for AI Agents |
||
|
|
||
| ## Quick Checklist | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth to also mention the sub-test feature golang has here.
For reference: https://go.dev/blog/subtests#table-driven-tests-using-subtests