Files
query-orchestration/internal/document/text/extract_test.go
T
Michael McGuinness 24a038ec3d Merged in feature/doctextstructure (pull request #56)
DocTextRunner Structure

* firstround

* shorttests
2025-02-07 14:15:06 +00:00

63 lines
1.4 KiB
Go

package documenttext
import (
"context"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/document"
"testing"
"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()
if err != nil {
t.Fatalf("failed to open pgxmock database: %v", err)
}
cfg := &DocTextConfig{}
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
svc := Service{
cfg: cfg,
svc: &Services{
Document: document.New(cfg),
},
}
id := uuid.New()
inloc := document.Location{
Bucket: "bucket_name",
Key: "/i/am/here",
}
pool.ExpectQuery("name: GetDocumentCleanEntry :one").WithArgs(database.MustToDBUUID(id)).WillReturnRows(
pgxmock.NewRows([]string{"documentId", "bucket", "key"}).
AddRow(database.MustToDBUUID(id), inloc.Bucket, inloc.Key),
)
pool.ExpectExec("name: AddDocumentTextEntry :exec").WithArgs(database.MustToDBUUID(id), int32(1), inloc.Bucket, inloc.Key).
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)
}