fa95d733ca
Add short tests and Tidy internal directories * complete the tasks
75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package queryqueue
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
queryprocessor "queryorchestration/internal/query/processor"
|
|
"queryorchestration/internal/query/result"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSetResult(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,
|
|
}
|
|
|
|
q := &Queue{
|
|
db: db,
|
|
documentId: uuid.New(),
|
|
cleanVersion: int32(1),
|
|
textVersion: int32(2),
|
|
}
|
|
|
|
qu := &queryprocessor.Query{ID: uuid.New(), Type: queryprocessor.TypeContextFull, RequiredQueryIDs: []uuid.UUID{}, Version: int32(1)}
|
|
resultValues := []result.Value{}
|
|
|
|
pool.ExpectQuery("name: SetResult :one").WithArgs(database.MustToDBUUID(qu.ID), database.MustToDBUUID(q.documentId), pgxmock.AnyArg(), q.cleanVersion, q.textVersion, qu.Version).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"id"}).AddRow(pgtype.UUID{}),
|
|
)
|
|
|
|
err = q.setResult(ctx, qu, resultValues)
|
|
assert.Nil(t, err)
|
|
}
|
|
|
|
func TestGetProcessor(t *testing.T) {
|
|
q := Queue{}
|
|
|
|
qType := queryprocessor.Type(queryprocessor.TypeContextFull)
|
|
|
|
processor, err := q.getProcessor(qType)
|
|
assert.Nil(t, err)
|
|
assert.NotNil(t, processor)
|
|
}
|
|
|
|
func TestGetResultValue(t *testing.T) {
|
|
result := &repository.ListResultValuesByIDRow{
|
|
Queryid: database.MustToDBUUID(uuid.New()),
|
|
Value: "EXAMPLE_VALUE",
|
|
}
|
|
|
|
q := &Queue{
|
|
collectorQueries: []*queryprocessor.Query{
|
|
{ID: database.MustToUUID(result.Queryid), Type: queryprocessor.TypeContextFull},
|
|
},
|
|
}
|
|
|
|
value, err := q.getResultValue(result)
|
|
assert.Nil(t, err)
|
|
assert.NotNil(t, value)
|
|
}
|