ed8cfbbee4
Set Collector * set
83 lines
2.3 KiB
Go
83 lines
2.3 KiB
Go
package collector_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"queryorchestration/internal/collector"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
resultprocessor "queryorchestration/internal/query/result/processor"
|
|
"queryorchestration/internal/serviceconfig"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGetByClientID(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
pool, err := pgxmock.NewPool()
|
|
require.NoError(t, err)
|
|
cfg := &serviceconfig.BaseConfig{}
|
|
cfg.DBPool = pool
|
|
cfg.DBQueries = repository.New(pool)
|
|
|
|
svc := collector.New(cfg)
|
|
|
|
minCleanV := int32(2)
|
|
minTextV := int32(4)
|
|
ogc := collector.Collector{
|
|
ClientID: uuid.New(),
|
|
MinCleanVersion: minCleanV,
|
|
MinTextVersion: minTextV,
|
|
Fields: map[string]uuid.UUID{
|
|
"example_key": uuid.New(),
|
|
},
|
|
}
|
|
|
|
pool.ExpectQuery("name: GetCollectorByClientID :one").WithArgs(database.MustToDBUUID(ogc.ClientID)).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"clientId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
|
|
AddRow(database.MustToDBUUID(ogc.ClientID), ogc.MinCleanVersion, ogc.MinTextVersion, ogc.ActiveVersion, ogc.LatestVersion, []byte(fmt.Sprintf("{\"example_key\":\"%s\"}", ogc.Fields["example_key"].String()))),
|
|
)
|
|
|
|
coll, err := svc.GetByClientID(ctx, ogc.ClientID)
|
|
assert.NoError(t, err)
|
|
assert.EqualExportedValues(t, ogc, *coll)
|
|
}
|
|
|
|
func TestListQueries(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
pool, err := pgxmock.NewPool()
|
|
require.NoError(t, err)
|
|
cfg := &serviceconfig.BaseConfig{}
|
|
cfg.DBPool = pool
|
|
cfg.DBQueries = repository.New(pool)
|
|
|
|
svc := collector.New(cfg)
|
|
|
|
clientId := uuid.New()
|
|
ogc := []*resultprocessor.Query{
|
|
{
|
|
ID: uuid.New(),
|
|
Type: resultprocessor.TypeContextFull,
|
|
Version: 2,
|
|
},
|
|
}
|
|
|
|
pool.ExpectQuery("name: ListCollectorQueries :many").WithArgs(database.MustToDBUUID(clientId)).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"clientId", "queryId", "type", "queryVersion", "requiredIds"}).
|
|
AddRow(database.MustToDBUUID(clientId), database.MustToDBUUID(ogc[0].ID), repository.QuerytypeContextFull, int32(2), nil),
|
|
)
|
|
|
|
qs, err := svc.ListQueries(ctx, clientId)
|
|
assert.NoError(t, err)
|
|
assert.EqualExportedValues(t, ogc, qs)
|
|
}
|