bbd86fb4ea
Collector Build Version * lint * fixtests
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package documentclean
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"strings"
|
|
"testing"
|
|
|
|
"queryorchestration/internal/document"
|
|
objectstoremock "queryorchestration/mocks/objectstore"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/mock"
|
|
)
|
|
|
|
func TestGetContent(t *testing.T) {
|
|
t.Run("Working", func(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
cfg := &DocCleanConfig{}
|
|
mockS3 := objectstoremock.NewMockS3Client(t)
|
|
cfg.StoreClient = mockS3
|
|
|
|
svc := Service{
|
|
cfg: cfg,
|
|
}
|
|
|
|
inloc := document.Location{
|
|
Bucket: "bucket_name",
|
|
Key: "/i/am/here",
|
|
}
|
|
params := &CleanParams{
|
|
Hash: "hash",
|
|
Location: inloc,
|
|
}
|
|
mimeType := MimeTypePDF
|
|
|
|
body := io.NopCloser(strings.NewReader(pdfHelloWorld))
|
|
mockS3.EXPECT().
|
|
GetObject(
|
|
mock.Anything,
|
|
mock.MatchedBy(func(in *s3.GetObjectInput) bool {
|
|
return *in.Bucket == inloc.Bucket && *in.Key == inloc.Key
|
|
}),
|
|
mock.Anything,
|
|
).
|
|
Return(&s3.GetObjectOutput{
|
|
Body: body,
|
|
}, nil)
|
|
|
|
content, err := svc.getContent(ctx, params, mimeType)
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, content)
|
|
})
|
|
}
|