Skip to content

Cover google_update.go by unit tests#941

Open
iliatsuprik wants to merge 2 commits intoGoogleCloudPlatform:masterfrom
iliatsuprik:googet_update
Open

Cover google_update.go by unit tests#941
iliatsuprik wants to merge 2 commits intoGoogleCloudPlatform:masterfrom
iliatsuprik:googet_update

Conversation

@iliatsuprik
Copy link
Copy Markdown
Contributor

Coverage increased from 0 to 100%

@google-oss-prow google-oss-prow bot requested a review from burov March 31, 2026 14:20
@google-oss-prow
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: iliatsuprik
Once this PR has been reviewed and has the lgtm label, please assign burov 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
Copy link
Copy Markdown

Hi @iliatsuprik. 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.

@burov
Copy link
Copy Markdown
Member

burov commented Apr 13, 2026

/gcbrun

Comment on lines +108 to +112
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

mockCommandRunner := utilmocks.NewMockCommandRunner(mockCtrl)
packages.SetCommandRunner(mockCommandRunner)
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.

Do we really need to recreate mock each time or we can do it just once?

Comment on lines +114 to +127
updatesCmd := utilmocks.EqCmd(exec.Command(googet, "update"))
updatesCall := mockCommandRunner.EXPECT().
Run(ctx, updatesCmd).
Return(tt.updatesOut, []byte("stderr"), tt.updatesErr).
Times(1)

if tt.expectInstall {
installArgs := append([]string{"-noconfirm", "install"}, tt.installPkgNames...)
installCmd := utilmocks.EqCmd(exec.Command(googet, installArgs...))
mockCommandRunner.EXPECT().
Run(ctx, installCmd).
After(updatesCall).
Return(tt.installOut, []byte("stderr"), tt.installErr).
Times(1)
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.

I think declarative way of expected command improve readability of the code and reduce cognitive load of the actual test case, see https://github.com/GoogleCloudPlatform/osconfig/blob/master/packages/pip_test.go#L25

wantErr error
}{
{
desc: "success",
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.

Please be more specific in name of the test, list what is expected result of the test, success is to generic from my perspective, i suggest to have something like "want install command list packages foo and bar"

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 on other cases "updates error" -> "googet update error is propogated"


func TestRunGooGetUpdate(t *testing.T) {
ctx := context.Background()
googet := filepath.Join(os.Getenv("GooGetRoot"), "googet.exe")
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.

Can we avoid reliance on the environment variable here ?

@burov
Copy link
Copy Markdown
Member

burov commented Apr 14, 2026

/gcbrun

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.

2 participants