Files
query-orchestration/internal/document/clean/content_test.go
T
Michael McGuinness 60812aba91 Merged in feature/richname (pull request #112)
Standardised rich name for Files

* tests
2025-04-03 19:17:24 +00:00

66 lines
1.4 KiB
Go

package documentclean
import (
"context"
"io"
"strings"
"testing"
"time"
documenttypes "queryorchestration/internal/document/types"
"queryorchestration/internal/serviceconfig/objectstore"
objectstoremock "queryorchestration/mocks/objectstore"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
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,
}
bucket := "example_bucket"
key := objectstore.BucketKey{
ClientID: "ddddddd",
CreatedAt: time.Now().UTC(),
EntityID: uuid.New(),
Location: objectstore.Import,
}
params := &CleanParams{
Hash: "hash",
Bucket: bucket,
Key: key,
}
mimeType := documenttypes.MimeTypePDF
body := io.NopCloser(strings.NewReader(pdfHelloWorld))
mockS3.EXPECT().
GetObject(
mock.Anything,
mock.MatchedBy(func(in *s3.GetObjectInput) bool {
return *in.Bucket == bucket && *in.Key == key.String()
}),
mock.Anything,
).
Return(&s3.GetObjectOutput{
Body: body,
}, nil)
content, err := svc.getContent(ctx, params, mimeType)
require.NoError(t, err)
assert.NotNil(t, content)
})
}