5c253b3592
Feature/docinit * createunittests * cleanup * skip * cleanup
66 lines
1.5 KiB
Go
66 lines
1.5 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 TestDocument(t *testing.T) {
|
|
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)
|
|
|
|
bucket := "example_bucket"
|
|
location := "/i/am/here"
|
|
err = queries.AddDocumentEntry(ctx, &repository.AddDocumentEntryParams{
|
|
Documentid: id,
|
|
Bucket: bucket,
|
|
Location: location,
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
doc, err := queries.GetDocument(ctx, id)
|
|
assert.NoError(t, err)
|
|
assert.EqualExportedValues(t, &repository.Document{
|
|
ID: id,
|
|
Jobid: jobId,
|
|
Hash: hash,
|
|
}, doc)
|
|
|
|
docid, err := queries.GetDocumentIDByHash(ctx, &repository.GetDocumentIDByHashParams{
|
|
Hash: hash,
|
|
Jobid: jobId,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.EqualExportedValues(t, id, docid)
|
|
}
|