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