Files
query-orchestration/internal/query/result/get_test.go
T
Jay Brown 15adaebfcd Merged in feature/serviceconfig-integration (pull request #38)
DRAFT PR : WIP working through ideas for integration

* movearound

* attempttwo

* openapi

* further sanding

* fix

* start on tests

* runthroughsingleconfig

* somechanges

* reflectissue

* removeerrs

* mostlyremovepanic

* removeenv

* noncfgtests

* go

* repo

* fix service config test

* add PWD to all

* test fix

* fix lint

* todo for later

* passingunittests

* alltests

* testlogger

* testloggername

* clean
2025-01-31 13:43:55 +00:00

65 lines
1.9 KiB
Go

package result
import (
"context"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
resultprocessor "queryorchestration/internal/query/result/processor"
jsonextractor "queryorchestration/internal/query/types/jsonExtractor"
"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 TestGetValueByType(t *testing.T) {
_, err := getValueByType(resultprocessor.Type(-1), "example_val")
assert.Error(t, err)
pro, err := getValueByType(resultprocessor.TypeContextFull, "example_context")
assert.Nil(t, err)
assert.NotNil(t, pro)
assert.Equal(t, "example_context", pro.GetStoreValue())
pro, err = getValueByType(resultprocessor.TypeJsonExtractor, "example_json")
assert.Nil(t, err)
assert.NotNil(t, pro)
assert.Equal(t, "example_json", pro.GetStoreValue())
}
func TestGetValueWithVersion(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 := New(cfg)
params := &GetValueWithVersionParams{
Type: resultprocessor.TypeJsonExtractor,
QueryID: uuid.New(),
DocumentID: uuid.New(),
QueryVersion: 1,
MinCleanVersion: 2,
MinTextVersion: 3,
}
pool.ExpectQuery("name: GetResultValueWithVersion :one").WithArgs(database.MustToDBUUID(params.QueryID), params.QueryVersion, database.MustToDBUUID(params.DocumentID), params.MinCleanVersion, params.MinTextVersion).
WillReturnRows(
pgxmock.NewRows([]string{"id", "value"}).
AddRow(pgtype.UUID{}, "example_value"),
)
val, err := svc.GetValueWithVersion(ctx, params)
assert.Nil(t, err)
v := jsonextractor.NewResult("example_value")
assert.Equal(t, v, val)
assert.Equal(t, "example_value", v.GetStoreValue())
}