Skip to content

Commit

Permalink
refactor(test): use s3 canned acl
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Pivkin <[email protected]>
  • Loading branch information
nikpivkin committed Nov 26, 2024
1 parent 791d9a9 commit 4d4af75
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions internal/adapters/cloud/aws/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type publicAccessBlock struct {

type bucketDetails struct {
bucketName string
acl string
acl s3types.BucketCannedACL
encrypted bool
loggingEnabled bool
loggingTargetBucket string
Expand All @@ -43,38 +43,38 @@ func Test_S3BucketACLs(t *testing.T) {
name: "simple bucket with public-read acl",
details: bucketDetails{
bucketName: "test-bucket",
acl: "public-read",
acl: s3types.BucketCannedACLPublicRead,
encrypted: false,
},
},
{
name: "simple bucket with authenticated-read acl",
details: bucketDetails{
bucketName: "wide-open-bucket",
acl: "authenticated-read",
acl: s3types.BucketCannedACLAuthenticatedRead,
encrypted: false,
},
},
{
name: "simple bucket with public-read-write acl",
details: bucketDetails{
bucketName: "public-read-write-bucket",
acl: "public-read-write",
acl: s3types.BucketCannedACLPublicReadWrite,
encrypted: false,
},
},
{
name: "simple bucket with private acl and encryption",
details: bucketDetails{
bucketName: "private-bucket",
acl: "private",
acl: s3types.BucketCannedACLPrivate,
encrypted: true,
},
},
}

ra, stack, err := test.CreateLocalstackAdapter(t)
defer func() { _ = stack.Stop() }()
defer stack.Stop()

Check failure on line 77 in internal/adapters/cloud/aws/s3/s3_test.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `stack.Stop` is not checked (errcheck)
require.NoError(t, err)

for _, tt := range tests {
Expand Down Expand Up @@ -296,8 +296,7 @@ func bootstrapBucket(t *testing.T, ra *aws.RootAdapter, spec bucketDetails) {

_, err := api.CreateBucket(ra.Context(), &s3api.CreateBucketInput{
Bucket: awssdk.String(spec.bucketName),

ACL: aclToCannedACL(spec.acl),
ACL: spec.acl,
})
require.NoError(t, err)

Expand Down Expand Up @@ -386,19 +385,6 @@ func createPublicAccessBlock(t *testing.T, api *s3api.Client, ctx context.Contex
require.NoError(t, err)
}

func aclToCannedACL(acl string) s3types.BucketCannedACL {
switch acl {
case "authenticated-read":
return s3types.BucketCannedACLAuthenticatedRead
case "public-read":
return s3types.BucketCannedACLPublicRead
case "public-read-write":
return s3types.BucketCannedACLPublicReadWrite
default:
return s3types.BucketCannedACLPrivate
}
}

func removeBucket(t *testing.T, ra *aws.RootAdapter, spec bucketDetails) {

api := s3api.NewFromConfig(ra.SessionConfig())
Expand Down

0 comments on commit 4d4af75

Please sign in to comment.