Skip to content

Add unit tests for policies/recipes/steps.go PART 2#975

Merged
google-oss-prow[bot] merged 14 commits into
GoogleCloudPlatform:masterfrom
ganochenkodg:recipes-steps-unittests-part2
Jul 8, 2026
Merged

Add unit tests for policies/recipes/steps.go PART 2#975
google-oss-prow[bot] merged 14 commits into
GoogleCloudPlatform:masterfrom
ganochenkodg:recipes-steps-unittests-part2

Conversation

@ganochenkodg

@ganochenkodg ganochenkodg commented May 10, 2026

Copy link
Copy Markdown
Contributor

Second part of unit tests for steps.go:

github.com/GoogleCloudPlatform/osconfig/policies/recipes/steps.go:286: checkForConflicts 65.0% -> 80.0%
github.com/GoogleCloudPlatform/osconfig/policies/recipes/steps.go:268: decompress 28.6% -> 100.0%

@google-oss-prow

Copy link
Copy Markdown

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

if err := tw.Close(); err != nil {
t.Fatalf("failed to close tar writer: %v", err)
}
return &buf

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.

can this be reused in other tests? if so, could you move this to common test utils

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.

Do you mean whole createTarArchive func? it's a setup func for one specific test. If you talk about one if err != nil { } block, it's too simple and short imo to create a helper

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'm talking about the whole func. If we don't need something like this in other tests, lets keep as it is

Comment thread policies/recipes/steps_test.go Outdated
func Test_checkForConflicts(t *testing.T) {
tmpDir := t.TempDir()
existingFile := "exists.txt"
os.WriteFile(filepath.Join(tmpDir, existingFile), []byte("content"), 0644)

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.

utiltest has a method WriteToTempFileMust, can you check if that can be reused here?

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.

yes, applied suggested fix

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

// Test_checkForConflicts verifies that archive extraction does not overwrite existing files.
func Test_checkForConflicts(t *testing.T) {

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.

Lets stick to pascal case

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, it is a common pattern to name test for private functions this way

@burov

burov commented Jun 24, 2026

Copy link
Copy Markdown
Member

/gcbrun

}

// Test_checkForConflicts verifies that archive extraction does not overwrite existing files.
func Test_checkForConflicts(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.

Same comment, it is a common pattern to name test for private functions this way

Comment thread policies/recipes/steps_test.go Outdated

// Test_checkForConflicts verifies that archive extraction does not overwrite existing files.
func Test_checkForConflicts(t *testing.T) {
existingFile := "exists.txt"

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.

Inline this variable as it used only in one place.

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

@google-oss-prow google-oss-prow Bot added size/XS and removed size/L labels Jul 1, 2026
@google-oss-prow google-oss-prow Bot added size/L and removed size/XS labels Jul 1, 2026
@petercieslak

Copy link
Copy Markdown
Contributor

/gcbrun

@petercieslak

Copy link
Copy Markdown
Contributor

/gcbrun

@petercieslak

Copy link
Copy Markdown
Contributor

/ok-to-test

@google-oss-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: burov, ganochenkodg, iliatsuprik, petercieslak

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

The pull request process is described 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 Jul 7, 2026
@google-oss-prow

Copy link
Copy Markdown

New changes are detected. LGTM label has been removed.

@petercieslak

Copy link
Copy Markdown
Contributor

/gcbrun

@petercieslak

Copy link
Copy Markdown
Contributor

/ok-to-test

@petercieslak

Copy link
Copy Markdown
Contributor

/test ?

@google-oss-prow

Copy link
Copy Markdown

@petercieslak: The following commands are available to trigger required jobs:

  • /gobuild
  • /gocheck
  • /gotest

Use /test all to run all jobs.

Details

In response to this:

/test ?

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.

@google-oss-prow google-oss-prow Bot merged commit c0faeb2 into GoogleCloudPlatform:master Jul 8, 2026
13 checks passed
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.

4 participants