test(missions): unit tests for missions pure functions [Part 1 of #17600]#18373
test(missions): unit tests for missions pure functions [Part 1 of #17600]#18373AdeshDeshmukh wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
✅ Deploy Preview for kubestellarconsole canceled.Built without sensitive environment variables
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds new unit tests for the missions handlers package, focusing on input validation and internal helper behavior.
Changes:
- Add tests for Slack webhook URL validation, share repo allowlist resolution, and repo allow/deny checks.
- Add tests for
isDemoModeheader parsing behavior. - Add tests for embedded mission entry “hidden file” filtering.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| pkg/api/handlers/missions/share_test.go | Adds coverage for Slack webhook URL validation and share repo allowlist logic (env-driven + matching). |
| pkg/api/handlers/missions/helpers_test.go | Adds tests for demo-mode detection via X-Demo-Mode header. |
| pkg/api/handlers/missions/embedded_test.go | Adds tests for filtering hidden embedded mission entries. |
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| err := validateSlackWebhookURL(tt.url) | ||
| assert.Error(t, err) | ||
| assert.Contains(t, err.Error(), tt.msg) | ||
| }) | ||
| } |
| os.Setenv(envVar, "org1/repo1,org2/repo2") | ||
|
|
||
| repos := resolveAllowedShareRepos() | ||
| assert.Len(t, repos, 3) |
| t.Cleanup(func() { | ||
| os.Unsetenv(envVar) | ||
| }) | ||
| os.Setenv(envVar, "org1/repo1,org2/repo2") |
| t.Cleanup(func() { | ||
| os.Unsetenv(envVar) | ||
| }) | ||
| os.Setenv(envVar, " org1/repo1 , org2/repo2 ") |
| t.Cleanup(func() { | ||
| os.Unsetenv(envVar) | ||
| }) | ||
| os.Setenv(envVar, "org1/repo1,,org2/repo2") |
| resp, err := app.Test(req, 5000) | ||
| require.NoError(t, err) | ||
| body, _ := io.ReadAll(resp.Body) | ||
| assert.Equal(t, fmt.Sprintf("%t", tt.want), string(body)) |
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| result := embeddedHiddenMissionEntry(tt.entry) | ||
| assert.Equal(t, tt.hidden, result) | ||
| }) | ||
| } |
1f78b3d to
f7cc6b4
Compare
Signed-off-by: AdeshDeshmukh <adeshkd123@gmail.com>
f7cc6b4 to
53eee87
Compare
Picking up issue #17600 — the pkg/api/handlers/ directory has had zero test coverage since the codebase was first built. The child issues (#17605–#17609) were auto-closed by a bot without any actual tests written, so the gap is completely untouched.
This is the first of several focused PRs to fix that. I am starting with the pure functions in the missions package because they have no external dependencies (no HTTP, no DB, no Kubernetes) — which means no mocking infrastructure needed, and tests that run in under a millisecond.
What is in this PR
Three new test files following the existing pattern in types_test.go:
All tests are table-driven with t.Run() subtests, matching the project's existing convention.
Coverage delta
Why these test cases specifically
The allowlist logic (isRepoAllowedForShare) and webhook validation (validateSlackWebhookURL) are security-sensitive. The tests deliberately include adversarial inputs — SSRF vectors, subdomain confusion attacks, path traversal attempts, and protocol injection — not just the happy path. If this logic regresses, the test suite will catch it before it ships.
Test output
58 passed in 1 packages
What comes next
PR 2 will cover feedback/github_helpers.go and feedback/github_prs.go using a mocked GitHub client interface.
Addresses part of #17600