Test Coverage PR-2: Tests added in ./dispatch and ./github subdir.#233
Test Coverage PR-2: Tests added in ./dispatch and ./github subdir.#233mohanmanikanta2299 wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds new unit tests to raise coverage for the github/ and dispatch/ packages, focusing on GitHub auth configuration discovery and GitHub Actions workflow dispatch/polling helpers.
Changes:
- Added table-driven tests for
githubrepo discovery and repository-creation-year lookup. - Added tests for
githubclient auth configuration fallbacks (GH App env/.env,GITHUB_TOKEN, andghCLI config). - Added tests for
dispatchworkflow dispatch, run lookup, and completion polling logic using anhttptestGitHub API.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
github/repo_test.go |
New tests for DiscoverRepo and GetRepoCreationYear. |
github/client_test.go |
New tests for GH App config parsing and client auth fallback selection. |
dispatch/dispatch_test.go |
New tests for dispatch worker flow and Actions run polling/lookup. |
| CreatedAt: &gogithub.Timestamp{Time: time.Date(2021, 6, 15, 0, 0, 0, 0, time.UTC)}, | ||
| } | ||
| w.Header().Set("Content-Type", "application/json") | ||
| require.NoError(t, json.NewEncoder(w).Encode(repoData)) |
| CreatedAt: &gogithub.Timestamp{Time: time.Date(2023, 1, 1, 12, 0, 0, 0, time.UTC)}, | ||
| } | ||
| w.Header().Set("Content-Type", "application/json") | ||
| require.NoError(t, json.NewEncoder(w).Encode(repoData)) |
|
|
||
| // "os/exec" | ||
| "testing" |
| // Copyright IBM Corp. 2023, 2025 | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
ssagarverma
left a comment
There was a problem hiding this comment.
Minor comments. Overall LGTM 👍.
| } | ||
|
|
||
| err := WaitRunFinished(client, baseOpts, run) | ||
| assert.NoError(t, err) |
There was a problem hiding this comment.
assert.NoError(t, err) doesn't seem sufficient here to confirm that the github API call really happened or not. Can we also verify that github API call did not happen and the function immediately return nil.
| }) | ||
|
|
||
| err := WaitRunFinished(client, baseOpts, run) | ||
| assert.Error(t, err) |
There was a problem hiding this comment.
Can we assert the error msg here as well
|
|
||
| res := <-results | ||
| assert.False(t, res.Success) | ||
| assert.Error(t, res.Error) |
There was a problem hiding this comment.
Can we also check res.Name == "test-repo" here
| client := NewGHClient() | ||
| require.NotNil(t, client) | ||
| assert.NotNil(t, client.gh) | ||
| assert.NotNil(t, client.Raw()) |
There was a problem hiding this comment.
Can we also check that unauthenticated client was chosen
| client := NewGHClient() | ||
| require.NotNil(t, client) | ||
| assert.NotNil(t, client.gh) | ||
| assert.NotNil(t, client.Raw()) |
There was a problem hiding this comment.
Same here, can we check the actual client chosen
| // This will attempt to create ghinstallation transport with invalid PEM | ||
| // The function logs an error but still returns a client | ||
| client := NewGHClient() | ||
| require.NotNil(t, client) |
| } | ||
| } | ||
|
|
||
| func TestDiscoverRepo_NotInGitRepo(t *testing.T) { |
There was a problem hiding this comment.
We should add success test case as well for this.
🛠️ Description
Summary
This PR is the 2nd part of the test coverage PRs intended to increase the test coverage of the entire repo from 55% to 80+%, fulfilling our coverage requirements.
Changes Made
./githuband./dispatchpackage.fields,github-org).assert.Equal,assert.Contains) and explicit error checking to validate function outputs and edge cases.requirefor critical initializations (like loggers and flag lookups) to prevent nil-pointer panics during test execution.Testing
go test -v ./...(All tests passing)go test -race ./...(No race conditions detected)🔗 External Links
https://hashicorp.atlassian.net/browse/CCEN-512
👍 Definition of Done
🤔 Can be merged upon approval?
✅
PCI review checklist
I have documented a clear reason for, and description of, the change I am making.
If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.
If applicable, I've documented the impact of any changes to security controls.
Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.