Skip to content

Add unit tests for zypper.go - #1014

Open
bromivipo wants to merge 16 commits into
GoogleCloudPlatform:masterfrom
bromivipo:zypper
Open

Add unit tests for zypper.go#1014
bromivipo wants to merge 16 commits into
GoogleCloudPlatform:masterfrom
bromivipo:zypper

Conversation

@bromivipo

Copy link
Copy Markdown
Contributor

This PR contains unit tests for packages/zypper.go
Initial coverage 73.8%. Current coverage: 100%

@google-oss-prow

Copy link
Copy Markdown

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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 kubernetes/test-infra repository.

Comment thread packages/zypper_test.go Outdated
defer mockCtrl.Finish()

mockCommandRunner := utilmocks.NewMockCommandRunner(mockCtrl)
runner = mockCommandRunner

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread packages/zypper_test.go Outdated
defer mockCtrl.Finish()

mockCommandRunner := utilmocks.NewMockCommandRunner(mockCtrl)
runner = mockCommandRunner

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, can we move mockCommandRunner creation out of the loop. Can we also do this for other tests in this file?

@google-oss-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: bromivipo, iliatsuprik
Once this PR has been reviewed and has the lgtm label, please assign ekremenetskii for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow Bot removed the lgtm label Jun 23, 2026
@google-oss-prow

Copy link
Copy Markdown

New changes are detected. LGTM label has been removed.

@bromivipo
bromivipo marked this pull request as ready for review June 24, 2026 09:01
@google-oss-prow
google-oss-prow Bot requested review from burov and zoltak-g June 24, 2026 09:02
@burov

burov commented Jul 17, 2026

Copy link
Copy Markdown
Member

/gcbrun

Comment thread packages/zypper_test.go Outdated

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.expectedCmd != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread packages/zypper_test.go Outdated
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mockCommandRunner.EXPECT().
Run(testCtx, utilmocks.EqCmd(expectedCmd)).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testCtx -> ctx, see other cases as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed global testCtx usage across the file and initialized local context in each test function instead

Comment thread packages/zypper_test.go Outdated
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"`),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract error to variable and give it reasonable name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed both in this and one other test

Comment thread packages/zypper_test.go Outdated

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mockCommandRunner.EXPECT().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about util

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread packages/zypper_test.go Outdated

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mockCommandRunner.EXPECT().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about util

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread packages/zypper_test.go Outdated
}
}

func TestParseZypperPatchInfo_Errors(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid defining separate tests fro handling only negative cases, test should cover both success/fail case.

@bromivipo bromivipo Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@burov

burov commented Jul 28, 2026

Copy link
Copy Markdown
Member

/gcbrun

Comment thread packages/zypper_test.go Outdated
t.Run(tt.name, func(t *testing.T) {
utiltest.SetExpectedCommands(ctx, mockCommandRunner, tt.expectedCommands)

_, _ = ZypperPatches(ctx, tt.options...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we're not testing return parameters ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@burov

burov commented Aug 19, 2026

Copy link
Copy Markdown
Member

/gcbrun

@google-oss-prow google-oss-prow Bot added size/XL and removed size/L labels Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants