1587da9d11
Fix Fullsuite * save * foundthefix.. * codeandrequire
90 lines
2.6 KiB
Go
90 lines
2.6 KiB
Go
package query_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/query"
|
|
resultprocessor "queryorchestration/internal/query/result/processor"
|
|
"queryorchestration/internal/serviceconfig"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
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 := query.New(cfg)
|
|
|
|
config := "{\"path\":\"example_path\"}"
|
|
query := query.Query{
|
|
ID: uuid.New(),
|
|
Type: resultprocessor.TypeJsonExtractor,
|
|
ActiveVersion: int32(1),
|
|
LatestVersion: int32(1),
|
|
RequiredQueryIDs: &[]uuid.UUID{
|
|
uuid.New(),
|
|
},
|
|
Config: &config,
|
|
}
|
|
|
|
dbReqIDs := database.MustToDBUUIDArray(*query.RequiredQueryIDs)
|
|
|
|
pool.ExpectQuery("name: GetQuery :one").WithArgs(database.MustToDBUUID(query.ID)).WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
|
|
AddRow(database.MustToDBUUID(query.ID), repository.QuerytypeJsonExtractor, query.ActiveVersion, query.LatestVersion, []byte(config), dbReqIDs),
|
|
)
|
|
|
|
returnQuery, err := svc.Get(ctx, query.ID)
|
|
require.NoError(t, err)
|
|
|
|
assert.EqualExportedValues(t, query, *returnQuery)
|
|
}
|
|
|
|
func TestGetWithVersion(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 := query.New(cfg)
|
|
|
|
config := "{\"path\":\"example_path\"}"
|
|
query := query.Query{
|
|
ID: uuid.New(),
|
|
Type: resultprocessor.TypeJsonExtractor,
|
|
ActiveVersion: int32(1),
|
|
LatestVersion: int32(3),
|
|
RequiredQueryIDs: &[]uuid.UUID{
|
|
uuid.New(),
|
|
},
|
|
Config: &config,
|
|
}
|
|
|
|
version := int32(2)
|
|
|
|
dbReqIDs := database.MustToDBUUIDArray(*query.RequiredQueryIDs)
|
|
|
|
pool.ExpectQuery("name: GetQueryWithVersion :one").WithArgs(database.MustToDBUUID(query.ID), &version).WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
|
|
AddRow(database.MustToDBUUID(query.ID), repository.QuerytypeJsonExtractor, query.ActiveVersion, query.LatestVersion, []byte(config), dbReqIDs),
|
|
)
|
|
|
|
returnQuery, err := svc.GetWithVersion(ctx, query.ID, version)
|
|
require.NoError(t, err)
|
|
|
|
assert.EqualExportedValues(t, query, *returnQuery)
|
|
}
|