0ac5ff9e15
Test Query * depstextandclean * startedcleaningresult * resulttidyup * roundone * cleaning * unsyncedquery * startedtestsandsimplification * api * querytests * resultprocessortests * unittests * cleanup
65 lines
1.9 KiB
Go
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"
|
|
"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)
|
|
}
|
|
queries := repository.New(pool)
|
|
db := &database.Connection{
|
|
Queries: queries,
|
|
Pool: pool,
|
|
}
|
|
svc := New(db)
|
|
|
|
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())
|
|
}
|