Skip to content

Commit de8f035

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

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

pkg/splunk/enterprise/afwscheduler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ func createOrTruncateAppFileLocally(appFileName string, size int64) error {
14021402

14031403
func areAppsDownloadedSuccessfully(appDeployInfoList []*enterpriseApi.AppDeploymentInfo) (bool, error) {
14041404
for _, appInfo := range appDeployInfoList {
1405-
if appInfo.PhaseInfo.Status != enterpriseApi.AppPkgDownloadComplete {
1405+
if appInfo.PhaseInfo.Status != enterpriseApi.AppPkgDownloadComplete || appInfo.ObjectHash == "" {
14061406
err := fmt.Errorf("App:%s is not downloaded yet", appInfo.AppName)
14071407
return false, err
14081408
}

pkg/splunk/test/awss3client.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
enterpriseApi "github.com/splunk/splunk-operator/api/v4"
2828

29+
"github.com/aws/aws-sdk-go-v2/aws"
2930
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
3031
"github.com/aws/aws-sdk-go-v2/service/s3"
3132
)
@@ -104,6 +105,13 @@ func (mockClient MockAWSS3Client) GetObject(ctx context.Context, input *s3.GetOb
104105
return output, nil
105106
}
106107

108+
// HeadObject is a mock call to HeadObject
109+
func (mockClient MockAWSS3Client) HeadObject(ctx context.Context, input *s3.HeadObjectInput, options ...func(*s3.Options)) (*s3.HeadObjectOutput, error) {
110+
return &s3.HeadObjectOutput{
111+
ETag: aws.String(""),
112+
}, nil
113+
}
114+
107115
// ListObjectsV2 is a mock call to ListObjectsV2
108116
func (mockClient MockAWSS3ClientError) ListObjectsV2(ctx context.Context, input *s3.ListObjectsV2Input, options ...func(*s3.Options)) (*s3.ListObjectsV2Output, error) {
109117
return &s3.ListObjectsV2Output{}, errors.New("Dummy Error")
@@ -114,6 +122,11 @@ func (mockClient MockAWSS3ClientError) GetObject(ctx context.Context, input *s3.
114122
return &s3.GetObjectOutput{}, errors.New("Dummy Error")
115123
}
116124

125+
// HeadObject is a mock call to HeadObject
126+
func (mockClient MockAWSS3ClientError) HeadObject(ctx context.Context, input *s3.HeadObjectInput, options ...func(*s3.Options)) (*s3.HeadObjectOutput, error) {
127+
return &s3.HeadObjectOutput{}, errors.New("dummy Error")
128+
}
129+
117130
// MockAWSDownloadClient is mock aws client for download
118131
type MockAWSDownloadClient struct{}
119132

@@ -123,10 +136,9 @@ func (mockDownloadClient MockAWSDownloadClient) Download(ctx context.Context, w
123136
var bytes int64
124137
remoteFile := *input.Key
125138
localFile := w.(*os.File).Name()
126-
eTag := *input.IfMatch
127139

128-
if remoteFile == "" || localFile == "" || eTag == "" {
129-
err := fmt.Errorf("empty localFile/remoteFile/eTag. remoteFile=%s, localFile=%s, etag=%s", remoteFile, localFile, eTag)
140+
if remoteFile == "" || localFile == "" {
141+
err := fmt.Errorf("empty localFile/remoteFile/eTag. remoteFile=%s, localFile=%s", remoteFile, localFile)
130142
return bytes, err
131143
}
132144

0 commit comments

Comments
 (0)