24a038ec3d
DocTextRunner Structure * firstround * shorttests
93 lines
2.2 KiB
Go
93 lines
2.2 KiB
Go
package repository_test
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/serviceconfig"
|
|
"queryorchestration/internal/test"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestTextExtraction(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("Skipping long test in short mode")
|
|
}
|
|
ctx := context.Background()
|
|
|
|
cfg := &serviceconfig.BaseConfig{}
|
|
test.SetCfgProvider(t, cfg)
|
|
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
|
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
|
Cfg: cfg,
|
|
RunMigrations: true,
|
|
})
|
|
defer cleanup()
|
|
|
|
queries := cfg.GetDBQueries()
|
|
|
|
clientId, err := queries.CreateClient(ctx, "example_client")
|
|
assert.NoError(t, err)
|
|
jobId, err := queries.CreateJob(ctx, clientId)
|
|
assert.NoError(t, err)
|
|
|
|
hash := "example_hash"
|
|
id, err := queries.CreateDocument(ctx, &repository.CreateDocumentParams{
|
|
Jobid: jobId,
|
|
Hash: hash,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.NotEmpty(t, id)
|
|
|
|
collId, err := queries.CreateCollector(ctx, jobId)
|
|
assert.NoError(t, err)
|
|
err = queries.AddCollectorCodeVersion(ctx, &repository.AddCollectorCodeVersionParams{
|
|
Collectorid: collId,
|
|
Addedversion: 1,
|
|
Mincleanversion: 1,
|
|
Mintextversion: 2,
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
isextract, err := queries.IsDocumentTextExtracted(ctx, id)
|
|
assert.NoError(t, err)
|
|
assert.False(t, isextract)
|
|
|
|
bucket := "example_bucket"
|
|
key := "example_key"
|
|
err = queries.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
|
Documentid: id,
|
|
Version: 1,
|
|
Bucket: bucket,
|
|
Key: key,
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
isextract, err = queries.IsDocumentTextExtracted(ctx, id)
|
|
assert.NoError(t, err)
|
|
assert.False(t, isextract)
|
|
|
|
err = queries.AddCollectorCodeVersion(ctx, &repository.AddCollectorCodeVersionParams{
|
|
Collectorid: collId,
|
|
Addedversion: 1,
|
|
Mincleanversion: 1,
|
|
Mintextversion: 1,
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
isextract, err = queries.IsDocumentTextExtracted(ctx, id)
|
|
assert.NoError(t, err)
|
|
assert.True(t, isextract)
|
|
|
|
clean, err := queries.GetDocumentTextEntry(ctx, id)
|
|
assert.NoError(t, err)
|
|
assert.EqualExportedValues(t, &repository.GetDocumentTextEntryRow{
|
|
Documentid: id,
|
|
Bucket: bucket,
|
|
Key: key,
|
|
}, clean)
|
|
}
|