c1e9d93037
Document Sync and Job Sync * docsyncfunc * startedQueryWork * morefixes * jobsyncsvcstart * save * jobsynctext * save * save * docsync * shorttest * jobsync * jobsyncupdateoncollectorupdate * passlivetest * collectortest * lint
167 lines
3.7 KiB
Go
167 lines
3.7 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 TestJob(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)
|
|
|
|
id, err := queries.CreateJob(ctx, clientId)
|
|
assert.NoError(t, err)
|
|
assert.NotEmpty(t, id)
|
|
|
|
job, err := queries.GetJob(ctx, id)
|
|
assert.NoError(t, err)
|
|
assert.EqualExportedValues(t, &repository.GetJobRow{
|
|
ID: id,
|
|
Clientid: clientId,
|
|
Cansync: false,
|
|
}, job)
|
|
|
|
err = queries.AddJobCanSync(ctx, &repository.AddJobCanSyncParams{
|
|
Cansync: true,
|
|
Jobid: id,
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
job, err = queries.GetJob(ctx, id)
|
|
assert.NoError(t, err)
|
|
assert.EqualExportedValues(t, &repository.GetJobRow{
|
|
ID: id,
|
|
Clientid: clientId,
|
|
Cansync: true,
|
|
}, job)
|
|
}
|
|
func TestListJobDocumentIDs(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)
|
|
|
|
id, err := queries.CreateJob(ctx, clientId)
|
|
assert.NoError(t, err)
|
|
assert.NotEmpty(t, id)
|
|
|
|
ids, err := queries.ListJobDocumentIDsBatch(ctx, &repository.ListJobDocumentIDsBatchParams{
|
|
Jobid: id,
|
|
Batchsize: 1,
|
|
Pageoffset: 0,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, ids, 0)
|
|
|
|
docOne, err := queries.CreateDocument(ctx, &repository.CreateDocumentParams{
|
|
Jobid: id,
|
|
Hash: "example_hash",
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
ids, err = queries.ListJobDocumentIDsBatch(ctx, &repository.ListJobDocumentIDsBatchParams{
|
|
Jobid: id,
|
|
Batchsize: 1,
|
|
Pageoffset: 0,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, ids, 1)
|
|
total := int64(1)
|
|
assert.ElementsMatch(t, []*repository.ListJobDocumentIDsBatchRow{
|
|
{
|
|
ID: docOne,
|
|
Totalcount: &total,
|
|
},
|
|
}, ids)
|
|
|
|
docTwo, err := queries.CreateDocument(ctx, &repository.CreateDocumentParams{
|
|
Jobid: id,
|
|
Hash: "example_hash_two",
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
ids, err = queries.ListJobDocumentIDsBatch(ctx, &repository.ListJobDocumentIDsBatchParams{
|
|
Jobid: id,
|
|
Batchsize: 1,
|
|
Pageoffset: 0,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, ids, 1)
|
|
total = int64(2)
|
|
assert.ElementsMatch(t, []*repository.ListJobDocumentIDsBatchRow{
|
|
{
|
|
ID: docOne,
|
|
Totalcount: &total,
|
|
},
|
|
}, ids)
|
|
|
|
ids, err = queries.ListJobDocumentIDsBatch(ctx, &repository.ListJobDocumentIDsBatchParams{
|
|
Jobid: id,
|
|
Batchsize: 1,
|
|
Pageoffset: 1,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, ids, 1)
|
|
assert.ElementsMatch(t, []*repository.ListJobDocumentIDsBatchRow{
|
|
{
|
|
ID: docTwo,
|
|
Totalcount: &total,
|
|
},
|
|
}, ids)
|
|
|
|
ids, err = queries.ListJobDocumentIDsBatch(ctx, &repository.ListJobDocumentIDsBatchParams{
|
|
Jobid: id,
|
|
Batchsize: 2,
|
|
Pageoffset: 0,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, ids, 2)
|
|
assert.ElementsMatch(t, []*repository.ListJobDocumentIDsBatchRow{
|
|
{
|
|
ID: docOne,
|
|
Totalcount: &total,
|
|
},
|
|
{
|
|
ID: docTwo,
|
|
Totalcount: &total,
|
|
},
|
|
}, ids)
|
|
}
|