movetests
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
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"
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCreate(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\"}"
|
||||
q := query.Query{
|
||||
ID: uuid.New(),
|
||||
Type: queryprocessor.TypeJsonExtractor,
|
||||
ActiveVersion: int32(1),
|
||||
LatestVersion: int32(1),
|
||||
RequiredQueryIDs: []uuid.UUID{
|
||||
uuid.New(),
|
||||
},
|
||||
Config: config,
|
||||
}
|
||||
create := &queryprocessor.Create{
|
||||
Type: q.Type,
|
||||
RequiredQueryIDs: q.RequiredQueryIDs,
|
||||
Config: q.Config,
|
||||
}
|
||||
|
||||
dbType, err := queryprocessor.ToDBQueryType(create.Type)
|
||||
assert.Nil(t, err)
|
||||
|
||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
||||
pool.ExpectQuery("name: CreateQuery :one").WithArgs(dbType).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(database.MustToDBUUID(q.ID)),
|
||||
)
|
||||
for _, req := range create.RequiredQueryIDs {
|
||||
pool.ExpectExec("name: CreateRequiredQuery :exec").WithArgs(database.MustToDBUUID(q.ID), database.MustToDBUUID(req), int32(1)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
}
|
||||
pool.ExpectExec("name: CreateQueryConfig :exec").WithArgs(database.MustToDBUUID(q.ID), []byte(create.Config), int32(1)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
id, err := svc.Create(ctx, create)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, q.ID, id)
|
||||
}
|
||||
Reference in New Issue
Block a user