Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
stefans-elastic committed Dec 17, 2024
1 parent 30bc1f4 commit 3041ff4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions x-pack/filebeat/input/awss3/s3_objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path/filepath"
"strings"
"testing"
"time"

awssdk "github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
Expand Down Expand Up @@ -435,6 +436,33 @@ func TestNewMockS3Pager(t *testing.T) {
assert.Equal(t, []string{"foo", "bar", "baz"}, keys)
}

// Test_s3ObjectHash verifies that s3ObjectHash function produces correct value
func Test_s3ObjectHash(t *testing.T) {
lastModified, _ := time.Parse("2006-01-02 15:04:05 -0700", "2022-10-07 12:44:22 +0530")
objHash := s3ObjectHash(s3EventV2{
S3: struct {
Bucket struct {
Name string `json:"name"`
ARN string `json:"arn"`
} `json:"bucket"`
Object struct {
Key string `json:"key"`
LastModified time.Time `json:"lastModified"`
} `json:"object"`
}{
Bucket: struct {
Name string `json:"name"`
ARN string `json:"arn"`
}{Name: "test", ARN: "arn:aws:s3:::test"},
Object: struct {
Key string `json:"key"`
LastModified time.Time `json:"lastModified"`
}{Key: "test-obj", LastModified: lastModified},
},
})
assert.Equal(t, "fe8a230c26", objHash)
}

// newMockS3Pager returns a s3Pager that paginates the given s3Objects based on
// the specified page size. It never returns an error.
func newMockS3Pager(ctrl *gomock.Controller, pageSize int, s3Objects []types.Object) *MockS3Pager {
Expand Down

0 comments on commit 3041ff4

Please sign in to comment.