7001ca854c
Queuing Changes and Cfg Testing * staarting * staarting * startedpush * note * save * mocking * removederrs * fixtests * cleanuperrs * newenvsetup * preppingtests * queue * mmovetocfgpassunittests * sortoutconfig * passinginteg * deps * fixtests
67 lines
2.0 KiB
Go
67 lines
2.0 KiB
Go
package result
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
resultprocessor "queryorchestration/internal/query/result/processor"
|
|
"queryorchestration/internal/serviceconfig"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSet(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
pool, err := pgxmock.NewPool()
|
|
if err != nil {
|
|
t.Fatalf("failed to open pgxmock database: %v", err)
|
|
}
|
|
cfg := &serviceconfig.BaseConfig{}
|
|
cfg.DBPool = pool
|
|
cfg.DBQueries = repository.New(pool)
|
|
|
|
svc := Service{
|
|
cfg: cfg,
|
|
}
|
|
|
|
rid := uuid.New()
|
|
qcfg := "{\"path\":\"examplekey\"}"
|
|
params := Set{
|
|
DocumentID: uuid.New(),
|
|
CleanVersion: 1,
|
|
TextVersion: 3,
|
|
Query: &resultprocessor.Query{
|
|
ID: uuid.New(),
|
|
Version: 2,
|
|
Config: &qcfg,
|
|
RequiredQueryIDs: &[]uuid.UUID{
|
|
uuid.New(),
|
|
},
|
|
},
|
|
}
|
|
|
|
pool.ExpectQuery("name: ListQueryRequirementValues :many").WithArgs(database.MustToDBUUID(params.Query.ID), params.Query.Version, database.MustToDBUUID(params.DocumentID), params.CleanVersion, params.TextVersion).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"queryId", "value", "type"}).
|
|
AddRow(database.MustToDBUUID((*params.Query.RequiredQueryIDs)[0]), "{\"examplekey\":\"example_value\"}", repository.QuerytypeContextFull),
|
|
)
|
|
pool.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(params.Query.ID), params.Query.Version).WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "config"}).
|
|
AddRow(pgtype.UUID{}, []byte(qcfg)),
|
|
)
|
|
pool.ExpectQuery("name: SetResult :one").WithArgs(database.MustToDBUUID(params.Query.ID), database.MustToDBUUID(params.DocumentID), pgxmock.AnyArg(), params.CleanVersion, params.TextVersion, params.Query.Version).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"id"}).
|
|
AddRow(database.MustToDBUUID(rid)),
|
|
)
|
|
|
|
id, err := svc.Set(ctx, ¶ms)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, rid, id)
|
|
}
|