ee776d2681
Single Mock Server * mockserver * mockserver * reqs * mockserver * slowrunner * someoptimisedqueries * passedfullsuite * passedfullsuite
88 lines
2.3 KiB
Go
88 lines
2.3 KiB
Go
package collector_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"queryorchestration/internal/collector"
|
|
"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 := int64(2)
|
|
minTextV := int64(4)
|
|
ogc := collector.Collector{
|
|
ClientID: "hi",
|
|
MinCleanVersion: minCleanV,
|
|
MinTextVersion: minTextV,
|
|
Fields: map[string]uuid.UUID{
|
|
"example_key": uuid.New(),
|
|
},
|
|
}
|
|
|
|
pool.ExpectQuery("name: GetCollectorByClientID :one").WithArgs(ogc.ClientID).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"clientId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
|
|
AddRow(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)
|
|
require.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 := "id"
|
|
ogc := []*resultprocessor.Query{
|
|
{
|
|
ID: uuid.New(),
|
|
Type: resultprocessor.TypeContextFull,
|
|
Version: 2,
|
|
},
|
|
}
|
|
|
|
v := int32(2)
|
|
ty := repository.NullQuerytype{
|
|
Querytype: repository.QuerytypeContextFull,
|
|
Valid: true,
|
|
}
|
|
pool.ExpectQuery("name: ListCollectorQueries :many").WithArgs(clientId).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"clientId", "queryId", "type", "queryVersion", "requiredIds"}).
|
|
AddRow(&clientId, &ogc[0].ID, ty, &v, nil),
|
|
)
|
|
|
|
qs, err := svc.ListQueries(ctx, clientId)
|
|
require.NoError(t, err)
|
|
assert.Len(t, qs, 1)
|
|
assert.EqualExportedValues(t, *ogc[0], *qs[0])
|
|
}
|