Add unit tests for zypper.go - #1014
Conversation
|
Hi @bromivipo. Thanks for your PR. I'm waiting for a GoogleCloudPlatform member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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/test-infra repository. |
| defer mockCtrl.Finish() | ||
|
|
||
| mockCommandRunner := utilmocks.NewMockCommandRunner(mockCtrl) | ||
| runner = mockCommandRunner |
There was a problem hiding this comment.
I suppose we can move lines 639-643 out of the test loop (that's done like this in most of the tests), so testing part would be shorter
| defer mockCtrl.Finish() | ||
|
|
||
| mockCommandRunner := utilmocks.NewMockCommandRunner(mockCtrl) | ||
| runner = mockCommandRunner |
There was a problem hiding this comment.
same, can we move mockCommandRunner creation out of the loop. Can we also do this for other tests in this file?
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: bromivipo, iliatsuprik 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 |
|
New changes are detected. LGTM label has been removed. |
|
/gcbrun |
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| if tt.expectedCmd != nil { |
There was a problem hiding this comment.
I guess can be replaced with https://github.com/GoogleCloudPlatform/osconfig/blob/master/util/utiltest/utiltest.go#L208
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| mockCommandRunner.EXPECT(). | ||
| Run(testCtx, utilmocks.EqCmd(expectedCmd)). |
There was a problem hiding this comment.
testCtx -> ctx, see other cases as well
There was a problem hiding this comment.
Removed global testCtx usage across the file and initialized local context in each test function instead
| name: "generic error, want wrapped error", | ||
| stdout: []byte("stdout"), | ||
| mockErr: errors.New("generic error"), | ||
| wantErr: errors.New(`error running /usr/bin/zypper with args ["--gpg-auto-import-keys" "--non-interactive" "install" "--auto-agree-with-licenses" "patch:patch1" "package:pkg1"]: generic error, stdout: "stdout", stderr: "stderr"`), |
There was a problem hiding this comment.
Extract error to variable and give it reasonable name
There was a problem hiding this comment.
Fixed both in this and one other test
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| mockCommandRunner.EXPECT(). |
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| mockCommandRunner.EXPECT(). |
| } | ||
| } | ||
|
|
||
| func TestParseZypperPatchInfo_Errors(t *testing.T) { |
There was a problem hiding this comment.
Avoid defining separate tests fro handling only negative cases, test should cover both success/fail case.
There was a problem hiding this comment.
Merged TestParseZypperPatchInfo_Errors with two existing functions TestParsePatchInfo and TestParsePatchInfo_differentFormatsOfConflictPkgsVersions into TestParseZypperPatchInfo. Changed the way mappings are verified and also shortened patchInfo mocks without losing coverage for edge cases.
|
/gcbrun |
| t.Run(tt.name, func(t *testing.T) { | ||
| utiltest.SetExpectedCommands(ctx, mockCommandRunner, tt.expectedCommands) | ||
|
|
||
| _, _ = ZypperPatches(ctx, tt.options...) |
There was a problem hiding this comment.
Why we're not testing return parameters ?
There was a problem hiding this comment.
Added the return parameter checks. Initially, I didn't test the return values here because I viewed this test primarily as a check for proper command construction with various options.
|
/gcbrun |
This PR contains unit tests for packages/zypper.go
Initial coverage 73.8%. Current coverage: 100%