Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(testutil): add new function for creating a test bucket #4001

Merged
merged 4 commits into from May 13, 2024

Conversation

BrennaEpp
Copy link
Contributor

@BrennaEpp BrennaEpp commented Apr 19, 2024

Part 1 to bucket creation cleanup.
Part 2 will be a PR replacing all references to CleanBucket with TestBucket or CreateTestBucket.
Part 3 will remove the CleanBucket function.

Deprecates CleanBucket; a followup PR will remove all references to this function. CleanBucket can run into problems of availability due to fast creation after deletion. Instead, unique randomly generated bucket names should be used.

To replace CleanBucket, TestBucket provides a simple way to create a bucket for testing, creating this random name and taking charge of the cleanup.

Checklist

  • I have followed Contributing Guidelines from CONTRIBUTING.MD
  • Tests pass: go test -v ./.. (see Testing)
  • Code formatted: gofmt (see Formatting)
  • Vetting pass: go vet (see Formatting)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

Part 1 to bucket creation cleanup.

Deprecates CleanBucket; a followup PR will remove all references to this function.
CleanBucket can run into problems of availability due to fast creation after deletion. Instead,
unique randomly generated bucket names should be used.

TestBucket provides a simple way to create a bucket for testing, creating this random name
and taking charge of the cleanup.
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Apr 19, 2024
@BrennaEpp BrennaEpp marked this pull request as ready for review April 22, 2024 22:54
@BrennaEpp BrennaEpp requested review from a team as code owners April 22, 2024 22:54
internal/testutil/storage_cleaner.go Show resolved Hide resolved
// CreateTestBucket creates a new bucket with the given prefix and registers a
// cleanup function to delete the bucket and any objects it contains.
// It is equivalent to TestBucket but allows Storage Client re-use.
func CreateTestBucket(ctx context.Context, t *testing.T, client *storage.Client, projectID, prefix string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe re-name these to indicate what the difference is (e.g. CreateBucket vs CreateBucketWithClient)? Also is it actually important to have both functions available? Creating an extra client in a test is not much overhead.

Copy link
Contributor Author

@BrennaEpp BrennaEpp Apr 23, 2024

Choose a reason for hiding this comment

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

So I don't want to change the signature of the CreateTestBucket function since it will break tests. But I agree that we could just create the extra client instead, which is why I named the function that does that something simpler. We could eventually remove this function after moving everything over to TestBucket.

@@ -702,8 +702,6 @@ func TestRPO(t *testing.T) {
t.Fatalf("createBucketTurboReplication: %v", err)
}

testutil.WaitForBucketToExist(ctx, t, bucket)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change relevant to this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's relevant in that it is cleanup as well, this method is no longer relevant with these changes and will also be removed. Outside of testutil this is the only reference to it.

@BrennaEpp BrennaEpp requested a review from tritone May 10, 2024 18:00
@BrennaEpp BrennaEpp enabled auto-merge (squash) May 13, 2024 20:47
@BrennaEpp BrennaEpp merged commit 63a6b58 into GoogleCloudPlatform:main May 13, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants