d91ef1832b
Function Test Coverage * test * scripts
70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
package documenttext
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/document"
|
|
textversion "queryorchestration/internal/document/text/version"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestExtract(t *testing.T) {
|
|
ctx := context.Background()
|
|
pool, err := pgxmock.NewPool()
|
|
require.NoError(t, err)
|
|
|
|
cfg := &DocTextConfig{}
|
|
cfg.DBPool = pool
|
|
cfg.DBQueries = repository.New(pool)
|
|
|
|
svc := Service{
|
|
cfg: cfg,
|
|
svc: &Services{
|
|
Version: textversion.New(cfg),
|
|
},
|
|
}
|
|
|
|
id := uuid.New()
|
|
inloc := document.Location{
|
|
Bucket: "bucket_name",
|
|
Key: "/i/am/here",
|
|
}
|
|
|
|
cleanId := database.MustToDBUUID(uuid.New())
|
|
mimeType := "application/pdf"
|
|
dbmimetype := repository.NullCleanmimetype{
|
|
Valid: true,
|
|
Cleanmimetype: repository.Cleanmimetype(mimeType),
|
|
}
|
|
pool.ExpectQuery("name: GetDocumentCleanEntry :one").WithArgs(database.MustToDBUUID(id)).WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}).
|
|
AddRow(cleanId, database.MustToDBUUID(id), &inloc.Bucket, &inloc.Key, int32(1), dbmimetype, repository.NullCleanfailtype{}),
|
|
)
|
|
pool.ExpectExec("name: AddDocumentTextEntry :exec").WithArgs(int32(1), inloc.Bucket, inloc.Key, cleanId).
|
|
WillReturnResult(pgxmock.NewResult("", 1))
|
|
|
|
err = svc.extract(ctx, id)
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestExecuteExtraction(t *testing.T) {
|
|
svc := Service{}
|
|
|
|
id := uuid.New()
|
|
location := document.Location{}
|
|
|
|
outloc, err := svc.executeExtraction(&ExtractionParams{
|
|
ID: id,
|
|
Location: location,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.EqualExportedValues(t, location, *outloc)
|
|
}
|