Skip to content

Commit 6c0cdc1

Browse files
committed
CSPL-3974 Fix unit tests by implementing HeadObject in mock client
1 parent 3f84268 commit 6c0cdc1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pkg/splunk/test/awss3client.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,23 @@ func (mockClient MockAWSS3Client) GetObject(ctx context.Context, input *s3.GetOb
104104
return output, nil
105105
}
106106

107+
// HeadObject is a mock call to HeadObject
108+
func (mockClient MockAWSS3Client) HeadObject(ctx context.Context, input *s3.HeadObjectInput, options ...func(*s3.Options)) (*s3.HeadObjectOutput, error) {
109+
output := &s3.HeadObjectOutput{}
110+
111+
tmp, err := json.Marshal(mockClient.Objects)
112+
if err != nil {
113+
return nil, err
114+
}
115+
116+
err = json.Unmarshal(tmp, &output.ETag)
117+
if err != nil {
118+
return nil, err
119+
}
120+
121+
return output, nil
122+
}
123+
107124
// ListObjectsV2 is a mock call to ListObjectsV2
108125
func (mockClient MockAWSS3ClientError) ListObjectsV2(ctx context.Context, input *s3.ListObjectsV2Input, options ...func(*s3.Options)) (*s3.ListObjectsV2Output, error) {
109126
return &s3.ListObjectsV2Output{}, errors.New("Dummy Error")
@@ -114,6 +131,11 @@ func (mockClient MockAWSS3ClientError) GetObject(ctx context.Context, input *s3.
114131
return &s3.GetObjectOutput{}, errors.New("Dummy Error")
115132
}
116133

134+
// HeadObject is a mock call to HeadObject
135+
func (mockClient MockAWSS3ClientError) HeadObject(ctx context.Context, input *s3.HeadObjectInput, options ...func(*s3.Options)) (*s3.HeadObjectOutput, error) {
136+
return &s3.HeadObjectOutput{}, errors.New("Dummy Error")
137+
}
138+
117139
// MockAWSDownloadClient is mock aws client for download
118140
type MockAWSDownloadClient struct{}
119141

0 commit comments

Comments
 (0)