0815cb35fb
Basic Lint Checks * basic
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package document_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/document"
|
|
"queryorchestration/internal/serviceconfig"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGet(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
pool, err := pgxmock.NewPool()
|
|
require.NoError(t, err)
|
|
cfg := &serviceconfig.BaseConfig{}
|
|
cfg.DBPool = pool
|
|
cfg.DBQueries = repository.New(pool)
|
|
|
|
svc := document.New(cfg)
|
|
|
|
doc := document.Document{
|
|
ID: uuid.New(),
|
|
JobID: uuid.New(),
|
|
Hash: "example_hash",
|
|
}
|
|
|
|
pool.ExpectQuery("name: GetDocument :one").WithArgs(database.MustToDBUUID(doc.ID)).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "jobId", "hash"}).
|
|
AddRow(database.MustToDBUUID(doc.ID), database.MustToDBUUID(doc.JobID), doc.Hash),
|
|
)
|
|
|
|
adoc, err := svc.Get(ctx, doc.ID)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, &doc, adoc)
|
|
}
|