From 1258b16109653850777067ddcc3e25660ef553fd Mon Sep 17 00:00:00 2001 From: Anurag Mittal Date: Tue, 10 Dec 2024 19:19:13 +0100 Subject: [PATCH] COSI-40: add-test-for-debug-log-in-aws-config --- pkg/clients/iam/iam_client_test.go | 25 +++++++++++++++++++++++++ pkg/clients/s3/s3_client_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/pkg/clients/iam/iam_client_test.go b/pkg/clients/iam/iam_client_test.go index db759098..c178fb5c 100644 --- a/pkg/clients/iam/iam_client_test.go +++ b/pkg/clients/iam/iam_client_test.go @@ -247,6 +247,31 @@ var _ = Describe("IAMClient", func() { Expect(err.Error()).To(ContainSubstring("failed to load AWS config: mock LoadAWSConfig failure")) Expect(client).To(BeNil()) }) + + It("should set up a logger when Debug is enabled", func() { + params.Debug = true + + // Mock LoadAWSConfig + originalLoadAWSConfig := iamclient.LoadAWSConfig + defer func() { iamclient.LoadAWSConfig = originalLoadAWSConfig }() + + var loggerUsed bool + iamclient.LoadAWSConfig = func(ctx context.Context, optFns ...func(*config.LoadOptions) error) (aws.Config, error) { + // Check if a logger is passed + for _, optFn := range optFns { + opt := &config.LoadOptions{} + optFn(opt) + if opt.Logger != nil { + loggerUsed = true + } + } + return aws.Config{}, nil // Simulate a successful load + } + + _, err := iamclient.InitIAMClient(params) + Expect(err).To(BeNil()) + Expect(loggerUsed).To(BeTrue(), "Expected logger to be used when Debug is enabled") + }) }) Describe("RevokeBucketAccess", func() { diff --git a/pkg/clients/s3/s3_client_test.go b/pkg/clients/s3/s3_client_test.go index fcdd01db..66e3fa8b 100644 --- a/pkg/clients/s3/s3_client_test.go +++ b/pkg/clients/s3/s3_client_test.go @@ -65,6 +65,31 @@ var _ = Describe("S3Client", func() { Expect(err.Error()).To(ContainSubstring("failed to load AWS config: mock config loading error")) Expect(client).To(BeNil()) }) + + It("should set up a logger when Debug is enabled", func() { + params.Debug = true + + // Mock LoadAWSConfig + originalLoadAWSConfig := s3client.LoadAWSConfig + defer func() { s3client.LoadAWSConfig = originalLoadAWSConfig }() + + var loggerUsed bool + s3client.LoadAWSConfig = func(ctx context.Context, optFns ...func(*config.LoadOptions) error) (aws.Config, error) { + // Check if a logger is passed + for _, optFn := range optFns { + opt := &config.LoadOptions{} + optFn(opt) + if opt.Logger != nil { + loggerUsed = true + } + } + return aws.Config{}, nil // Simulate a successful load + } + + _, err := s3client.InitS3Client(params) + Expect(err).To(BeNil()) + Expect(loggerUsed).To(BeTrue(), "Expected logger to be used when Debug is enabled") + }) }) Describe("CreateBucket", func() {