2025-02-07 12:12:51 +00:00
|
|
|
package documentclean
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-02-28 13:11:53 +00:00
|
|
|
"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-02-07 12:12:51 +00:00
|
|
|
"queryorchestration/internal/database/repository"
|
|
|
|
|
"queryorchestration/internal/document"
|
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"
|
2025-02-07 12:12:51 +00:00
|
|
|
|
2025-03-04 15:51:03 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
2025-02-28 13:11:53 +00:00
|
|
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
2025-02-07 12:12:51 +00:00
|
|
|
"github.com/google/uuid"
|
|
|
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2025-02-28 13:11:53 +00:00
|
|
|
"github.com/stretchr/testify/mock"
|
2025-02-07 12:12:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestClean(t *testing.T) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
pool, err := pgxmock.NewPool()
|
2025-03-04 15:51:03 +00:00
|
|
|
require.NoError(t, err)
|
2025-02-07 12:12:51 +00:00
|
|
|
|
|
|
|
|
cfg := &DocCleanConfig{}
|
|
|
|
|
cfg.DBPool = pool
|
|
|
|
|
cfg.DBQueries = repository.New(pool)
|
2025-02-28 13:11:53 +00:00
|
|
|
mockS3 := objectstoremock.NewMockS3Client(t)
|
|
|
|
|
cfg.StoreClient = mockS3
|
2025-02-07 12:12:51 +00:00
|
|
|
|
|
|
|
|
svc := Service{
|
|
|
|
|
cfg: cfg,
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-17 18:14:15 +00:00
|
|
|
doc := document.DocumentSummary{
|
2025-03-10 11:03:00 +00:00
|
|
|
ID: uuid.New(),
|
2025-04-02 18:50:03 +00:00
|
|
|
ClientID: "yuyu",
|
2025-03-10 11:03:00 +00:00
|
|
|
Hash: "example_hash",
|
2025-02-28 13:11:53 +00:00
|
|
|
}
|
2025-04-03 19:17:24 +00:00
|
|
|
bucket := "example_bucket"
|
|
|
|
|
key := objectstore.BucketKey{
|
|
|
|
|
ClientID: doc.ClientID,
|
|
|
|
|
CreatedAt: time.Now().UTC(),
|
|
|
|
|
EntityID: uuid.New(),
|
|
|
|
|
Location: objectstore.Import,
|
2025-02-07 12:12:51 +00:00
|
|
|
}
|
2025-04-03 19:17:24 +00:00
|
|
|
keyStr := key.String()
|
2025-03-20 11:06:41 +00:00
|
|
|
dbid := doc.ID
|
2025-02-07 12:12:51 +00:00
|
|
|
|
2025-03-17 18:14:15 +00:00
|
|
|
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(dbid).
|
2025-02-28 13:11:53 +00:00
|
|
|
WillReturnRows(
|
2025-03-10 11:03:00 +00:00
|
|
|
pgxmock.NewRows([]string{"id", "clientId", "hash"}).
|
2025-03-20 11:06:41 +00:00
|
|
|
AddRow(dbid, doc.ClientID, doc.Hash),
|
2025-02-28 13:11:53 +00:00
|
|
|
)
|
|
|
|
|
pool.ExpectQuery("name: GetDocumentEntry :one").WithArgs(dbid).WillReturnRows(
|
2025-02-07 12:12:51 +00:00
|
|
|
pgxmock.NewRows([]string{"documentId", "bucket", "key"}).
|
2025-04-03 19:17:24 +00:00
|
|
|
AddRow(dbid, bucket, keyStr),
|
2025-02-07 12:12:51 +00:00
|
|
|
)
|
2025-02-28 13:11:53 +00:00
|
|
|
mimeType := "application/pdf"
|
2025-03-03 21:56:17 +00:00
|
|
|
dbmimetype := repository.NullCleanmimetype{
|
|
|
|
|
Valid: true,
|
|
|
|
|
Cleanmimetype: repository.Cleanmimetype(mimeType),
|
2025-02-28 13:11:53 +00:00
|
|
|
}
|
2025-03-03 21:56:17 +00:00
|
|
|
pool.ExpectBegin()
|
|
|
|
|
pool.ExpectQuery("name: GetMostRecentDocumentCleanEntry :one").WithArgs(dbid).
|
|
|
|
|
WillReturnRows(
|
2025-04-02 18:50:03 +00:00
|
|
|
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "hash", "mimetype", "fail"}),
|
2025-03-03 21:56:17 +00:00
|
|
|
)
|
2025-03-20 11:06:41 +00:00
|
|
|
cleanid := uuid.New()
|
2025-04-03 19:17:24 +00:00
|
|
|
pool.ExpectQuery("name: AddDocumentClean :one").WithArgs(dbid, &bucket, &keyStr, &doc.Hash, dbmimetype, repository.NullCleanfailtype{}).
|
2025-03-03 21:56:17 +00:00
|
|
|
WillReturnRows(
|
|
|
|
|
pgxmock.NewRows([]string{"id"}).
|
|
|
|
|
AddRow(cleanid),
|
|
|
|
|
)
|
2025-03-11 18:15:49 +00:00
|
|
|
pool.ExpectExec("name: AddDocumentCleanEntry :exec").WithArgs(cleanid, pgxmock.AnyArg()).
|
2025-02-07 12:12:51 +00:00
|
|
|
WillReturnResult(pgxmock.NewResult("", 1))
|
2025-03-03 21:56:17 +00:00
|
|
|
pool.ExpectCommit()
|
2025-02-07 12:12:51 +00:00
|
|
|
|
2025-02-28 13:11:53 +00:00
|
|
|
var length int64 = 10
|
|
|
|
|
mockS3.EXPECT().
|
|
|
|
|
HeadObject(
|
|
|
|
|
mock.Anything,
|
|
|
|
|
mock.MatchedBy(func(in *s3.HeadObjectInput) bool {
|
2025-04-03 19:17:24 +00:00
|
|
|
return *in.Bucket == bucket && *in.Key == keyStr
|
2025-02-28 13:11:53 +00:00
|
|
|
}),
|
|
|
|
|
mock.Anything,
|
|
|
|
|
).
|
|
|
|
|
Return(&s3.HeadObjectOutput{
|
|
|
|
|
ContentType: &mimeType,
|
|
|
|
|
ContentLength: &length,
|
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
|
|
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 == keyStr
|
2025-02-28 13:11:53 +00:00
|
|
|
}),
|
|
|
|
|
mock.Anything,
|
|
|
|
|
).
|
|
|
|
|
Return(&s3.GetObjectOutput{
|
|
|
|
|
Body: body,
|
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
|
|
err = svc.clean(ctx, doc.ID)
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-02-07 12:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExecuteCleanTasks(t *testing.T) {
|
2025-02-28 13:11:53 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
cfg := &DocCleanConfig{}
|
|
|
|
|
mockS3 := objectstoremock.NewMockS3Client(t)
|
|
|
|
|
cfg.StoreClient = mockS3
|
|
|
|
|
svc := Service{
|
|
|
|
|
cfg: cfg,
|
|
|
|
|
}
|
2025-02-07 12:12:51 +00:00
|
|
|
|
|
|
|
|
id := uuid.New()
|
2025-02-28 13:11:53 +00:00
|
|
|
hash := "example_hash"
|
2025-04-03 19:17:24 +00:00
|
|
|
bucket := "example_bucket"
|
|
|
|
|
key := objectstore.BucketKey{
|
|
|
|
|
ClientID: "client",
|
|
|
|
|
CreatedAt: time.Now().UTC(),
|
|
|
|
|
EntityID: uuid.New(),
|
|
|
|
|
Location: objectstore.Import,
|
2025-02-28 13:11:53 +00:00
|
|
|
}
|
2025-04-03 19:17:24 +00:00
|
|
|
keyStr := key.String()
|
2025-02-28 13:11:53 +00:00
|
|
|
|
|
|
|
|
mimeType := "application/pdf"
|
|
|
|
|
mockS3.EXPECT().
|
|
|
|
|
HeadObject(
|
|
|
|
|
mock.Anything,
|
|
|
|
|
mock.MatchedBy(func(in *s3.HeadObjectInput) bool {
|
2025-04-03 19:17:24 +00:00
|
|
|
return *in.Bucket == bucket && *in.Key == keyStr
|
2025-02-28 13:11:53 +00:00
|
|
|
}),
|
|
|
|
|
mock.Anything,
|
|
|
|
|
).
|
|
|
|
|
Return(&s3.HeadObjectOutput{
|
|
|
|
|
ContentType: &mimeType,
|
|
|
|
|
}, nil)
|
2025-02-07 12:12:51 +00:00
|
|
|
|
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 == keyStr
|
2025-02-28 13:11:53 +00:00
|
|
|
}),
|
|
|
|
|
mock.Anything,
|
|
|
|
|
).
|
|
|
|
|
Return(&s3.GetObjectOutput{
|
|
|
|
|
Body: body,
|
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
|
|
outloc, err := svc.executeCleanTasks(ctx, &CleanParams{
|
2025-04-03 19:17:24 +00:00
|
|
|
ID: id,
|
|
|
|
|
Hash: hash,
|
|
|
|
|
Bucket: bucket,
|
|
|
|
|
Key: key,
|
2025-02-07 12:12:51 +00:00
|
|
|
})
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-02-28 13:11:53 +00:00
|
|
|
assert.EqualExportedValues(t, ExecuteCleanResponse{
|
2025-04-03 19:17:24 +00:00
|
|
|
hash: &hash,
|
2025-02-28 13:11:53 +00:00
|
|
|
}, *outloc)
|
2025-02-07 12:12:51 +00:00
|
|
|
}
|
2025-02-28 13:11:53 +00:00
|
|
|
|
2025-03-03 21:56:17 +00:00
|
|
|
func TestStoreClean(t *testing.T) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
pool, err := pgxmock.NewPool()
|
2025-03-04 15:51:03 +00:00
|
|
|
require.NoError(t, err)
|
2025-03-03 21:56:17 +00:00
|
|
|
|
|
|
|
|
cfg := &DocCleanConfig{}
|
|
|
|
|
cfg.DBPool = pool
|
|
|
|
|
cfg.DBQueries = repository.New(pool)
|
|
|
|
|
|
|
|
|
|
svc := Service{
|
|
|
|
|
cfg: cfg,
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-17 18:14:15 +00:00
|
|
|
doc := document.DocumentSummary{
|
2025-03-03 21:56:17 +00:00
|
|
|
ID: uuid.New(),
|
|
|
|
|
}
|
2025-04-03 19:17:24 +00:00
|
|
|
bucket := "example_bucket"
|
|
|
|
|
key := objectstore.BucketKey{
|
|
|
|
|
ClientID: doc.ClientID,
|
|
|
|
|
CreatedAt: time.Now().UTC(),
|
|
|
|
|
EntityID: uuid.New(),
|
|
|
|
|
Location: objectstore.Import,
|
2025-03-03 21:56:17 +00:00
|
|
|
}
|
2025-04-03 19:17:24 +00:00
|
|
|
keyStr := key.String()
|
2025-03-03 21:56:17 +00:00
|
|
|
t.Run("no prev entry", func(t *testing.T) {
|
|
|
|
|
mimeType := "application/pdf"
|
2025-04-02 18:50:03 +00:00
|
|
|
hash := "heyman"
|
2025-03-03 21:56:17 +00:00
|
|
|
params := &ExecuteCleanResponse{
|
2025-04-02 18:50:03 +00:00
|
|
|
hash: &hash,
|
|
|
|
|
mimetype: (*documenttypes.MimeType)(&mimeType),
|
2025-04-03 19:17:24 +00:00
|
|
|
key: &key,
|
|
|
|
|
bucket: &bucket,
|
2025-03-03 21:56:17 +00:00
|
|
|
}
|
2025-03-20 11:06:41 +00:00
|
|
|
dbid := doc.ID
|
2025-03-03 21:56:17 +00:00
|
|
|
|
|
|
|
|
dbmimetype := repository.NullCleanmimetype{
|
|
|
|
|
Valid: true,
|
|
|
|
|
Cleanmimetype: repository.Cleanmimetype(mimeType),
|
|
|
|
|
}
|
|
|
|
|
pool.ExpectBegin()
|
|
|
|
|
pool.ExpectQuery("name: GetMostRecentDocumentCleanEntry :one").WithArgs(dbid).
|
|
|
|
|
WillReturnRows(
|
2025-04-02 18:50:03 +00:00
|
|
|
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "hash", "mimetype", "fail"}),
|
2025-03-03 21:56:17 +00:00
|
|
|
)
|
2025-03-20 11:06:41 +00:00
|
|
|
cleanid := uuid.New()
|
2025-04-03 19:17:24 +00:00
|
|
|
pool.ExpectQuery("name: AddDocumentClean :one").WithArgs(dbid, &bucket, &keyStr, params.hash, dbmimetype, repository.NullCleanfailtype{}).
|
2025-03-03 21:56:17 +00:00
|
|
|
WillReturnRows(
|
|
|
|
|
pgxmock.NewRows([]string{"id"}).
|
|
|
|
|
AddRow(cleanid),
|
|
|
|
|
)
|
2025-03-11 18:15:49 +00:00
|
|
|
pool.ExpectExec("name: AddDocumentCleanEntry :exec").WithArgs(cleanid, pgxmock.AnyArg()).
|
2025-03-03 21:56:17 +00:00
|
|
|
WillReturnResult(pgxmock.NewResult("", 1))
|
|
|
|
|
pool.ExpectCommit()
|
|
|
|
|
|
|
|
|
|
err = svc.storeClean(ctx, doc.ID, params)
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-03-03 21:56:17 +00:00
|
|
|
})
|
|
|
|
|
t.Run("diff prev entry", func(t *testing.T) {
|
|
|
|
|
mimeType := "application/pdf"
|
2025-04-02 18:50:03 +00:00
|
|
|
hash := "heyman"
|
2025-03-03 21:56:17 +00:00
|
|
|
params := &ExecuteCleanResponse{
|
2025-04-02 18:50:03 +00:00
|
|
|
hash: &hash,
|
2025-04-03 19:17:24 +00:00
|
|
|
bucket: &bucket,
|
|
|
|
|
key: &key,
|
2025-04-02 18:50:03 +00:00
|
|
|
mimetype: (*documenttypes.MimeType)(&mimeType),
|
2025-03-03 21:56:17 +00:00
|
|
|
}
|
2025-03-20 11:06:41 +00:00
|
|
|
dbid := doc.ID
|
2025-03-03 21:56:17 +00:00
|
|
|
|
|
|
|
|
dbmimetype := repository.NullCleanmimetype{
|
|
|
|
|
Valid: true,
|
|
|
|
|
Cleanmimetype: repository.Cleanmimetype(mimeType),
|
|
|
|
|
}
|
|
|
|
|
pool.ExpectBegin()
|
|
|
|
|
pool.ExpectQuery("name: GetMostRecentDocumentCleanEntry :one").WithArgs(dbid).
|
|
|
|
|
WillReturnRows(
|
2025-04-02 18:50:03 +00:00
|
|
|
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "hash", "mimetype", "fail"}).
|
|
|
|
|
AddRow(uuid.New(), dbid, nil, nil, int64(1), nil, nil, repository.CleanfailtypeInvalidRead),
|
2025-03-03 21:56:17 +00:00
|
|
|
)
|
2025-03-20 11:06:41 +00:00
|
|
|
cleanid := uuid.New()
|
2025-04-03 19:17:24 +00:00
|
|
|
pool.ExpectQuery("name: AddDocumentClean :one").WithArgs(dbid, &bucket, &keyStr, params.hash, dbmimetype, repository.NullCleanfailtype{}).
|
2025-03-03 21:56:17 +00:00
|
|
|
WillReturnRows(
|
|
|
|
|
pgxmock.NewRows([]string{"id"}).
|
|
|
|
|
AddRow(cleanid),
|
|
|
|
|
)
|
2025-03-11 18:15:49 +00:00
|
|
|
pool.ExpectExec("name: AddDocumentCleanEntry :exec").WithArgs(cleanid, pgxmock.AnyArg()).
|
2025-03-03 21:56:17 +00:00
|
|
|
WillReturnResult(pgxmock.NewResult("", 1))
|
|
|
|
|
pool.ExpectCommit()
|
|
|
|
|
|
|
|
|
|
err = svc.storeClean(ctx, doc.ID, params)
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-03-03 21:56:17 +00:00
|
|
|
})
|
|
|
|
|
t.Run("same fail", func(t *testing.T) {
|
2025-04-02 18:50:03 +00:00
|
|
|
reason := documenttypes.InvalidDocumentMimeType
|
2025-03-03 21:56:17 +00:00
|
|
|
params := &ExecuteCleanResponse{
|
|
|
|
|
failReason: &reason,
|
|
|
|
|
}
|
2025-03-20 11:06:41 +00:00
|
|
|
dbid := doc.ID
|
|
|
|
|
cleanid := uuid.New()
|
2025-03-03 21:56:17 +00:00
|
|
|
|
|
|
|
|
pool.ExpectBegin()
|
|
|
|
|
pool.ExpectQuery("name: GetMostRecentDocumentCleanEntry :one").WithArgs(dbid).
|
|
|
|
|
WillReturnRows(
|
2025-04-02 18:50:03 +00:00
|
|
|
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "hash", "mimetype", "fail"}).
|
|
|
|
|
AddRow(cleanid, dbid, nil, nil, int64(1), nil, nil, repository.NullCleanfailtype{
|
2025-03-03 21:56:17 +00:00
|
|
|
Valid: true,
|
|
|
|
|
Cleanfailtype: repository.CleanfailtypeInvalidMimetype,
|
|
|
|
|
}),
|
|
|
|
|
)
|
2025-03-11 18:15:49 +00:00
|
|
|
pool.ExpectExec("name: AddDocumentCleanEntry :exec").WithArgs(cleanid, pgxmock.AnyArg()).
|
2025-03-03 21:56:17 +00:00
|
|
|
WillReturnResult(pgxmock.NewResult("", 1))
|
|
|
|
|
pool.ExpectCommit()
|
|
|
|
|
|
|
|
|
|
err = svc.storeClean(ctx, doc.ID, params)
|
|
|
|
|
assert.EqualError(t, err, "invalid_mimetype")
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestIsNewClean(t *testing.T) {
|
|
|
|
|
svc := Service{}
|
|
|
|
|
t.Run("no last entry", func(t *testing.T) {
|
|
|
|
|
var lastEntry *repository.GetMostRecentDocumentCleanEntryRow = nil
|
|
|
|
|
params := &ExecuteCleanResponse{}
|
|
|
|
|
assert.True(t, svc.isNewClean(lastEntry, params))
|
|
|
|
|
})
|
|
|
|
|
t.Run("same fail", func(t *testing.T) {
|
|
|
|
|
var lastEntry *repository.GetMostRecentDocumentCleanEntryRow = &repository.GetMostRecentDocumentCleanEntryRow{
|
2025-03-20 11:06:41 +00:00
|
|
|
ID: uuid.New(),
|
2025-03-03 21:56:17 +00:00
|
|
|
Fail: repository.NullCleanfailtype{
|
|
|
|
|
Valid: true,
|
|
|
|
|
Cleanfailtype: repository.CleanfailtypeInvalidMimetype,
|
|
|
|
|
},
|
|
|
|
|
}
|
2025-04-02 18:50:03 +00:00
|
|
|
reason := documenttypes.InvalidDocumentMimeType
|
2025-03-03 21:56:17 +00:00
|
|
|
params := &ExecuteCleanResponse{
|
|
|
|
|
failReason: &reason,
|
|
|
|
|
}
|
|
|
|
|
assert.False(t, svc.isNewClean(lastEntry, params))
|
|
|
|
|
})
|
|
|
|
|
t.Run("different fail", func(t *testing.T) {
|
|
|
|
|
var lastEntry *repository.GetMostRecentDocumentCleanEntryRow = &repository.GetMostRecentDocumentCleanEntryRow{
|
2025-03-20 11:06:41 +00:00
|
|
|
ID: uuid.New(),
|
2025-03-03 21:56:17 +00:00
|
|
|
Fail: repository.NullCleanfailtype{
|
|
|
|
|
Valid: true,
|
|
|
|
|
Cleanfailtype: repository.CleanfailtypeInvalidMimetype,
|
|
|
|
|
},
|
|
|
|
|
}
|
2025-04-02 18:50:03 +00:00
|
|
|
reason := documenttypes.InvalidDocumentLargeDPI
|
2025-03-03 21:56:17 +00:00
|
|
|
params := &ExecuteCleanResponse{
|
|
|
|
|
failReason: &reason,
|
|
|
|
|
}
|
|
|
|
|
assert.True(t, svc.isNewClean(lastEntry, params))
|
|
|
|
|
})
|
|
|
|
|
t.Run("same location", func(t *testing.T) {
|
2025-04-03 19:17:24 +00:00
|
|
|
bucket := "example_bucket"
|
|
|
|
|
key := objectstore.BucketKey{
|
|
|
|
|
ClientID: "diw",
|
|
|
|
|
CreatedAt: time.Now().UTC(),
|
|
|
|
|
EntityID: uuid.New(),
|
|
|
|
|
Location: objectstore.Import,
|
2025-03-03 21:56:17 +00:00
|
|
|
}
|
2025-04-03 19:17:24 +00:00
|
|
|
keyStr := key.String()
|
2025-04-02 18:50:03 +00:00
|
|
|
mimeType := documenttypes.MimeTypePDF
|
2025-03-03 21:56:17 +00:00
|
|
|
var lastEntry *repository.GetMostRecentDocumentCleanEntryRow = &repository.GetMostRecentDocumentCleanEntryRow{
|
2025-03-20 11:06:41 +00:00
|
|
|
ID: uuid.New(),
|
2025-04-03 19:17:24 +00:00
|
|
|
Bucket: &bucket,
|
|
|
|
|
Key: &keyStr,
|
2025-03-03 21:56:17 +00:00
|
|
|
Mimetype: repository.NullCleanmimetype{
|
|
|
|
|
Valid: true,
|
|
|
|
|
Cleanmimetype: repository.Cleanmimetype(mimeType),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
params := &ExecuteCleanResponse{
|
2025-04-03 19:17:24 +00:00
|
|
|
bucket: &bucket,
|
|
|
|
|
key: &key,
|
2025-03-03 21:56:17 +00:00
|
|
|
mimetype: &mimeType,
|
|
|
|
|
}
|
|
|
|
|
assert.False(t, svc.isNewClean(lastEntry, params))
|
|
|
|
|
})
|
|
|
|
|
t.Run("different location", func(t *testing.T) {
|
2025-04-03 19:17:24 +00:00
|
|
|
bucket := "example_bucket"
|
|
|
|
|
oldKey := objectstore.BucketKey{
|
|
|
|
|
ClientID: "hi",
|
|
|
|
|
CreatedAt: time.Now().UTC(),
|
|
|
|
|
EntityID: uuid.New(),
|
|
|
|
|
Location: objectstore.Import,
|
2025-03-03 21:56:17 +00:00
|
|
|
}
|
2025-04-03 19:17:24 +00:00
|
|
|
oldKeyStr := oldKey.String()
|
|
|
|
|
newKey := objectstore.BucketKey{
|
|
|
|
|
ClientID: "hi",
|
|
|
|
|
CreatedAt: time.Now().UTC(),
|
|
|
|
|
EntityID: uuid.New(),
|
|
|
|
|
Location: objectstore.Import,
|
2025-03-03 21:56:17 +00:00
|
|
|
}
|
2025-04-02 18:50:03 +00:00
|
|
|
mimeType := documenttypes.MimeTypePDF
|
2025-03-03 21:56:17 +00:00
|
|
|
var lastEntry *repository.GetMostRecentDocumentCleanEntryRow = &repository.GetMostRecentDocumentCleanEntryRow{
|
2025-03-20 11:06:41 +00:00
|
|
|
ID: uuid.New(),
|
2025-04-03 19:17:24 +00:00
|
|
|
Bucket: &bucket,
|
|
|
|
|
Key: &oldKeyStr,
|
2025-03-03 21:56:17 +00:00
|
|
|
Mimetype: repository.NullCleanmimetype{
|
|
|
|
|
Valid: true,
|
|
|
|
|
Cleanmimetype: repository.Cleanmimetype(mimeType),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
params := &ExecuteCleanResponse{
|
2025-04-03 19:17:24 +00:00
|
|
|
bucket: &bucket,
|
|
|
|
|
key: &newKey,
|
2025-03-03 21:56:17 +00:00
|
|
|
mimetype: &mimeType,
|
|
|
|
|
}
|
|
|
|
|
assert.True(t, svc.isNewClean(lastEntry, params))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-28 13:11:53 +00:00
|
|
|
const pdfHelloWorld = `%PDF-1.4
|
|
|
|
|
%����
|
|
|
|
|
1 0 obj
|
|
|
|
|
<<
|
|
|
|
|
/Type /Catalog
|
|
|
|
|
/Pages 2 0 R
|
|
|
|
|
/Version /1.4
|
|
|
|
|
>>
|
|
|
|
|
endobj
|
|
|
|
|
2 0 obj
|
|
|
|
|
<<
|
|
|
|
|
/Type /Pages
|
|
|
|
|
/Kids [3 0 R]
|
|
|
|
|
/Count 1
|
|
|
|
|
>>
|
|
|
|
|
endobj
|
|
|
|
|
3 0 obj
|
|
|
|
|
<<
|
|
|
|
|
/Type /Page
|
|
|
|
|
/Parent 2 0 R
|
|
|
|
|
/MediaBox [0 0 612 792]
|
|
|
|
|
/Resources <<
|
|
|
|
|
/Font <<
|
|
|
|
|
/F1 <<
|
|
|
|
|
/Type /Font
|
|
|
|
|
/Subtype /Type1
|
|
|
|
|
/BaseFont /Helvetica
|
|
|
|
|
>>
|
|
|
|
|
>>
|
|
|
|
|
>>
|
|
|
|
|
/Contents 4 0 R
|
|
|
|
|
>>
|
|
|
|
|
endobj
|
|
|
|
|
4 0 obj
|
|
|
|
|
<<
|
|
|
|
|
/Length
|
|
|
|
|
44
|
|
|
|
|
>>
|
|
|
|
|
stream
|
|
|
|
|
BT
|
|
|
|
|
/F1 24 Tf
|
|
|
|
|
100 700 Td
|
|
|
|
|
(Hello World!) Tj
|
|
|
|
|
ET
|
|
|
|
|
endstream
|
|
|
|
|
endobj
|
|
|
|
|
xref
|
|
|
|
|
0 5
|
|
|
|
|
0000000000 65535 f
|
|
|
|
|
0000000015 00000 n
|
|
|
|
|
0000000086 00000 n
|
|
|
|
|
0000000151 00000 n
|
|
|
|
|
0000000376 00000 n
|
|
|
|
|
trailer
|
|
|
|
|
<<
|
|
|
|
|
/Size 5
|
|
|
|
|
/Root 1 0 R
|
|
|
|
|
>>
|
|
|
|
|
startxref
|
|
|
|
|
472
|
|
|
|
|
%%EOF`
|