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
Conversation
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.
// 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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
go test -v ./..
(see Testing)gofmt
(see Formatting)go vet
(see Formatting)