57764272c3
Feature/unittests * addedmoretests * easyquerytests * fixotelinit * preppedqueriestotestcontainer * dbqueries * splitintoqueryfiles * covered the bases
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package query
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
queryprocessor "queryorchestration/internal/queryProcessor"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetUpdator(t *testing.T) {
|
|
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 := New(db)
|
|
|
|
queryType := queryprocessor.Type(queryprocessor.TypeContextFull)
|
|
updator, err := svc.getUpdator(queryType)
|
|
assert.Nil(t, err)
|
|
assert.NotNil(t, updator)
|
|
|
|
queryType = queryprocessor.Type(queryprocessor.TypeJsonExtractor)
|
|
updator, err = svc.getUpdator(queryType)
|
|
assert.Nil(t, err)
|
|
assert.NotNil(t, updator)
|
|
|
|
queryType = queryprocessor.Type(-1)
|
|
_, err = svc.getUpdator(queryType)
|
|
assert.NotNil(t, err)
|
|
}
|
|
|
|
func TestSubmitUpdate(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 := New(db)
|
|
|
|
config := "{\"path\":\"example_path\"}"
|
|
q := Query{
|
|
ID: uuid.New(),
|
|
RequiredQueryIDs: []uuid.UUID{
|
|
uuid.New(),
|
|
},
|
|
Config: config,
|
|
}
|
|
update := &queryprocessor.Update{
|
|
ID: q.ID,
|
|
RequiredQueryIDs: q.RequiredQueryIDs,
|
|
Config: q.Config,
|
|
}
|
|
|
|
err = svc.submitUpdate(ctx, update)
|
|
assert.Nil(t, err)
|
|
}
|