Skip to content

Commit

Permalink
cloud: use uuid as bucket name
Browse files Browse the repository at this point in the history
Previously, the GCS and S3 tests used hard coded bucket names to test
the behavior of buckets that do not exist. Now, the tests use a random
UUID. This change is necessary because someone appears to have created
the GCP bucket which causes the test to fail.

Release Justification: Test Only Change
Release Note: None
Fixes: cockroachdb#135307
Fixes: cockroachdb#135348
Fixes: cockroachdb#135349
Fixes: cockroachdb#135350
Fixes: cockroachdb#135351
Fixes: cockroachdb#135352
  • Loading branch information
jeffswenson committed Nov 18, 2024
1 parent 6649dad commit 627c9ac
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions pkg/cloud/amazon/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ go_test(
"//pkg/testutils",
"//pkg/testutils/skip",
"//pkg/util/leaktest",
"//pkg/util/uuid",
"@com_github_aws_aws_sdk_go//aws/awserr",
"@com_github_aws_aws_sdk_go//aws/request",
"@com_github_aws_aws_sdk_go_v2_config//:config",
Expand Down
12 changes: 6 additions & 6 deletions pkg/cloud/amazon/s3_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/testutils/skip"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/uuid"
"github.com/cockroachdb/errors"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -529,11 +530,11 @@ func TestS3BucketDoesNotExist(t *testing.T) {
q.Add(cloud.AuthParam, cloud.AuthParamImplicit)
q.Add(S3RegionParam, "us-east-1")

// Very long, very random bucket name, that hopefully nobody will ever create.
bucket := "VIBK1H88MOJ665V2RAPVH6X3TWUS0HCWTW5A27AFPPLHMABKH7X445K86K1BP2"
u := url.URL{
Scheme: "s3",
Host: bucket,
Scheme: "s3",
// Use UUID to create a random bucket name that does not exist. If this was
// a constent, someone could create the bucket and break the test.
Host: uuid.NewV4().String(),
Path: "backup-test",
RawQuery: q.Encode(),
}
Expand Down Expand Up @@ -563,8 +564,7 @@ func TestS3BucketDoesNotExist(t *testing.T) {
}

_, _, err = s.ReadFile(ctx, "", cloud.ReadOptions{NoFileSize: true})
require.Error(t, err, "")
require.True(t, errors.Is(err, cloud.ErrFileDoesNotExist), "error is not cloud.ErrFileDoesNotExist: %v", err)
require.ErrorIs(t, err, cloud.ErrFileDoesNotExist)
}

func TestAntagonisticS3Read(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions pkg/cloud/gcp/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ go_test(
"//pkg/testutils/skip",
"//pkg/util/ioctx",
"//pkg/util/leaktest",
"//pkg/util/uuid",
"@com_github_cockroachdb_errors//:errors",
"@com_github_googleapis_gax_go_v2//apierror",
"@com_github_stretchr_testify//assert",
Expand Down
13 changes: 6 additions & 7 deletions pkg/cloud/gcp/gcs_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/testutils/skip"
"github.com/cockroachdb/cockroach/pkg/util/ioctx"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/cockroach/pkg/util/uuid"
"github.com/stretchr/testify/require"
"golang.org/x/oauth2/google"
)
Expand Down Expand Up @@ -355,13 +355,13 @@ func TestFileDoesNotExist(t *testing.T) {
)
require.NoError(t, err)
_, _, err = s.ReadFile(context.Background(), "", cloud.ReadOptions{NoFileSize: true})
require.Error(t, err, "")
require.True(t, errors.Is(err, cloud.ErrFileDoesNotExist))
require.ErrorIs(t, err, cloud.ErrFileDoesNotExist)
}

{
// Invalid gsBucket.
gsFile := "gs://cockroach-fixtures-us-east1-invalid/tpch-csv/sf-1/region.tbl?AUTH=implicit"
// Use a random UUID as the name of the bucket that does not exist in order
// to avoid name squating.
gsFile := fmt.Sprintf("gs://%s/tpch-csv/sf-1/region.tbl?AUTH=implicit", uuid.NewV4())
conf, err := cloud.ExternalStorageConfFromURI(gsFile, user)
require.NoError(t, err)

Expand All @@ -373,8 +373,7 @@ func TestFileDoesNotExist(t *testing.T) {
)
require.NoError(t, err)
_, _, err = s.ReadFile(context.Background(), "", cloud.ReadOptions{NoFileSize: true})
require.Error(t, err, "")
require.True(t, errors.Is(err, cloud.ErrFileDoesNotExist))
require.ErrorIs(t, err, cloud.ErrFileDoesNotExist)
}
}

Expand Down

0 comments on commit 627c9ac

Please sign in to comment.