3d434eedb8
Job Status Get and DB tidy up * initalquery * tests * shorttests * testing queries * job * solvedthequery * updatingdb * fixingtests * repotests * shorttests * docker * testspassed
64 lines
1.9 KiB
Go
64 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.NoError(t, err)
|
|
assert.NotNil(t, pro)
|
|
assert.Equal(t, "example_context", pro.GetStoreValue())
|
|
pro, err = getValueByType(resultprocessor.TypeJsonExtractor, "example_json")
|
|
assert.NoError(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, &Services{})
|
|
|
|
params := &GetValueWithVersionParams{
|
|
Type: resultprocessor.TypeJsonExtractor,
|
|
QueryID: uuid.New(),
|
|
DocumentID: uuid.New(),
|
|
QueryVersion: 1,
|
|
}
|
|
|
|
value := "exaple_value"
|
|
pool.ExpectQuery("name: GetResultValueWithVersion :one").WithArgs(database.MustToDBUUID(params.QueryID), ¶ms.QueryVersion, database.MustToDBUUID(params.DocumentID)).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "value"}).
|
|
AddRow(pgtype.UUID{}, &value),
|
|
)
|
|
|
|
val, err := svc.GetValueWithVersion(ctx, params)
|
|
assert.NoError(t, err)
|
|
v := jsonextractor.NewResult(value)
|
|
assert.Equal(t, v, val)
|
|
assert.Equal(t, value, v.GetStoreValue())
|
|
}
|