Skip to content

Commit

Permalink
feat: add a progress bar and quiet option
Browse files Browse the repository at this point in the history
  • Loading branch information
go-to-k committed Sep 20, 2023
1 parent 0fc4968 commit 7469ba2
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 33 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ This tool allows you to **search for bucket names** and empty or delete **multip
- ForceMode (Delete the bucket together)
- -i, --interactive: optional
- Interactive Mode for buckets selection
- -q, --quiet: optional
- Not to display a progress bar

## Interactive Mode

Expand Down
19 changes: 11 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ module github.com/go-to-k/cls3
go 1.18

require (
github.com/AlecAivazis/survey/v2 v2.3.6
github.com/aws/aws-sdk-go-v2 v1.20.2
github.com/aws/aws-sdk-go-v2/config v1.18.0
github.com/aws/aws-sdk-go-v2/service/s3 v1.38.3
github.com/aws/smithy-go v1.14.1
github.com/golang/mock v1.6.0
github.com/rs/zerolog v1.30.0
github.com/schollz/progressbar/v3 v3.13.1
github.com/urfave/cli/v2 v2.25.0
go.uber.org/goleak v1.2.1
golang.org/x/sync v0.3.0
)

require go.uber.org/goleak v1.2.1 // indirect

require (
github.com/AlecAivazis/survey/v2 v2.3.6
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.12 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.0 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.19 // indirect
Expand All @@ -29,16 +31,17 @@ require (
github.com/aws/aws-sdk-go-v2/service/sso v1.11.25 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.13.8 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.17.2 // indirect
github.com/aws/smithy-go v1.14.1
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/sync v0.3.0
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.3.8 // indirect
)
27 changes: 22 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,40 @@ github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c=
github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/schollz/progressbar/v3 v3.13.1 h1:o8rySDYiQ59Mwzy2FELeHY5ZARXZTVJC7iHD6PEFUiE=
github.com/schollz/progressbar/v3 v3.13.1/go.mod h1:xvrbki8kfT1fzWzBT/UZd9L6GA+jdL7HAgq2RFnO6fQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/urfave/cli/v2 v2.25.0 h1:ykdZKuQey2zq0yin/l7JOm9Mh+pg72ngYMeB0ABn6q8=
github.com/urfave/cli/v2 v2.25.0/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
Expand All @@ -107,11 +120,15 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 h1:b8jxX3zqjpqb2LklXPzKSGJhzyxCOZSz8ncv8Nv+y7w=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
Expand Down
10 changes: 9 additions & 1 deletion internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type App struct {
Region string
ForceMode bool
InteractiveMode bool
Quiet bool
}

func NewApp(version string) *App {
Expand Down Expand Up @@ -65,6 +66,13 @@ func NewApp(version string) *App {
Usage: "Interactive Mode",
Destination: &app.InteractiveMode,
},
&cli.BoolFlag{
Name: "quiet",
Aliases: []string{"q"},
Value: false,
Usage: "Not to display a progress bar",
Destination: &app.Quiet,
},
},
}

Expand Down Expand Up @@ -118,7 +126,7 @@ func (a *App) getAction() func(c *cli.Context) error {
}

for _, bucket := range a.BucketNames.Value() {
if err := s3Wrapper.ClearS3Objects(c.Context, bucket, a.ForceMode); err != nil {
if err := s3Wrapper.ClearS3Objects(c.Context, bucket, a.ForceMode, a.Quiet); err != nil {
return err
}
}
Expand Down
18 changes: 12 additions & 6 deletions internal/wrapper/s3_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewS3Wrapper(client client.IS3) *S3Wrapper {
}
}

func (s *S3Wrapper) ClearS3Objects(ctx context.Context, bucketName string, forceMode bool) error {
func (s *S3Wrapper) ClearS3Objects(ctx context.Context, bucketName string, forceMode bool, quiet bool) error {
exists, err := s.client.CheckBucketExists(ctx, aws.String(bucketName))
if err != nil {
return err
Expand All @@ -35,13 +35,19 @@ func (s *S3Wrapper) ClearS3Objects(ctx context.Context, bucketName string, force
return err
}

io.Logger.Info().Msgf("%v Checking...", bucketName)

versions, err := s.client.ListObjectVersions(ctx, aws.String(bucketName), region)
if err != nil {
return err
}

if len(versions) > 0 {
errors, err := s.client.DeleteObjects(ctx, aws.String(bucketName), versions, region)
if len(versions) == 0 {
io.Logger.Info().Msgf("%v No objects.", bucketName)
} else {
io.Logger.Info().Msgf("%v Clearing...", bucketName)

errors, err := s.client.DeleteObjects(ctx, aws.String(bucketName), versions, region, quiet)
if err != nil {
return err
}
Expand All @@ -55,15 +61,15 @@ func (s *S3Wrapper) ClearS3Objects(ctx context.Context, bucketName string, force
}
return fmt.Errorf("DeleteObjectsError: followings %v", errorStr)
}
}

io.Logger.Info().Msgf("%v Cleared.", bucketName)
io.Logger.Info().Msgf("%v Cleared!!", bucketName)
}

if forceMode {
if err := s.client.DeleteBucket(ctx, aws.String(bucketName), region); err != nil {
return err
}
io.Logger.Info().Msgf("%v Deleted.", bucketName)
io.Logger.Info().Msgf("%v Deleted!!", bucketName)
}

return nil
Expand Down
51 changes: 45 additions & 6 deletions internal/wrapper/s3_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {
ctx context.Context
bucketName string
forceMode bool
quiet bool
}

cases := []struct {
Expand All @@ -39,6 +40,7 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {
ctx: context.Background(),
bucketName: "test",
forceMode: false,
quiet: false,
},
prepareMockFn: func(m *client.MockIS3) {
m.EXPECT().CheckBucketExists(gomock.Any(), aws.String("test")).Return(true, nil)
Expand All @@ -54,7 +56,34 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {
VersionId: aws.String("VersionIdForDeleteMarkers"),
},
}, nil)
m.EXPECT().DeleteObjects(gomock.Any(), aws.String("test"), gomock.Any(), "ap-northeast-1").Return([]types.Error{}, nil)
m.EXPECT().DeleteObjects(gomock.Any(), aws.String("test"), gomock.Any(), "ap-northeast-1", gomock.Any()).Return([]types.Error{}, nil)
},
want: nil,
wantErr: false,
},
{
name: "clear objects with quiet successfully",
args: args{
ctx: context.Background(),
bucketName: "test",
forceMode: false,
quiet: true,
},
prepareMockFn: func(m *client.MockIS3) {
m.EXPECT().CheckBucketExists(gomock.Any(), aws.String("test")).Return(true, nil)
m.EXPECT().GetBucketLocation(gomock.Any(), aws.String("test")).Return("ap-northeast-1", nil)
m.EXPECT().ListObjectVersions(gomock.Any(), aws.String("test"), "ap-northeast-1").Return(
[]types.ObjectIdentifier{
{
Key: aws.String("KeyForVersions"),
VersionId: aws.String("VersionIdForVersions"),
},
{
Key: aws.String("KeyForDeleteMarkers"),
VersionId: aws.String("VersionIdForDeleteMarkers"),
},
}, nil)
m.EXPECT().DeleteObjects(gomock.Any(), aws.String("test"), gomock.Any(), "ap-northeast-1", gomock.Any()).Return([]types.Error{}, nil)
},
want: nil,
wantErr: false,
Expand All @@ -65,6 +94,7 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {
ctx: context.Background(),
bucketName: "test",
forceMode: true,
quiet: false,
},
prepareMockFn: func(m *client.MockIS3) {
m.EXPECT().CheckBucketExists(gomock.Any(), aws.String("test")).Return(true, nil)
Expand All @@ -80,7 +110,7 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {
VersionId: aws.String("VersionIdForDeleteMarkers"),
},
}, nil)
m.EXPECT().DeleteObjects(gomock.Any(), aws.String("test"), gomock.Any(), "ap-northeast-1").Return([]types.Error{}, nil)
m.EXPECT().DeleteObjects(gomock.Any(), aws.String("test"), gomock.Any(), "ap-northeast-1", gomock.Any()).Return([]types.Error{}, nil)
m.EXPECT().DeleteBucket(gomock.Any(), aws.String("test"), "ap-northeast-1").Return(nil)
},
want: nil,
Expand All @@ -92,6 +122,7 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {
ctx: context.Background(),
bucketName: "test",
forceMode: false,
quiet: false,
},
prepareMockFn: func(m *client.MockIS3) {
m.EXPECT().CheckBucketExists(gomock.Any(), aws.String("test")).Return(false, fmt.Errorf("ListBucketsError"))
Expand All @@ -105,6 +136,7 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {
ctx: context.Background(),
bucketName: "test",
forceMode: false,
quiet: false,
},
prepareMockFn: func(m *client.MockIS3) {
m.EXPECT().CheckBucketExists(gomock.Any(), aws.String("test")).Return(false, nil)
Expand All @@ -118,6 +150,7 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {
ctx: context.Background(),
bucketName: "test",
forceMode: false,
quiet: false,
},
prepareMockFn: func(m *client.MockIS3) {
m.EXPECT().CheckBucketExists(gomock.Any(), aws.String("test")).Return(true, nil)
Expand All @@ -132,6 +165,7 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {
ctx: context.Background(),
bucketName: "test",
forceMode: false,
quiet: false,
},
prepareMockFn: func(m *client.MockIS3) {
m.EXPECT().CheckBucketExists(gomock.Any(), aws.String("test")).Return(true, nil)
Expand All @@ -147,6 +181,7 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {
ctx: context.Background(),
bucketName: "test",
forceMode: false,
quiet: false,
},
prepareMockFn: func(m *client.MockIS3) {
m.EXPECT().CheckBucketExists(gomock.Any(), aws.String("test")).Return(true, nil)
Expand All @@ -162,7 +197,7 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {
VersionId: aws.String("VersionIdForDeleteMarkers"),
},
}, nil)
m.EXPECT().DeleteObjects(gomock.Any(), aws.String("test"), gomock.Any(), "ap-northeast-1").Return([]types.Error{}, fmt.Errorf("DeleteObjectsError"))
m.EXPECT().DeleteObjects(gomock.Any(), aws.String("test"), gomock.Any(), "ap-northeast-1", gomock.Any()).Return([]types.Error{}, fmt.Errorf("DeleteObjectsError"))
},
want: fmt.Errorf("DeleteObjectsError"),
wantErr: true,
Expand All @@ -173,6 +208,7 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {
ctx: context.Background(),
bucketName: "test",
forceMode: false,
quiet: false,
},
prepareMockFn: func(m *client.MockIS3) {
m.EXPECT().CheckBucketExists(gomock.Any(), aws.String("test")).Return(true, nil)
Expand All @@ -188,7 +224,7 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {
VersionId: aws.String("VersionIdForDeleteMarkers"),
},
}, nil)
m.EXPECT().DeleteObjects(gomock.Any(), aws.String("test"), gomock.Any(), "ap-northeast-1").Return(
m.EXPECT().DeleteObjects(gomock.Any(), aws.String("test"), gomock.Any(), "ap-northeast-1", gomock.Any()).Return(
[]types.Error{
{
Key: aws.String("Key"),
Expand All @@ -208,6 +244,7 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {
ctx: context.Background(),
bucketName: "test",
forceMode: true,
quiet: false,
},
prepareMockFn: func(m *client.MockIS3) {
m.EXPECT().CheckBucketExists(gomock.Any(), aws.String("test")).Return(true, nil)
Expand All @@ -223,7 +260,7 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {
VersionId: aws.String("VersionIdForDeleteMarkers"),
},
}, nil)
m.EXPECT().DeleteObjects(gomock.Any(), aws.String("test"), gomock.Any(), "ap-northeast-1").Return([]types.Error{}, nil)
m.EXPECT().DeleteObjects(gomock.Any(), aws.String("test"), gomock.Any(), "ap-northeast-1", gomock.Any()).Return([]types.Error{}, nil)
m.EXPECT().DeleteBucket(gomock.Any(), aws.String("test"), "ap-northeast-1").Return(fmt.Errorf("DeleteBucketError"))
},
want: fmt.Errorf("DeleteBucketError"),
Expand All @@ -235,6 +272,7 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {
ctx: context.Background(),
bucketName: "test",
forceMode: true,
quiet: false,
},
prepareMockFn: func(m *client.MockIS3) {
m.EXPECT().CheckBucketExists(gomock.Any(), aws.String("test")).Return(true, nil)
Expand All @@ -251,6 +289,7 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {
ctx: context.Background(),
bucketName: "test",
forceMode: true,
quiet: false,
},
prepareMockFn: func(m *client.MockIS3) {
m.EXPECT().CheckBucketExists(gomock.Any(), aws.String("test")).Return(true, nil)
Expand All @@ -271,7 +310,7 @@ func TestS3Wrapper_ClearS3Objects(t *testing.T) {

s3 := NewS3Wrapper(s3Mock)

err := s3.ClearS3Objects(tt.args.ctx, tt.args.bucketName, tt.args.forceMode)
err := s3.ClearS3Objects(tt.args.ctx, tt.args.bucketName, tt.args.forceMode, tt.args.quiet)
if (err != nil) != tt.wantErr {
t.Errorf("error = %#v, wantErr %#v", err.Error(), tt.wantErr)
return
Expand Down
Loading

0 comments on commit 7469ba2

Please sign in to comment.