Files
query-orchestration/test/unit/internal/query/get_test.go
T

58 lines
1.5 KiB
Go
Raw Normal View History

2025-01-03 10:35:42 +00:00
package document_test
import (
"context"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/query"
2025-01-03 13:41:07 +00:00
queryprocessor "queryorchestration/internal/queryProcessor"
2025-01-03 10:35:42 +00:00
"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()
2025-01-06 13:30:20 +00:00
pool, err := pgxmock.NewPool()
2025-01-03 10:35:42 +00:00
if err != nil {
t.Fatalf("failed to open pgxmock database: %v", err)
}
2025-01-06 13:30:20 +00:00
queries := repository.New(pool)
db := &database.Connection{
Queries: queries,
Pool: pool,
}
svc := query.New(db)
2025-01-03 10:35:42 +00:00
config := "{\"path\":\"example_path\"}"
query := query.Query{
2025-01-06 13:30:20 +00:00
ID: uuid.New(),
Type: queryprocessor.TypeJsonExtractor,
ActiveVersion: int32(1),
LatestVersion: int32(1),
2025-01-03 10:35:42 +00:00
RequiredQueryIDs: []uuid.UUID{
uuid.New(),
},
Config: config,
}
dbReqIDs := make([]pgtype.UUID, len(query.RequiredQueryIDs))
for index, id := range query.RequiredQueryIDs {
dbReqIDs[index] = database.MustToDBUUID(id)
}
2025-01-06 13:30:20 +00:00
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),
2025-01-03 10:35:42 +00:00
)
returnQuery, err := svc.Get(ctx, query.ID)
assert.Nil(t, err)
assert.EqualExportedValues(t, query, *returnQuery)
}