Merged in feature/update (pull request #27)
Query Update * baselineupdate * baseupdateplusmodelupdates * passtests * somemoresubmittesting * testinnerfunctions * readmeandinstall * cleanerstartup * readmeplusdeps * tidyatrighttime * validatetests * normalizedontvalidate * abitofzenormalizationcleanup * addunitstestforhelperfuns * normalizeactiveversiontestas
This commit is contained in:
@@ -2,6 +2,7 @@ package query_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query"
|
||||
@@ -32,10 +33,10 @@ func TestCreate(t *testing.T) {
|
||||
q := query.Query{
|
||||
ID: uuid.New(),
|
||||
Type: queryprocessor.TypeJsonExtractor,
|
||||
RequiredQueryIDs: []uuid.UUID{
|
||||
RequiredQueryIDs: &[]uuid.UUID{
|
||||
uuid.New(),
|
||||
},
|
||||
Config: config,
|
||||
Config: &config,
|
||||
}
|
||||
create := &queryprocessor.Create{
|
||||
Type: q.Type,
|
||||
@@ -46,16 +47,20 @@ func TestCreate(t *testing.T) {
|
||||
dbType, err := queryprocessor.ToDBQueryType(create.Type)
|
||||
assert.Nil(t, err)
|
||||
|
||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(database.MustToDBUUIDArray(*create.RequiredQueryIDs)).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"all_exist"}).AddRow(true),
|
||||
)
|
||||
|
||||
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)).
|
||||
for _, req := range *create.RequiredQueryIDs {
|
||||
pool.ExpectExec("name: AddRequiredQuery :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)).
|
||||
pool.ExpectExec("name: AddQueryConfig :exec").WithArgs(database.MustToDBUUID(q.ID), []byte(*create.Config), int32(1)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
@@ -63,3 +68,74 @@ func TestCreate(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, q.ID, id)
|
||||
}
|
||||
|
||||
func TestCreateMinimal(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)
|
||||
|
||||
q := query.Query{
|
||||
ID: uuid.New(),
|
||||
Type: queryprocessor.TypeJsonExtractor,
|
||||
}
|
||||
create := &queryprocessor.Create{
|
||||
Type: q.Type,
|
||||
}
|
||||
|
||||
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)),
|
||||
)
|
||||
pool.ExpectCommit()
|
||||
|
||||
id, err := svc.Create(ctx, create)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, q.ID, id)
|
||||
}
|
||||
|
||||
func TestCreateRollback(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)
|
||||
|
||||
q := query.Query{
|
||||
ID: uuid.New(),
|
||||
Type: queryprocessor.TypeJsonExtractor,
|
||||
}
|
||||
create := &queryprocessor.Create{
|
||||
Type: q.Type,
|
||||
}
|
||||
|
||||
dbType, err := queryprocessor.ToDBQueryType(create.Type)
|
||||
assert.Nil(t, err)
|
||||
|
||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
||||
msg := "database failure"
|
||||
pool.ExpectQuery("name: CreateQuery :one").WithArgs(dbType).WillReturnError(errors.New(msg))
|
||||
pool.ExpectRollback()
|
||||
|
||||
_, err = svc.Create(ctx, create)
|
||||
assert.EqualError(t, err, msg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user