67a50bac0a
Add get, list, create, deprecate query service integration tests * showtestlines * more config * roundone * splituptests * splitfurther
99 lines
2.8 KiB
Go
99 lines
2.8 KiB
Go
package query_test
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/query"
|
|
queryprocessor "queryorchestration/internal/queryProcessor"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGet(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 := query.New(db)
|
|
|
|
config := "{\"path\":\"example_path\"}"
|
|
query := query.Query{
|
|
ID: uuid.New(),
|
|
Type: queryprocessor.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)
|
|
assert.Nil(t, err)
|
|
|
|
assert.EqualExportedValues(t, query, *returnQuery)
|
|
}
|
|
|
|
func TestFullActiveQueryEmpty(t *testing.T) {
|
|
dbQuery := &repository.Fullactivequery{
|
|
ID: database.MustToDBUUID(uuid.New()),
|
|
Type: repository.QuerytypeContextFull,
|
|
Activeversion: int32(1),
|
|
Latestversion: int32(2),
|
|
Config: []byte(""),
|
|
Requiredids: []pgtype.UUID{},
|
|
}
|
|
|
|
out, err := query.ParseFullActiveQuery(dbQuery)
|
|
assert.Nil(t, err)
|
|
assert.EqualExportedValues(t, query.Query{
|
|
ID: database.MustToUUID(dbQuery.ID),
|
|
Type: queryprocessor.TypeContextFull,
|
|
ActiveVersion: int32(1),
|
|
LatestVersion: int32(2),
|
|
Config: "",
|
|
RequiredQueryIDs: []uuid.UUID{},
|
|
}, *out)
|
|
}
|
|
|
|
func TestFullActiveQueryWithNullUUID(t *testing.T) {
|
|
dbQuery := &repository.Fullactivequery{
|
|
ID: database.MustToDBUUID(uuid.New()),
|
|
Type: repository.QuerytypeContextFull,
|
|
Activeversion: int32(1),
|
|
Latestversion: int32(2),
|
|
Config: []byte(""),
|
|
Requiredids: []pgtype.UUID{database.MustToDBUUID(uuid.Nil)},
|
|
}
|
|
|
|
out, err := query.ParseFullActiveQuery(dbQuery)
|
|
assert.Nil(t, err)
|
|
assert.EqualExportedValues(t, query.Query{
|
|
ID: database.MustToUUID(dbQuery.ID),
|
|
Type: queryprocessor.TypeContextFull,
|
|
ActiveVersion: int32(1),
|
|
LatestVersion: int32(2),
|
|
Config: "",
|
|
RequiredQueryIDs: []uuid.UUID{},
|
|
}, *out)
|
|
}
|