CCXDEV-15561: Improve test coverage 4#1226
CCXDEV-15561: Improve test coverage 4#1226openshift-merge-bot[bot] merged 7 commits intoopenshift:masterfrom
Conversation
|
@katushiik11: This pull request references CCXDEV-15561 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.22.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
/retest |
2 similar comments
|
/retest |
|
/retest |
ncaak
left a comment
There was a problem hiding this comment.
Overall, it looks good.
I have a few minor concerns about some field names, such as "now" and "expected," which could be more specific. However, the tests are readable, so I won't push for a refactor.
I approve these changes, but I'll let @opokornyy give final approval and the "lgtm" label.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: katushiik11, ncaak The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/test lint |
1 similar comment
|
/test lint |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds seven new test files exercising archive obfuscation, periodic datagather informer, container/pod health checks, and several line-based utility functions; all changes are test-only with no production code modifications. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.11.3)Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can approve the review once all CodeRabbit's comments are resolved.Enable the |
|
@katushiik11: This pull request references CCXDEV-15561 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.22.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pkg/utils/line_limit_reader_test.go (1)
67-80:expectEOFis misleading when usingio.ReadAll.
io.ReadAllconsumes EOF and typically returnserr == nil, so this branch doesn’t actually validate EOF behavior. This weakens readability and test intent.Proposed cleanup
- n, err := io.ReadAll(limitedReader) - - if tt.expectEOF { - // For limited reads, we expect some data followed by EOF - assert.Equal(t, tt.expectedOutput, string(n)) - } else { - // For unlimited or empty reads - if err != nil && err != io.EOF { - t.Fatalf("unexpected error: %v", err) - } - if len(tt.input) > 0 { - assert.Equal(t, tt.expectedOutput, string(n)) - } - } + n, err := io.ReadAll(limitedReader) + assert.NoError(t, err) + assert.Equal(t, tt.expectedOutput, string(n))🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/utils/line_limit_reader_test.go` around lines 67 - 80, The test's use of tt.expectEOF with io.ReadAll is misleading because io.ReadAll consumes EOF and usually returns nil error; update the test around io.ReadAll(limitedReader) so it no longer branches on tt.expectEOF: always assert the returned bytes match tt.expectedOutput (using string(n)), and if you need to verify EOF behavior explicitly use a different read strategy (e.g., call limitedReader.Read with a buffer or io.ReadFull and check for io.EOF) to assert EOF semantics for the limitedReader; adjust references to tt.expectEOF, io.ReadAll, and limitedReader accordingly so the intent is clear.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cmd/obfuscate-archive/main_test.go`:
- Around line 149-159: The test case labeled "invalid JSON returns nil error"
currently expects no error for malformed ingress JSON; change the test table
entry to set expectError: true (and keep expectedDomain empty) and update the
test assertion in the table-driven test (the test function that iterates over
the cases, e.g., Test... in main_test.go that uses the case fields
invalidJSON/expectError/expectedDomain) to assert an error is returned when
invalidJSON is true, ensuring the ingress JSON parsing path (the parser invoked
by the test) surfaces parse failures rather than treating malformed input as
success.
---
Nitpick comments:
In `@pkg/utils/line_limit_reader_test.go`:
- Around line 67-80: The test's use of tt.expectEOF with io.ReadAll is
misleading because io.ReadAll consumes EOF and usually returns nil error; update
the test around io.ReadAll(limitedReader) so it no longer branches on
tt.expectEOF: always assert the returned bytes match tt.expectedOutput (using
string(n)), and if you need to verify EOF behavior explicitly use a different
read strategy (e.g., call limitedReader.Read with a buffer or io.ReadFull and
check for io.EOF) to assert EOF semantics for the limitedReader; adjust
references to tt.expectEOF, io.ReadAll, and limitedReader accordingly so the
intent is clear.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 3f078cd4-c43b-445a-82f5-32b64aae5d6f
📒 Files selected for processing (7)
cmd/obfuscate-archive/main_test.gopkg/controller/periodic/datagather_informer_test.gopkg/utils/check/has_container_in_crashloop_test.gopkg/utils/check/is_healthy_pod_test.gopkg/utils/count_lines_test.gopkg/utils/gatherers_test.gopkg/utils/line_limit_reader_test.go
| name: "invalid JSON returns nil error", | ||
| ingress: &configv1.Ingress{ | ||
| Spec: configv1.IngressSpec{ | ||
| Domain: "test.example.com", | ||
| }, | ||
| }, | ||
| includeRecord: true, | ||
| invalidJSON: true, | ||
| expectError: false, | ||
| expectedDomain: "", | ||
| }, |
There was a problem hiding this comment.
Don’t treat malformed ingress JSON as a successful parse.
Expecting nil error for invalid JSON can hide corrupted archive input and weakens failure signaling in this path.
Suggested test expectation adjustment
- {
- name: "invalid JSON returns nil error",
+ {
+ name: "error - invalid JSON",
ingress: &configv1.Ingress{
Spec: configv1.IngressSpec{
Domain: "test.example.com",
},
},
includeRecord: true,
invalidJSON: true,
- expectError: false,
- expectedDomain: "",
+ expectError: true,
+ errorContains: "invalid character",
+ expectedDomain: "",
},📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| name: "invalid JSON returns nil error", | |
| ingress: &configv1.Ingress{ | |
| Spec: configv1.IngressSpec{ | |
| Domain: "test.example.com", | |
| }, | |
| }, | |
| includeRecord: true, | |
| invalidJSON: true, | |
| expectError: false, | |
| expectedDomain: "", | |
| }, | |
| name: "error - invalid JSON", | |
| ingress: &configv1.Ingress{ | |
| Spec: configv1.IngressSpec{ | |
| Domain: "test.example.com", | |
| }, | |
| }, | |
| includeRecord: true, | |
| invalidJSON: true, | |
| expectError: true, | |
| errorContains: "invalid character", | |
| expectedDomain: "", | |
| }, |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@cmd/obfuscate-archive/main_test.go` around lines 149 - 159, The test case
labeled "invalid JSON returns nil error" currently expects no error for
malformed ingress JSON; change the test table entry to set expectError: true
(and keep expectedDomain empty) and update the test assertion in the
table-driven test (the test function that iterates over the cases, e.g., Test...
in main_test.go that uses the case fields
invalidJSON/expectError/expectedDomain) to assert an error is returned when
invalidJSON is true, ensuring the ingress JSON parsing path (the parser invoked
by the test) surfaces parse failures rather than treating malformed input as
success.
|
@katushiik11: This pull request references CCXDEV-15561 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.22.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
/lgtm |
|
@opokornyy: This PR has been marked as verified by DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
@katushiik11: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
This PR implements tests to improve test coverage in directories, utils, utils/check, controller/periodic & cmd/obfuscate-archive.
Categories
Sample Archive
Documentation
Unit Tests
pkg/utils/count_lines_test.gopkg/utils/gatherers_test.gopkg/utils/line_limit_reader_test.gopkg/utils/check/has_container_in_crashloop_test.gopkg/utils/check/is_healthy_pod_test.gopkg/controller/periodic/datagather_informer_test.gocmd/obfuscate-archive/main_test.goPrivacy
Yes. There are no sensitive data in the newly collected information.
Changelog
No
Breaking Changes
No
References
https://issues.redhat.com/browse/CCXDEV-15561
Summary by CodeRabbit