Skip to content

Commit

Permalink
Merge pull request #184 from bilalcaliskan/devel
Browse files Browse the repository at this point in the history
test: cover missing lines [skip ci]
  • Loading branch information
bilalcaliskan authored Nov 27, 2023
2 parents 32c43c4 + 3505e14 commit 3ca003e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ import (
"github.com/bilalcaliskan/s3-manager/internal/utils"
)

func CreateClient(opts *options.RootOptions) (*s3.Client, error) {
func createConfig(opts *options.RootOptions) (cfg aws.Config, err error) {
appCreds := aws.NewCredentialsCache(credentials.NewStaticCredentialsProvider(opts.AccessKey, opts.SecretKey, ""))
cfg, err := config.LoadDefaultConfig(context.Background(),
return config.LoadDefaultConfig(context.Background(),
config.WithRegion(opts.Region),
config.WithCredentialsProvider(appCreds),
)
}

func CreateClient(opts *options.RootOptions) (*s3.Client, error) {
cfg, err := createConfig(opts)
if err != nil {
return nil, err
}
Expand Down
38 changes: 38 additions & 0 deletions internal/aws/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,37 @@ func TestDeleteFiles(t *testing.T) {
},
},
},
{
"Success with non-empty file list and dry-run enabled",
nil,
func(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error) {
return &s3.DeleteObjectOutput{}, nil
},
true,
[]types.Object{
{
ETag: aws.String("03c0fe42b7efa3470fc99037a8e5449d"),
Key: aws.String("../../testdata/file4.txt"),
StorageClass: types.ObjectStorageClass("STANDART"),
Size: aws.Int64(500),
LastModified: aws.Time(time.Now().Add(-5 * time.Hour)),
},
{
ETag: aws.String("03c0fe42b7efa3470fc99037a8e54122"),
Key: aws.String("../../testdata/file5.txt"),
StorageClass: types.ObjectStorageClass("STANDART"),
Size: aws.Int64(1000),
LastModified: aws.Time(time.Now().Add(-2 * time.Hour)),
},
{
ETag: aws.String("03c0fe42b7efa3470fc99037a8e5443d"),
Key: aws.String("../../testdata/file6.txt"),
StorageClass: types.ObjectStorageClass("STANDART"),
Size: aws.Int64(1500),
LastModified: aws.Time(time.Now().Add(-10 * time.Hour)),
},
},
},
{
"Failure caused by delete object err",
constants.ErrInjected,
Expand Down Expand Up @@ -171,6 +202,13 @@ func getMockBody(path string) io.ReadCloser {
return io.NopCloser(body)
}

func TestCreateClient(t *testing.T) {
rootOpts := options.GetMockedRootOptions()
cl, err := CreateClient(rootOpts)
assert.Nil(t, err)
assert.NotNil(t, cl)
}

// TestSearchString is a test function that tests the behavior of the SearchString function.
//
// It creates test cases with different scenarios and verifies the expected results.
Expand Down

0 comments on commit 3ca003e

Please sign in to comment.