Skip to content

Commit

Permalink
COSI-40: add-test-for-debug-log-in-aws-config
Browse files Browse the repository at this point in the history
  • Loading branch information
anurag4DSB committed Dec 11, 2024
1 parent 80cbe67 commit 1258b16
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/clients/iam/iam_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
25 changes: 25 additions & 0 deletions pkg/clients/s3/s3_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 1258b16

Please sign in to comment.