4ccb980593
Initial Job Collector (changes pending) * movearroundtocleancollector * internalgetfunctions * completecollectorquery * simplify * fixtests * addvendor * noplaceholder
87 lines
2.4 KiB
Go
87 lines
2.4 KiB
Go
package collector_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/job/collector"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGet(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 := collector.New(db)
|
|
|
|
ogc := collector.Collector{
|
|
ID: uuid.New(),
|
|
JobID: uuid.New(),
|
|
MinCleanVersion: 2,
|
|
MinTextVersion: 4,
|
|
Fields: map[string]uuid.UUID{
|
|
"example_key": uuid.New(),
|
|
},
|
|
}
|
|
|
|
pool.ExpectQuery("name: GetCollector :one").WithArgs(database.MustToDBUUID(ogc.ID)).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "jobId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
|
|
AddRow(database.MustToDBUUID(ogc.ID), database.MustToDBUUID(ogc.JobID), ogc.MinCleanVersion, ogc.MinTextVersion, ogc.ActiveVersion, ogc.LatestVersion, []byte(fmt.Sprintf("{\"example_key\":\"%s\"}", ogc.Fields["example_key"].String()))),
|
|
)
|
|
|
|
coll, err := svc.Get(ctx, ogc.ID)
|
|
assert.Nil(t, err)
|
|
assert.EqualExportedValues(t, ogc, *coll)
|
|
}
|
|
|
|
func TestGetByJobID(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 := collector.New(db)
|
|
|
|
ogc := collector.Collector{
|
|
ID: uuid.New(),
|
|
JobID: uuid.New(),
|
|
MinCleanVersion: 2,
|
|
MinTextVersion: 4,
|
|
Fields: map[string]uuid.UUID{
|
|
"example_key": uuid.New(),
|
|
},
|
|
}
|
|
|
|
pool.ExpectQuery("name: GetCollectorByJobID :one").WithArgs(database.MustToDBUUID(ogc.JobID)).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "jobId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
|
|
AddRow(database.MustToDBUUID(ogc.ID), database.MustToDBUUID(ogc.JobID), ogc.MinCleanVersion, ogc.MinTextVersion, ogc.ActiveVersion, ogc.LatestVersion, []byte(fmt.Sprintf("{\"example_key\":\"%s\"}", ogc.Fields["example_key"].String()))),
|
|
)
|
|
|
|
coll, err := svc.GetByJobID(ctx, ogc.JobID)
|
|
assert.Nil(t, err)
|
|
assert.EqualExportedValues(t, ogc, *coll)
|
|
}
|