@@ -46,7 +46,7 @@ func TestDocInitRunner(t *testing.T) {
|
|||||||
runner := docsyncrunner.New(validator.New(), &docsyncrunner.Services{
|
runner := docsyncrunner.New(validator.New(), &docsyncrunner.Services{
|
||||||
Document: documentsync.New(cfg, &documentsync.Services{
|
Document: documentsync.New(cfg, &documentsync.Services{
|
||||||
Document: document.New(cfg),
|
Document: document.New(cfg),
|
||||||
Client: client.New(cfg, &client.Services{}),
|
Client: client.New(cfg),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
assert.NotNil(t, runner)
|
assert.NotNil(t, runner)
|
||||||
|
|||||||
+51
-51
@@ -108,8 +108,8 @@ type CollectorField struct {
|
|||||||
QueryId openapi_types.UUID `json:"query_id"`
|
QueryId openapi_types.UUID `json:"query_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CollectorUpdate Payload for updating a Collector.
|
// CollectorSet Payload for updating a Collector.
|
||||||
type CollectorUpdate struct {
|
type CollectorSet struct {
|
||||||
// ActiveVersion The active version of the collector.
|
// ActiveVersion The active version of the collector.
|
||||||
ActiveVersion *int32 `json:"active_version,omitempty"`
|
ActiveVersion *int32 `json:"active_version,omitempty"`
|
||||||
|
|
||||||
@@ -276,8 +276,8 @@ type CreateClientJSONRequestBody = ClientCreate
|
|||||||
// UpdateClientJSONRequestBody defines body for UpdateClient for application/json ContentType.
|
// UpdateClientJSONRequestBody defines body for UpdateClient for application/json ContentType.
|
||||||
type UpdateClientJSONRequestBody = ClientUpdate
|
type UpdateClientJSONRequestBody = ClientUpdate
|
||||||
|
|
||||||
// UpdateCollectorByClientIdJSONRequestBody defines body for UpdateCollectorByClientId for application/json ContentType.
|
// SetCollectorByClientIdJSONRequestBody defines body for SetCollectorByClientId for application/json ContentType.
|
||||||
type UpdateCollectorByClientIdJSONRequestBody = CollectorUpdate
|
type SetCollectorByClientIdJSONRequestBody = CollectorSet
|
||||||
|
|
||||||
// TriggerExportJSONRequestBody defines body for TriggerExport for application/json ContentType.
|
// TriggerExportJSONRequestBody defines body for TriggerExport for application/json ContentType.
|
||||||
type TriggerExportJSONRequestBody = ExportTrigger
|
type TriggerExportJSONRequestBody = ExportTrigger
|
||||||
@@ -305,9 +305,9 @@ type ServerInterface interface {
|
|||||||
// Get a collector by client ID
|
// Get a collector by client ID
|
||||||
// (GET /client/{id}/collector)
|
// (GET /client/{id}/collector)
|
||||||
GetCollectorByClientId(ctx echo.Context, id openapi_types.UUID) error
|
GetCollectorByClientId(ctx echo.Context, id openapi_types.UUID) error
|
||||||
// Update a collector
|
// Set a collector
|
||||||
// (PATCH /client/{id}/collector)
|
// (PATCH /client/{id}/collector)
|
||||||
UpdateCollectorByClientId(ctx echo.Context, id openapi_types.UUID) error
|
SetCollectorByClientId(ctx echo.Context, id openapi_types.UUID) error
|
||||||
// List the documents for a client
|
// List the documents for a client
|
||||||
// (GET /client/{id}/documents)
|
// (GET /client/{id}/documents)
|
||||||
ListDocumentsByClientId(ctx echo.Context, id openapi_types.UUID) error
|
ListDocumentsByClientId(ctx echo.Context, id openapi_types.UUID) error
|
||||||
@@ -399,8 +399,8 @@ func (w *ServerInterfaceWrapper) GetCollectorByClientId(ctx echo.Context) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateCollectorByClientId converts echo context to params.
|
// SetCollectorByClientId converts echo context to params.
|
||||||
func (w *ServerInterfaceWrapper) UpdateCollectorByClientId(ctx echo.Context) error {
|
func (w *ServerInterfaceWrapper) SetCollectorByClientId(ctx echo.Context) error {
|
||||||
var err error
|
var err error
|
||||||
// ------------- Path parameter "id" -------------
|
// ------------- Path parameter "id" -------------
|
||||||
var id openapi_types.UUID
|
var id openapi_types.UUID
|
||||||
@@ -411,7 +411,7 @@ func (w *ServerInterfaceWrapper) UpdateCollectorByClientId(ctx echo.Context) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Invoke the callback with all the unmarshaled arguments
|
// Invoke the callback with all the unmarshaled arguments
|
||||||
err = w.Handler.UpdateCollectorByClientId(ctx, id)
|
err = w.Handler.SetCollectorByClientId(ctx, id)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -577,7 +577,7 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL
|
|||||||
router.GET(baseURL+"/client/:id", wrapper.GetClient)
|
router.GET(baseURL+"/client/:id", wrapper.GetClient)
|
||||||
router.PATCH(baseURL+"/client/:id", wrapper.UpdateClient)
|
router.PATCH(baseURL+"/client/:id", wrapper.UpdateClient)
|
||||||
router.GET(baseURL+"/client/:id/collector", wrapper.GetCollectorByClientId)
|
router.GET(baseURL+"/client/:id/collector", wrapper.GetCollectorByClientId)
|
||||||
router.PATCH(baseURL+"/client/:id/collector", wrapper.UpdateCollectorByClientId)
|
router.PATCH(baseURL+"/client/:id/collector", wrapper.SetCollectorByClientId)
|
||||||
router.GET(baseURL+"/client/:id/documents", wrapper.ListDocumentsByClientId)
|
router.GET(baseURL+"/client/:id/documents", wrapper.ListDocumentsByClientId)
|
||||||
router.GET(baseURL+"/client/:id/export", wrapper.ExportState)
|
router.GET(baseURL+"/client/:id/export", wrapper.ExportState)
|
||||||
router.POST(baseURL+"/client/:id/export", wrapper.TriggerExport)
|
router.POST(baseURL+"/client/:id/export", wrapper.TriggerExport)
|
||||||
@@ -593,47 +593,47 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL
|
|||||||
// Base64 encoded, gzipped, json marshaled Swagger object
|
// Base64 encoded, gzipped, json marshaled Swagger object
|
||||||
var swaggerSpec = []string{
|
var swaggerSpec = []string{
|
||||||
|
|
||||||
"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",
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSwagger returns the content of the embedded swagger specification file
|
// GetSwagger returns the content of the embedded swagger specification file
|
||||||
|
|||||||
@@ -10,16 +10,12 @@ import (
|
|||||||
|
|
||||||
queryservice "queryorchestration/api/queryService"
|
queryservice "queryorchestration/api/queryService"
|
||||||
"queryorchestration/internal/client"
|
"queryorchestration/internal/client"
|
||||||
"queryorchestration/internal/collector"
|
|
||||||
"queryorchestration/internal/database"
|
"queryorchestration/internal/database"
|
||||||
"queryorchestration/internal/database/repository"
|
"queryorchestration/internal/database/repository"
|
||||||
cleanversion "queryorchestration/internal/document/clean/version"
|
|
||||||
textversion "queryorchestration/internal/document/text/version"
|
|
||||||
"queryorchestration/internal/serviceconfig"
|
"queryorchestration/internal/serviceconfig"
|
||||||
|
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/jackc/pgx/v5"
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/pashagolub/pgxmock/v3"
|
"github.com/pashagolub/pgxmock/v3"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -35,12 +31,7 @@ func TestCreateClient(t *testing.T) {
|
|||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||||
Client: client.New(cfg, &client.Services{
|
Client: client.New(cfg),
|
||||||
Collector: collector.New(cfg, &collector.Services{
|
|
||||||
TextVersion: textversion.New(cfg),
|
|
||||||
CleanVersion: cleanversion.New(cfg),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
body := queryservice.ClientCreate{
|
body := queryservice.ClientCreate{
|
||||||
@@ -61,14 +52,6 @@ func TestCreateClient(t *testing.T) {
|
|||||||
pgxmock.NewRows([]string{"id"}).
|
pgxmock.NewRows([]string{"id"}).
|
||||||
AddRow(database.MustToDBUUID(id)),
|
AddRow(database.MustToDBUUID(id)),
|
||||||
)
|
)
|
||||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
|
||||||
pool.ExpectQuery("name: AddLatestCollectorVersion :one").WithArgs(database.MustToDBUUID(id)).WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"version"}).
|
|
||||||
AddRow(int32(1)),
|
|
||||||
)
|
|
||||||
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(database.MustToDBUUID(id), int32(1)).
|
|
||||||
WillReturnResult(pgxmock.NewResult("", 1))
|
|
||||||
pool.ExpectCommit()
|
|
||||||
|
|
||||||
err = cons.CreateClient(ctx)
|
err = cons.CreateClient(ctx)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@@ -85,12 +68,7 @@ func TestGetClient(t *testing.T) {
|
|||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||||
Client: client.New(cfg, &client.Services{
|
Client: client.New(cfg),
|
||||||
Collector: collector.New(cfg, &collector.Services{
|
|
||||||
TextVersion: textversion.New(cfg),
|
|
||||||
CleanVersion: cleanversion.New(cfg),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
@@ -130,12 +108,7 @@ func TestUpdateClient(t *testing.T) {
|
|||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||||
Client: client.New(cfg, &client.Services{
|
Client: client.New(cfg),
|
||||||
Collector: collector.New(cfg, &collector.Services{
|
|
||||||
TextVersion: textversion.New(cfg),
|
|
||||||
CleanVersion: cleanversion.New(cfg),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
cs := false
|
cs := false
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
collectorupdate "queryorchestration/internal/collector/update"
|
collectorset "queryorchestration/internal/collector/set"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
@@ -37,8 +37,8 @@ func (s *Controllers) GetCollectorByClientId(ctx echo.Context, clientId types.UU
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Controllers) UpdateCollectorByClientId(ctx echo.Context, clientId types.UUID) error {
|
func (s *Controllers) SetCollectorByClientId(ctx echo.Context, clientId types.UUID) error {
|
||||||
req := CollectorUpdate{}
|
req := CollectorSet{}
|
||||||
if err := ctx.Bind(&req); err != nil {
|
if err := ctx.Bind(&req); err != nil {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, err)
|
return echo.NewHTTPError(http.StatusBadRequest, err)
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ func (s *Controllers) UpdateCollectorByClientId(ctx echo.Context, clientId types
|
|||||||
fields = &fs
|
fields = &fs
|
||||||
}
|
}
|
||||||
|
|
||||||
err := s.svc.CollectorUpdate.UpdateByClientId(ctx.Request().Context(), &collectorupdate.UpdateParams{
|
err := s.svc.CollectorSet.SetByClientId(ctx.Request().Context(), &collectorset.SetParams{
|
||||||
ClientID: clientId,
|
ClientID: clientId,
|
||||||
ActiveVersion: req.ActiveVersion,
|
ActiveVersion: req.ActiveVersion,
|
||||||
MinCleanVersion: req.MinimumCleanerVersion,
|
MinCleanVersion: req.MinimumCleanerVersion,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
queryservice "queryorchestration/api/queryService"
|
queryservice "queryorchestration/api/queryService"
|
||||||
"queryorchestration/internal/collector"
|
"queryorchestration/internal/collector"
|
||||||
collectorupdate "queryorchestration/internal/collector/update"
|
collectorset "queryorchestration/internal/collector/set"
|
||||||
"queryorchestration/internal/database"
|
"queryorchestration/internal/database"
|
||||||
"queryorchestration/internal/database/repository"
|
"queryorchestration/internal/database/repository"
|
||||||
cleanversion "queryorchestration/internal/document/clean/version"
|
cleanversion "queryorchestration/internal/document/clean/version"
|
||||||
@@ -31,7 +31,7 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUpdateCollector(t *testing.T) {
|
func TestSetCollector(t *testing.T) {
|
||||||
pool, err := pgxmock.NewPool()
|
pool, err := pgxmock.NewPool()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cfg := &struct {
|
cfg := &struct {
|
||||||
@@ -51,7 +51,7 @@ func TestUpdateCollector(t *testing.T) {
|
|||||||
|
|
||||||
av := int32(2)
|
av := int32(2)
|
||||||
cv := int32(1)
|
cv := int32(1)
|
||||||
body := queryservice.CollectorUpdate{
|
body := queryservice.CollectorSet{
|
||||||
ActiveVersion: &av,
|
ActiveVersion: &av,
|
||||||
MinimumCleanerVersion: &cv,
|
MinimumCleanerVersion: &cv,
|
||||||
Fields: &[]queryservice.CollectorField{
|
Fields: &[]queryservice.CollectorField{
|
||||||
@@ -71,11 +71,10 @@ func TestUpdateCollector(t *testing.T) {
|
|||||||
ctx := e.NewContext(req, rec)
|
ctx := e.NewContext(req, rec)
|
||||||
|
|
||||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||||
CollectorUpdate: collectorupdate.New(cfg, &collectorupdate.Services{
|
CollectorSet: collectorset.New(cfg, &collectorset.Services{
|
||||||
Collector: collector.New(cfg, &collector.Services{
|
CleanVersion: cleanversion.New(cfg),
|
||||||
CleanVersion: cleanversion.New(cfg),
|
TextVersion: textversion.New(cfg),
|
||||||
TextVersion: textversion.New(cfg),
|
Collector: collector.New(cfg),
|
||||||
}),
|
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -114,7 +113,7 @@ func TestUpdateCollector(t *testing.T) {
|
|||||||
).
|
).
|
||||||
Return(&sqs.SendMessageOutput{}, nil)
|
Return(&sqs.SendMessageOutput{}, nil)
|
||||||
|
|
||||||
err = cons.UpdateCollectorByClientId(ctx, current.ClientID)
|
err = cons.SetCollectorByClientId(ctx, current.ClientID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, http.StatusOK, rec.Code)
|
assert.Equal(t, http.StatusOK, rec.Code)
|
||||||
assert.Empty(t, rec.Body.String())
|
assert.Empty(t, rec.Body.String())
|
||||||
@@ -132,10 +131,7 @@ func TestGetCollectorByclientId(t *testing.T) {
|
|||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
ctx := e.NewContext(req, rec)
|
ctx := e.NewContext(req, rec)
|
||||||
|
|
||||||
svc := collector.New(cfg, &collector.Services{
|
svc := collector.New(cfg)
|
||||||
CleanVersion: cleanversion.New(cfg),
|
|
||||||
TextVersion: textversion.New(cfg),
|
|
||||||
})
|
|
||||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||||
Collector: svc,
|
Collector: svc,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package queryservice
|
|||||||
import (
|
import (
|
||||||
"queryorchestration/internal/client"
|
"queryorchestration/internal/client"
|
||||||
"queryorchestration/internal/collector"
|
"queryorchestration/internal/collector"
|
||||||
collectorupdate "queryorchestration/internal/collector/update"
|
collectorset "queryorchestration/internal/collector/set"
|
||||||
"queryorchestration/internal/document"
|
"queryorchestration/internal/document"
|
||||||
"queryorchestration/internal/export"
|
"queryorchestration/internal/export"
|
||||||
"queryorchestration/internal/query"
|
"queryorchestration/internal/query"
|
||||||
@@ -16,14 +16,14 @@ import (
|
|||||||
const Name = "queryService"
|
const Name = "queryService"
|
||||||
|
|
||||||
type Services struct {
|
type Services struct {
|
||||||
Export *export.Service
|
Export *export.Service
|
||||||
Collector *collector.Service
|
Collector *collector.Service
|
||||||
CollectorUpdate *collectorupdate.Service
|
CollectorSet *collectorset.Service
|
||||||
Query *query.Service
|
Query *query.Service
|
||||||
QueryUpdate *queryupdate.Service
|
QueryUpdate *queryupdate.Service
|
||||||
QueryTest *querytest.Service
|
QueryTest *querytest.Service
|
||||||
Client *client.Service
|
Client *client.Service
|
||||||
Document *document.Service
|
Document *document.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
type Controllers struct {
|
type Controllers struct {
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ import (
|
|||||||
"queryorchestration/internal/database"
|
"queryorchestration/internal/database"
|
||||||
"queryorchestration/internal/database/repository"
|
"queryorchestration/internal/database/repository"
|
||||||
"queryorchestration/internal/document"
|
"queryorchestration/internal/document"
|
||||||
cleanversion "queryorchestration/internal/document/clean/version"
|
|
||||||
textversion "queryorchestration/internal/document/text/version"
|
|
||||||
"queryorchestration/internal/query"
|
"queryorchestration/internal/query"
|
||||||
"queryorchestration/internal/query/result"
|
"queryorchestration/internal/query/result"
|
||||||
querytest "queryorchestration/internal/query/test"
|
querytest "queryorchestration/internal/query/test"
|
||||||
@@ -230,10 +228,7 @@ func TestTestQuery(t *testing.T) {
|
|||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
docsvc := document.New(cfg)
|
docsvc := document.New(cfg)
|
||||||
col := collector.New(cfg, &collector.Services{
|
col := collector.New(cfg)
|
||||||
CleanVersion: cleanversion.New(cfg),
|
|
||||||
TextVersion: textversion.New(cfg),
|
|
||||||
})
|
|
||||||
que := query.New(cfg)
|
que := query.New(cfg)
|
||||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||||
Collector: col,
|
Collector: col,
|
||||||
|
|||||||
@@ -9,11 +9,8 @@ import (
|
|||||||
|
|
||||||
queryservice "queryorchestration/api/queryService"
|
queryservice "queryorchestration/api/queryService"
|
||||||
"queryorchestration/internal/client"
|
"queryorchestration/internal/client"
|
||||||
"queryorchestration/internal/collector"
|
|
||||||
"queryorchestration/internal/database"
|
"queryorchestration/internal/database"
|
||||||
"queryorchestration/internal/database/repository"
|
"queryorchestration/internal/database/repository"
|
||||||
cleanversion "queryorchestration/internal/document/clean/version"
|
|
||||||
textversion "queryorchestration/internal/document/text/version"
|
|
||||||
"queryorchestration/internal/serviceconfig"
|
"queryorchestration/internal/serviceconfig"
|
||||||
|
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
@@ -32,12 +29,7 @@ func TestGetClientStatus(t *testing.T) {
|
|||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||||
Client: client.New(cfg, &client.Services{
|
Client: client.New(cfg),
|
||||||
Collector: collector.New(cfg, &collector.Services{
|
|
||||||
TextVersion: textversion.New(cfg),
|
|
||||||
CleanVersion: cleanversion.New(cfg),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
|
|||||||
@@ -16,11 +16,8 @@ import (
|
|||||||
|
|
||||||
docsyncrunner "queryorchestration/api/docSyncRunner"
|
docsyncrunner "queryorchestration/api/docSyncRunner"
|
||||||
"queryorchestration/internal/client"
|
"queryorchestration/internal/client"
|
||||||
"queryorchestration/internal/collector"
|
|
||||||
"queryorchestration/internal/document"
|
"queryorchestration/internal/document"
|
||||||
cleanversion "queryorchestration/internal/document/clean/version"
|
|
||||||
documentsync "queryorchestration/internal/document/sync"
|
documentsync "queryorchestration/internal/document/sync"
|
||||||
textversion "queryorchestration/internal/document/text/version"
|
|
||||||
"queryorchestration/internal/server/runner"
|
"queryorchestration/internal/server/runner"
|
||||||
documentcleanc "queryorchestration/internal/serviceconfig/queue/documentclean"
|
documentcleanc "queryorchestration/internal/serviceconfig/queue/documentclean"
|
||||||
|
|
||||||
@@ -38,13 +35,7 @@ func main() {
|
|||||||
cfg := &DocSyncConfig{}
|
cfg := &DocSyncConfig{}
|
||||||
|
|
||||||
cfg.ControllerFunc = func() runner.Controller {
|
cfg.ControllerFunc = func() runner.Controller {
|
||||||
coll := collector.New(cfg, &collector.Services{
|
cli := client.New(cfg)
|
||||||
CleanVersion: cleanversion.New(cfg),
|
|
||||||
TextVersion: textversion.New(cfg),
|
|
||||||
})
|
|
||||||
cli := client.New(cfg, &client.Services{
|
|
||||||
Collector: coll,
|
|
||||||
})
|
|
||||||
doc := document.New(cfg)
|
doc := document.New(cfg)
|
||||||
docsync := documentsync.New(cfg, &documentsync.Services{
|
docsync := documentsync.New(cfg, &documentsync.Services{
|
||||||
Document: doc,
|
Document: doc,
|
||||||
|
|||||||
+12
-17
@@ -22,7 +22,7 @@ import (
|
|||||||
queryservice "queryorchestration/api/queryService"
|
queryservice "queryorchestration/api/queryService"
|
||||||
"queryorchestration/internal/client"
|
"queryorchestration/internal/client"
|
||||||
"queryorchestration/internal/collector"
|
"queryorchestration/internal/collector"
|
||||||
collectorupdate "queryorchestration/internal/collector/update"
|
collectorset "queryorchestration/internal/collector/set"
|
||||||
"queryorchestration/internal/document"
|
"queryorchestration/internal/document"
|
||||||
cleanversion "queryorchestration/internal/document/clean/version"
|
cleanversion "queryorchestration/internal/document/clean/version"
|
||||||
textversion "queryorchestration/internal/document/text/version"
|
textversion "queryorchestration/internal/document/text/version"
|
||||||
@@ -58,18 +58,13 @@ func main() {
|
|||||||
})
|
})
|
||||||
tev := textversion.New(cfg)
|
tev := textversion.New(cfg)
|
||||||
clv := cleanversion.New(cfg)
|
clv := cleanversion.New(cfg)
|
||||||
col := collector.New(cfg, &collector.Services{
|
col := collector.New(cfg)
|
||||||
CleanVersion: clv,
|
colupdate := collectorset.New(cfg, &collectorset.Services{
|
||||||
TextVersion: tev,
|
|
||||||
})
|
|
||||||
colupdate := collectorupdate.New(cfg, &collectorupdate.Services{
|
|
||||||
Collector: col,
|
Collector: col,
|
||||||
CleanVersion: clv,
|
CleanVersion: clv,
|
||||||
TextVersion: tev,
|
TextVersion: tev,
|
||||||
})
|
})
|
||||||
cli := client.New(cfg, &client.Services{
|
cli := client.New(cfg)
|
||||||
Collector: col,
|
|
||||||
})
|
|
||||||
doc := document.New(cfg)
|
doc := document.New(cfg)
|
||||||
quetest := querytest.New(cfg, &querytest.Services{
|
quetest := querytest.New(cfg, &querytest.Services{
|
||||||
Collector: col,
|
Collector: col,
|
||||||
@@ -81,14 +76,14 @@ func main() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
services := &queryservice.Services{
|
services := &queryservice.Services{
|
||||||
Export: exp,
|
Export: exp,
|
||||||
Collector: col,
|
Collector: col,
|
||||||
CollectorUpdate: colupdate,
|
CollectorSet: colupdate,
|
||||||
Query: que,
|
Query: que,
|
||||||
QueryUpdate: qupdate,
|
QueryUpdate: qupdate,
|
||||||
QueryTest: quetest,
|
QueryTest: quetest,
|
||||||
Client: cli,
|
Client: cli,
|
||||||
Document: doc,
|
Document: doc,
|
||||||
}
|
}
|
||||||
|
|
||||||
cons := queryservice.NewControllers(cfg.GetValidator(), services)
|
cons := queryservice.NewControllers(cfg.GetValidator(), services)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package client
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"queryorchestration/internal/collector"
|
|
||||||
"queryorchestration/internal/database"
|
"queryorchestration/internal/database"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@@ -20,12 +19,5 @@ func (s *Service) Create(ctx context.Context, name string) (uuid.UUID, error) {
|
|||||||
return uuid.Nil, err
|
return uuid.Nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.svc.Collector.Create(ctx, &collector.CreateParams{
|
|
||||||
ClientID: database.MustToUUID(id),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return uuid.Nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return database.MustToUUID(id), nil
|
return database.MustToUUID(id), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,11 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"queryorchestration/internal/client"
|
"queryorchestration/internal/client"
|
||||||
"queryorchestration/internal/collector"
|
|
||||||
"queryorchestration/internal/database"
|
"queryorchestration/internal/database"
|
||||||
"queryorchestration/internal/database/repository"
|
"queryorchestration/internal/database/repository"
|
||||||
cleanversion "queryorchestration/internal/document/clean/version"
|
|
||||||
textversion "queryorchestration/internal/document/text/version"
|
|
||||||
"queryorchestration/internal/serviceconfig"
|
"queryorchestration/internal/serviceconfig"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/jackc/pgx/v5"
|
|
||||||
"github.com/pashagolub/pgxmock/v3"
|
"github.com/pashagolub/pgxmock/v3"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -28,12 +24,7 @@ func TestCreate(t *testing.T) {
|
|||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
svc := client.New(cfg, &client.Services{
|
svc := client.New(cfg)
|
||||||
Collector: collector.New(cfg, &collector.Services{
|
|
||||||
CleanVersion: cleanversion.New(cfg),
|
|
||||||
TextVersion: textversion.New(cfg),
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
|
|
||||||
name := "client_name"
|
name := "client_name"
|
||||||
aid := uuid.New()
|
aid := uuid.New()
|
||||||
@@ -43,14 +34,6 @@ func TestCreate(t *testing.T) {
|
|||||||
pgxmock.NewRows([]string{"id"}).
|
pgxmock.NewRows([]string{"id"}).
|
||||||
AddRow(database.MustToDBUUID(aid)),
|
AddRow(database.MustToDBUUID(aid)),
|
||||||
)
|
)
|
||||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
|
||||||
pool.ExpectQuery("name: AddLatestCollectorVersion :one").WithArgs(database.MustToDBUUID(aid)).WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"version"}).
|
|
||||||
AddRow(int32(1)),
|
|
||||||
)
|
|
||||||
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(database.MustToDBUUID(aid), int32(1)).
|
|
||||||
WillReturnResult(pgxmock.NewResult("", 1))
|
|
||||||
pool.ExpectCommit()
|
|
||||||
|
|
||||||
id, err := svc.Create(ctx, name)
|
id, err := svc.Create(ctx, name)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ func TestGet(t *testing.T) {
|
|||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
svc := client.New(cfg, &client.Services{})
|
svc := client.New(cfg)
|
||||||
|
|
||||||
id := uuid.New()
|
id := uuid.New()
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"queryorchestration/internal/collector"
|
|
||||||
"queryorchestration/internal/serviceconfig"
|
"queryorchestration/internal/serviceconfig"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@@ -71,18 +70,12 @@ func normalizeName(name *string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Services struct {
|
|
||||||
Collector *collector.Service
|
|
||||||
}
|
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
cfg serviceconfig.ConfigProvider
|
cfg serviceconfig.ConfigProvider
|
||||||
svc *Services
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg serviceconfig.ConfigProvider, svc *Services) *Service {
|
func New(cfg serviceconfig.ConfigProvider) *Service {
|
||||||
return &Service{
|
return &Service{
|
||||||
cfg,
|
cfg,
|
||||||
svc,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,6 @@ func TestService(t *testing.T) {
|
|||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
svc := client.New(cfg, &client.Services{})
|
svc := client.New(cfg)
|
||||||
assert.NotNil(t, svc)
|
assert.NotNil(t, svc)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ func TestGetStatus(t *testing.T) {
|
|||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
svc := client.New(cfg, &client.Services{})
|
svc := client.New(cfg)
|
||||||
|
|
||||||
clientId := uuid.New()
|
clientId := uuid.New()
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
svc := New(cfg, &Services{})
|
svc := New(cfg)
|
||||||
|
|
||||||
c := Client{
|
c := Client{
|
||||||
ID: uuid.New(),
|
ID: uuid.New(),
|
||||||
@@ -120,7 +120,7 @@ func TestSubmitUpdate(t *testing.T) {
|
|||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
svc := New(cfg, &Services{})
|
svc := New(cfg)
|
||||||
|
|
||||||
c := Client{
|
c := Client{
|
||||||
ID: uuid.New(),
|
ID: uuid.New(),
|
||||||
|
|||||||
@@ -1,154 +0,0 @@
|
|||||||
package collector
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
|
|
||||||
"queryorchestration/internal/database"
|
|
||||||
"queryorchestration/internal/database/repository"
|
|
||||||
"queryorchestration/internal/validation"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/jackc/pgx/v5/pgtype"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CreateParams struct {
|
|
||||||
ClientID uuid.UUID
|
|
||||||
MinCleanVersion *int32
|
|
||||||
MinTextVersion *int32
|
|
||||||
Fields *map[string]uuid.UUID
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) Create(ctx context.Context, params *CreateParams) error {
|
|
||||||
dbparams, err := s.getCreateParams(ctx, params)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return s.submitCreate(ctx, dbparams)
|
|
||||||
}
|
|
||||||
|
|
||||||
type dbCreateParams struct {
|
|
||||||
ClientID pgtype.UUID
|
|
||||||
MinCleanVersion *int32
|
|
||||||
MinTextVersion *int32
|
|
||||||
Fields *map[string]pgtype.UUID
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) getCreateParams(ctx context.Context, params *CreateParams) (*dbCreateParams, error) {
|
|
||||||
minClean := params.MinCleanVersion
|
|
||||||
if minClean != nil {
|
|
||||||
err := s.svc.CleanVersion.IsValidVersion(*minClean)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
minText := params.MinTextVersion
|
|
||||||
if minText != nil {
|
|
||||||
err := s.svc.TextVersion.IsValidVersion(*minText)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fields, err := s.NormalizeFieldsToDB(ctx, params.Fields)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &dbCreateParams{
|
|
||||||
ClientID: database.MustToDBUUID(params.ClientID),
|
|
||||||
MinCleanVersion: minClean,
|
|
||||||
MinTextVersion: minText,
|
|
||||||
Fields: fields,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) NormalizeFieldsToDB(ctx context.Context, ofields *map[string]uuid.UUID) (*map[string]pgtype.UUID, error) {
|
|
||||||
if ofields == nil || *ofields == nil {
|
|
||||||
return nil, nil
|
|
||||||
} else if len(*ofields) == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
dbm := map[string]pgtype.UUID{}
|
|
||||||
for name, id := range *ofields {
|
|
||||||
dbm[name] = database.MustToDBUUID(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
dbids := []pgtype.UUID{}
|
|
||||||
for _, id := range dbm {
|
|
||||||
dbids = append(dbids, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
dedup := validation.DeduplicateArray(dbids)
|
|
||||||
|
|
||||||
if len(dedup) != len(dbids) {
|
|
||||||
return nil, errors.New("duplicate output fields")
|
|
||||||
}
|
|
||||||
|
|
||||||
exist, err := s.cfg.GetDBQueries().AllQueriesExist(ctx, dbids)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else if !exist {
|
|
||||||
return nil, errors.New("not all required ids are present")
|
|
||||||
}
|
|
||||||
|
|
||||||
return &dbm, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) submitCreate(ctx context.Context, params *dbCreateParams) error {
|
|
||||||
return s.cfg.ExecuteDBTransaction(ctx, func(ctx context.Context, qtx *repository.Queries) error {
|
|
||||||
version, err := qtx.AddLatestCollectorVersion(ctx, params.ClientID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = qtx.SetActiveCollectorVersion(ctx, &repository.SetActiveCollectorVersionParams{
|
|
||||||
Clientid: params.ClientID,
|
|
||||||
Versionid: version,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if params.MinCleanVersion != nil {
|
|
||||||
err = qtx.SetCollectorCleanVersion(ctx, &repository.SetCollectorCleanVersionParams{
|
|
||||||
Clientid: params.ClientID,
|
|
||||||
Versionid: *params.MinCleanVersion,
|
|
||||||
Addedversion: version,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if params.MinTextVersion != nil {
|
|
||||||
err = qtx.SetCollectorTextVersion(ctx, &repository.SetCollectorTextVersionParams{
|
|
||||||
Clientid: params.ClientID,
|
|
||||||
Versionid: *params.MinTextVersion,
|
|
||||||
Addedversion: version,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if params.Fields != nil {
|
|
||||||
for key, field := range *params.Fields {
|
|
||||||
err = qtx.AddCollectorQuery(ctx, &repository.AddCollectorQueryParams{
|
|
||||||
Clientid: params.ClientID,
|
|
||||||
Name: key,
|
|
||||||
Queryid: field,
|
|
||||||
Addedversion: version,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package collector_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"queryorchestration/internal/collector"
|
|
||||||
"queryorchestration/internal/database"
|
|
||||||
"queryorchestration/internal/database/repository"
|
|
||||||
"queryorchestration/internal/serviceconfig"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/jackc/pgx/v5"
|
|
||||||
"github.com/pashagolub/pgxmock/v3"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestCreate(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, &collector.Services{})
|
|
||||||
|
|
||||||
minCleanV := int32(1)
|
|
||||||
minTextV := int32(1)
|
|
||||||
create := collector.CreateParams{
|
|
||||||
ClientID: uuid.New(),
|
|
||||||
MinCleanVersion: &minCleanV,
|
|
||||||
MinTextVersion: &minTextV,
|
|
||||||
Fields: &map[string]uuid.UUID{
|
|
||||||
"example_key": uuid.New(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(database.MustToDBUUIDArray([]uuid.UUID{(*create.Fields)["example_key"]})).WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"all_exist"}).
|
|
||||||
AddRow(true),
|
|
||||||
)
|
|
||||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
|
||||||
pool.ExpectQuery("name: AddLatestCollectorVersion :one").WithArgs(database.MustToDBUUID(create.ClientID)).WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"version"}).
|
|
||||||
AddRow(int32(1)),
|
|
||||||
)
|
|
||||||
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(database.MustToDBUUID(create.ClientID), int32(1)).
|
|
||||||
WillReturnResult(pgxmock.NewResult("", 1))
|
|
||||||
pool.ExpectExec("name: SetCollectorCleanVersion :exec").WithArgs(database.MustToDBUUID(create.ClientID), int32(1), *create.MinCleanVersion).
|
|
||||||
WillReturnResult(pgxmock.NewResult("", 1))
|
|
||||||
pool.ExpectExec("name: SetCollectorTextVersion :exec").WithArgs(database.MustToDBUUID(create.ClientID), int32(1), *create.MinTextVersion).
|
|
||||||
WillReturnResult(pgxmock.NewResult("", 1))
|
|
||||||
pool.ExpectExec("name: AddCollectorQuery :exec").WithArgs(database.MustToDBUUID(create.ClientID), "example_key", database.MustToDBUUID((*create.Fields)["example_key"]), int32(1)).
|
|
||||||
WillReturnResult(pgxmock.NewResult("", 1))
|
|
||||||
pool.ExpectCommit()
|
|
||||||
|
|
||||||
err = svc.Create(ctx, &create)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
}
|
|
||||||
@@ -1,148 +0,0 @@
|
|||||||
package collector
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"queryorchestration/internal/database"
|
|
||||||
"queryorchestration/internal/database/repository"
|
|
||||||
"queryorchestration/internal/serviceconfig"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/jackc/pgx/v5"
|
|
||||||
"github.com/jackc/pgx/v5/pgtype"
|
|
||||||
"github.com/pashagolub/pgxmock/v3"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestGetCreateParams(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 := Service{
|
|
||||||
cfg: cfg,
|
|
||||||
svc: &Services{},
|
|
||||||
}
|
|
||||||
|
|
||||||
minCleanV := int32(1)
|
|
||||||
minTextV := int32(1)
|
|
||||||
params := CreateParams{
|
|
||||||
ClientID: uuid.New(),
|
|
||||||
MinCleanVersion: &minCleanV,
|
|
||||||
MinTextVersion: &minTextV,
|
|
||||||
Fields: &map[string]uuid.UUID{
|
|
||||||
"example_key": uuid.New(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(database.MustToDBUUIDArray([]uuid.UUID{(*params.Fields)["example_key"]})).WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"all_exist"}).
|
|
||||||
AddRow(true),
|
|
||||||
)
|
|
||||||
|
|
||||||
dbparams, err := svc.getCreateParams(ctx, ¶ms)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.EqualExportedValues(t, &dbCreateParams{
|
|
||||||
ClientID: database.MustToDBUUID(params.ClientID),
|
|
||||||
MinCleanVersion: &minCleanV,
|
|
||||||
MinTextVersion: &minTextV,
|
|
||||||
Fields: &map[string]pgtype.UUID{
|
|
||||||
"example_key": database.MustToDBUUID((*params.Fields)["example_key"]),
|
|
||||||
},
|
|
||||||
}, dbparams)
|
|
||||||
|
|
||||||
(*params.Fields)["second_key"] = (*params.Fields)["example_key"]
|
|
||||||
assert.Len(t, *params.Fields, 2)
|
|
||||||
_, err = svc.getCreateParams(ctx, ¶ms)
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSubmitCreate(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 := Service{
|
|
||||||
cfg: cfg,
|
|
||||||
svc: &Services{},
|
|
||||||
}
|
|
||||||
|
|
||||||
minCleanV := int32(2)
|
|
||||||
minTextV := int32(4)
|
|
||||||
params := dbCreateParams{
|
|
||||||
ClientID: database.MustToDBUUID(uuid.New()),
|
|
||||||
MinCleanVersion: &minCleanV,
|
|
||||||
MinTextVersion: &minTextV,
|
|
||||||
Fields: &map[string]pgtype.UUID{
|
|
||||||
"example_key": database.MustToDBUUID(uuid.New()),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
|
||||||
pool.ExpectQuery("name: AddLatestCollectorVersion :one").WithArgs(params.ClientID).WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"version"}).
|
|
||||||
AddRow(int32(1)),
|
|
||||||
)
|
|
||||||
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(params.ClientID, int32(1)).
|
|
||||||
WillReturnResult(pgxmock.NewResult("", 1))
|
|
||||||
pool.ExpectExec("name: SetCollectorCleanVersion :exec").WithArgs(params.ClientID, int32(1), *params.MinCleanVersion).
|
|
||||||
WillReturnResult(pgxmock.NewResult("", 1))
|
|
||||||
pool.ExpectExec("name: SetCollectorTextVersion :exec").WithArgs(params.ClientID, int32(1), *params.MinTextVersion).
|
|
||||||
WillReturnResult(pgxmock.NewResult("", 1))
|
|
||||||
pool.ExpectExec("name: AddCollectorQuery :exec").WithArgs(params.ClientID, "example_key", (*params.Fields)["example_key"], int32(1)).
|
|
||||||
WillReturnResult(pgxmock.NewResult("", 1))
|
|
||||||
pool.ExpectCommit()
|
|
||||||
|
|
||||||
err = svc.submitCreate(ctx, ¶ms)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNormalizeFieldsToDB(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 := Service{
|
|
||||||
cfg: cfg,
|
|
||||||
svc: &Services{},
|
|
||||||
}
|
|
||||||
|
|
||||||
fields := map[string]uuid.UUID{
|
|
||||||
"example_key": uuid.New(),
|
|
||||||
}
|
|
||||||
|
|
||||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(database.MustToDBUUIDArray([]uuid.UUID{fields["example_key"]})).WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"all_exist"}).
|
|
||||||
AddRow(true),
|
|
||||||
)
|
|
||||||
|
|
||||||
dbparams, err := svc.NormalizeFieldsToDB(ctx, &fields)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.EqualExportedValues(t, &map[string]pgtype.UUID{
|
|
||||||
"example_key": database.MustToDBUUID(fields["example_key"]),
|
|
||||||
}, dbparams)
|
|
||||||
|
|
||||||
fields["second_key"] = fields["example_key"]
|
|
||||||
|
|
||||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(database.MustToDBUUIDArray([]uuid.UUID{fields["example_key"]})).WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"all_exist"}).
|
|
||||||
AddRow(true),
|
|
||||||
)
|
|
||||||
|
|
||||||
_, err = svc.NormalizeFieldsToDB(ctx, &fields)
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
@@ -26,7 +26,7 @@ func TestGetByClientID(t *testing.T) {
|
|||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
svc := collector.New(cfg, &collector.Services{})
|
svc := collector.New(cfg)
|
||||||
|
|
||||||
minCleanV := int32(2)
|
minCleanV := int32(2)
|
||||||
minTextV := int32(4)
|
minTextV := int32(4)
|
||||||
@@ -59,7 +59,7 @@ func TestListQueries(t *testing.T) {
|
|||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
svc := collector.New(cfg, &collector.Services{})
|
svc := collector.New(cfg)
|
||||||
|
|
||||||
clientId := uuid.New()
|
clientId := uuid.New()
|
||||||
ogc := []*resultprocessor.Query{
|
ogc := []*resultprocessor.Query{
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
cleanversion "queryorchestration/internal/document/clean/version"
|
|
||||||
textversion "queryorchestration/internal/document/text/version"
|
|
||||||
"queryorchestration/internal/serviceconfig"
|
"queryorchestration/internal/serviceconfig"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@@ -17,19 +15,12 @@ type Collector struct {
|
|||||||
Fields map[string]uuid.UUID
|
Fields map[string]uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
type Services struct {
|
|
||||||
CleanVersion *cleanversion.Service
|
|
||||||
TextVersion *textversion.Service
|
|
||||||
}
|
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
cfg serviceconfig.ConfigProvider
|
cfg serviceconfig.ConfigProvider
|
||||||
svc *Services
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg serviceconfig.ConfigProvider, svc *Services) *Service {
|
func New(cfg serviceconfig.ConfigProvider) *Service {
|
||||||
return &Service{
|
return &Service{
|
||||||
cfg,
|
cfg,
|
||||||
svc,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,6 @@ func TestService(t *testing.T) {
|
|||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
svc := collector.New(cfg, &collector.Services{})
|
svc := collector.New(cfg)
|
||||||
assert.NotNil(t, svc)
|
assert.NotNil(t, svc)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package collectorupdate
|
package collectorset
|
||||||
|
|
||||||
import (
|
import (
|
||||||
collector "queryorchestration/internal/collector"
|
collector "queryorchestration/internal/collector"
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
package collectorupdate_test
|
package collectorset_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"queryorchestration/internal/collector"
|
collectorset "queryorchestration/internal/collector/set"
|
||||||
"queryorchestration/internal/database/repository"
|
"queryorchestration/internal/database/repository"
|
||||||
"queryorchestration/internal/serviceconfig"
|
|
||||||
|
|
||||||
"github.com/pashagolub/pgxmock/v3"
|
"github.com/pashagolub/pgxmock/v3"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -15,10 +14,10 @@ import (
|
|||||||
func TestService(t *testing.T) {
|
func TestService(t *testing.T) {
|
||||||
pool, err := pgxmock.NewPool()
|
pool, err := pgxmock.NewPool()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cfg := &serviceconfig.BaseConfig{}
|
cfg := &CollectorSetConfig{}
|
||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
svc := collector.New(cfg, &collector.Services{})
|
svc := collectorset.New(cfg, &collectorset.Services{})
|
||||||
assert.NotNil(t, svc)
|
assert.NotNil(t, svc)
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package collectorupdate
|
package collectorset
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/jackc/pgx/v5/pgtype"
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UpdateParams struct {
|
type SetParams struct {
|
||||||
ClientID uuid.UUID
|
ClientID uuid.UUID
|
||||||
ActiveVersion *int32
|
ActiveVersion *int32
|
||||||
MinCleanVersion *int32
|
MinCleanVersion *int32
|
||||||
@@ -24,23 +24,23 @@ type UpdateParams struct {
|
|||||||
Fields *map[string]uuid.UUID
|
Fields *map[string]uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) UpdateByClientId(ctx context.Context, params *UpdateParams) error {
|
func (s *Service) SetByClientId(ctx context.Context, params *SetParams) error {
|
||||||
current, err := s.svc.Collector.GetByClientID(ctx, params.ClientID)
|
current, err := s.svc.Collector.GetByClientID(ctx, params.ClientID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
dbparams, err := s.getUpdateParams(ctx, current, params)
|
dbparams, err := s.getSetParams(ctx, current, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.submitUpdate(ctx, current, dbparams)
|
err = s.submitSet(ctx, current, dbparams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.informUpdate(ctx, dbparams)
|
err = s.informSet(ctx, dbparams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ func (s *Service) UpdateByClientId(ctx context.Context, params *UpdateParams) er
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) informUpdate(ctx context.Context, update *dbUpdateParams) error {
|
func (s *Service) informSet(ctx context.Context, update *dbSetParams) error {
|
||||||
if update.ActiveVersion == nil {
|
if update.ActiveVersion == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ func (s *Service) informUpdate(ctx context.Context, update *dbUpdateParams) erro
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type dbUpdateParams struct {
|
type dbSetParams struct {
|
||||||
ClientID pgtype.UUID
|
ClientID pgtype.UUID
|
||||||
ActiveVersion *int32
|
ActiveVersion *int32
|
||||||
MinCleanVersion *int32
|
MinCleanVersion *int32
|
||||||
@@ -69,13 +69,13 @@ type dbUpdateParams struct {
|
|||||||
Fields *map[string]pgtype.UUID
|
Fields *map[string]pgtype.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) getUpdateParams(ctx context.Context, current *collector.Collector, params *UpdateParams) (*dbUpdateParams, error) {
|
func (s *Service) getSetParams(ctx context.Context, current *collector.Collector, params *SetParams) (*dbSetParams, error) {
|
||||||
err := s.normalizeCodeVersions(current, params)
|
err := s.normalizeCodeVersions(current, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fields, err := s.normalizeUpdateFieldsToDB(ctx, current.Fields, params.Fields)
|
fields, err := s.normalizeSetFieldsToDB(ctx, current.Fields, params.Fields)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ func (s *Service) getUpdateParams(ctx context.Context, current *collector.Collec
|
|||||||
return nil, errors.New("no changes")
|
return nil, errors.New("no changes")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &dbUpdateParams{
|
return &dbSetParams{
|
||||||
ClientID: database.MustToDBUUID(params.ClientID),
|
ClientID: database.MustToDBUUID(params.ClientID),
|
||||||
ActiveVersion: params.ActiveVersion,
|
ActiveVersion: params.ActiveVersion,
|
||||||
MinCleanVersion: params.MinCleanVersion,
|
MinCleanVersion: params.MinCleanVersion,
|
||||||
@@ -109,7 +109,7 @@ func (s *Service) getUpdateParams(ctx context.Context, current *collector.Collec
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) normalizeCodeVersions(current *collector.Collector, params *UpdateParams) error {
|
func (s *Service) normalizeCodeVersions(current *collector.Collector, params *SetParams) error {
|
||||||
if current == nil {
|
if current == nil {
|
||||||
return errors.New("current collector required")
|
return errors.New("current collector required")
|
||||||
}
|
}
|
||||||
@@ -143,7 +143,7 @@ func (s *Service) normalizeCodeVersions(current *collector.Collector, params *Up
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) normalizeActiveVersion(current *collector.Collector, params *UpdateParams) error {
|
func (s *Service) normalizeActiveVersion(current *collector.Collector, params *SetParams) error {
|
||||||
if current == nil {
|
if current == nil {
|
||||||
return errors.New("current collector required")
|
return errors.New("current collector required")
|
||||||
}
|
}
|
||||||
@@ -160,7 +160,7 @@ func (s *Service) normalizeActiveVersion(current *collector.Collector, params *U
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) normalizeUpdateFieldsToDB(ctx context.Context, current map[string]uuid.UUID, ofields *map[string]uuid.UUID) (*map[string]pgtype.UUID, error) {
|
func (s *Service) normalizeSetFieldsToDB(ctx context.Context, current map[string]uuid.UUID, ofields *map[string]uuid.UUID) (*map[string]pgtype.UUID, error) {
|
||||||
if ofields == nil || *ofields == nil {
|
if ofields == nil || *ofields == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
} else if len(*ofields) == 0 {
|
} else if len(*ofields) == 0 {
|
||||||
@@ -179,10 +179,10 @@ func (s *Service) normalizeUpdateFieldsToDB(ctx context.Context, current map[str
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.svc.Collector.NormalizeFieldsToDB(ctx, ofields)
|
return s.normalizeFieldsToDB(ctx, ofields)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) submitUpdate(ctx context.Context, current *collector.Collector, params *dbUpdateParams) error {
|
func (s *Service) submitSet(ctx context.Context, current *collector.Collector, params *dbSetParams) error {
|
||||||
err := s.cfg.ExecuteDBTransaction(ctx, func(ctx context.Context, qtx *repository.Queries) error {
|
err := s.cfg.ExecuteDBTransaction(ctx, func(ctx context.Context, qtx *repository.Queries) error {
|
||||||
activeName, err := validation.GetFieldName(params, params.ActiveVersion)
|
activeName, err := validation.GetFieldName(params, params.ActiveVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -304,3 +304,36 @@ func getAddFields(current map[string]uuid.UUID, update *map[string]pgtype.UUID)
|
|||||||
|
|
||||||
return diff
|
return diff
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) normalizeFieldsToDB(ctx context.Context, ofields *map[string]uuid.UUID) (*map[string]pgtype.UUID, error) {
|
||||||
|
if ofields == nil || *ofields == nil {
|
||||||
|
return nil, nil
|
||||||
|
} else if len(*ofields) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
dbm := map[string]pgtype.UUID{}
|
||||||
|
for name, id := range *ofields {
|
||||||
|
dbm[name] = database.MustToDBUUID(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
dbids := []pgtype.UUID{}
|
||||||
|
for _, id := range dbm {
|
||||||
|
dbids = append(dbids, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
dedup := validation.DeduplicateArray(dbids)
|
||||||
|
|
||||||
|
if len(dedup) != len(dbids) {
|
||||||
|
return nil, errors.New("duplicate output fields")
|
||||||
|
}
|
||||||
|
|
||||||
|
exist, err := s.cfg.GetDBQueries().AllQueriesExist(ctx, dbids)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if !exist {
|
||||||
|
return nil, errors.New("not all required ids are present")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &dbm, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
package collectorset_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"queryorchestration/internal/collector"
|
||||||
|
collectorset "queryorchestration/internal/collector/set"
|
||||||
|
"queryorchestration/internal/database"
|
||||||
|
"queryorchestration/internal/database/repository"
|
||||||
|
"queryorchestration/internal/serviceconfig"
|
||||||
|
"queryorchestration/internal/serviceconfig/queue/clientsync"
|
||||||
|
queuemock "queryorchestration/mocks/queue"
|
||||||
|
|
||||||
|
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
|
"github.com/pashagolub/pgxmock/v3"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/mock"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CollectorSetConfig struct {
|
||||||
|
serviceconfig.BaseConfig
|
||||||
|
clientsync.ClientSyncConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSet(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
pool, err := pgxmock.NewPool()
|
||||||
|
require.NoError(t, err)
|
||||||
|
cfg := &CollectorSetConfig{}
|
||||||
|
cfg.DBPool = pool
|
||||||
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
mockSQS := queuemock.NewMockSQSClient(t)
|
||||||
|
cfg.QueueClient = mockSQS
|
||||||
|
cfg.ClientSyncURL = "here"
|
||||||
|
|
||||||
|
svc := collectorset.New(cfg, &collectorset.Services{
|
||||||
|
Collector: collector.New(cfg),
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("valid", func(t *testing.T) {
|
||||||
|
current := collector.Collector{
|
||||||
|
ClientID: uuid.New(),
|
||||||
|
ActiveVersion: 1,
|
||||||
|
LatestVersion: 4,
|
||||||
|
}
|
||||||
|
av := int32(2)
|
||||||
|
mv := int32(1)
|
||||||
|
update := collectorset.SetParams{
|
||||||
|
ClientID: current.ClientID,
|
||||||
|
ActiveVersion: &av,
|
||||||
|
MinCleanVersion: &mv,
|
||||||
|
}
|
||||||
|
|
||||||
|
pool.ExpectQuery("name: GetCollectorByClientID :one").WithArgs(database.MustToDBUUID(update.ClientID)).
|
||||||
|
WillReturnRows(
|
||||||
|
pgxmock.NewRows([]string{"clientId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
|
||||||
|
AddRow(database.MustToDBUUID(current.ClientID), current.MinCleanVersion, current.MinTextVersion, current.ActiveVersion, current.LatestVersion, []byte("")),
|
||||||
|
)
|
||||||
|
pool.ExpectBeginTx(pgx.TxOptions{})
|
||||||
|
rv := current.LatestVersion + 1
|
||||||
|
pool.ExpectQuery("name: AddLatestCollectorVersion :one").WithArgs(database.MustToDBUUID(current.ClientID)).WillReturnRows(
|
||||||
|
pgxmock.NewRows([]string{"version"}).
|
||||||
|
AddRow(rv),
|
||||||
|
)
|
||||||
|
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), int32(2)).
|
||||||
|
WillReturnResult(pgxmock.NewResult("", 1))
|
||||||
|
pool.ExpectExec("name: SetCollectorCleanVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), rv, *update.MinCleanVersion).
|
||||||
|
WillReturnResult(pgxmock.NewResult("", 1))
|
||||||
|
pool.ExpectCommit()
|
||||||
|
|
||||||
|
mockSQS.EXPECT().
|
||||||
|
SendMessage(
|
||||||
|
mock.Anything,
|
||||||
|
mock.MatchedBy(func(in *sqs.SendMessageInput) bool {
|
||||||
|
return *in.QueueUrl == cfg.ClientSyncURL && *in.MessageBody == fmt.Sprintf("{\"id\":\"%s\"}", update.ClientID.String())
|
||||||
|
}),
|
||||||
|
mock.Anything,
|
||||||
|
).
|
||||||
|
Return(&sqs.SendMessageOutput{}, nil)
|
||||||
|
|
||||||
|
err = svc.SetByClientId(ctx, &update)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
})
|
||||||
|
t.Run("no collector", func(t *testing.T) {
|
||||||
|
current := collector.Collector{
|
||||||
|
ClientID: uuid.New(),
|
||||||
|
}
|
||||||
|
av := int32(1)
|
||||||
|
mv := int32(1)
|
||||||
|
update := collectorset.SetParams{
|
||||||
|
ClientID: current.ClientID,
|
||||||
|
ActiveVersion: &av,
|
||||||
|
MinCleanVersion: &mv,
|
||||||
|
}
|
||||||
|
|
||||||
|
pool.ExpectQuery("name: GetCollectorByClientID :one").WithArgs(database.MustToDBUUID(update.ClientID)).
|
||||||
|
WillReturnRows(
|
||||||
|
pgxmock.NewRows([]string{"clientId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
|
||||||
|
AddRow(database.MustToDBUUID(current.ClientID), current.MinCleanVersion, current.MinTextVersion, current.ActiveVersion, current.LatestVersion, []byte("")),
|
||||||
|
)
|
||||||
|
pool.ExpectBeginTx(pgx.TxOptions{})
|
||||||
|
rv := current.LatestVersion + 1
|
||||||
|
pool.ExpectQuery("name: AddLatestCollectorVersion :one").WithArgs(database.MustToDBUUID(current.ClientID)).WillReturnRows(
|
||||||
|
pgxmock.NewRows([]string{"version"}).
|
||||||
|
AddRow(rv),
|
||||||
|
)
|
||||||
|
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), int32(1)).
|
||||||
|
WillReturnResult(pgxmock.NewResult("", 1))
|
||||||
|
pool.ExpectExec("name: SetCollectorCleanVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), rv, *update.MinCleanVersion).
|
||||||
|
WillReturnResult(pgxmock.NewResult("", 1))
|
||||||
|
pool.ExpectCommit()
|
||||||
|
|
||||||
|
mockSQS.EXPECT().
|
||||||
|
SendMessage(
|
||||||
|
mock.Anything,
|
||||||
|
mock.MatchedBy(func(in *sqs.SendMessageInput) bool {
|
||||||
|
return *in.QueueUrl == cfg.ClientSyncURL && *in.MessageBody == fmt.Sprintf("{\"id\":\"%s\"}", update.ClientID.String())
|
||||||
|
}),
|
||||||
|
mock.Anything,
|
||||||
|
).
|
||||||
|
Return(&sqs.SendMessageOutput{}, nil)
|
||||||
|
|
||||||
|
err = svc.SetByClientId(ctx, &update)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
})
|
||||||
|
}
|
||||||
+93
-53
@@ -1,4 +1,4 @@
|
|||||||
package collectorupdate
|
package collectorset
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -24,25 +24,25 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CollectorUpdateConfig struct {
|
type CollectorSetConfig struct {
|
||||||
serviceconfig.BaseConfig
|
serviceconfig.BaseConfig
|
||||||
clientsync.ClientSyncConfig
|
clientsync.ClientSyncConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetUpdateParams(t *testing.T) {
|
func TestGetSetParams(t *testing.T) {
|
||||||
t.Run("all params", func(t *testing.T) {
|
t.Run("all params", func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
pool, err := pgxmock.NewPool()
|
pool, err := pgxmock.NewPool()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cfg := &CollectorUpdateConfig{}
|
cfg := &CollectorSetConfig{}
|
||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
svc := Service{
|
svc := Service{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
svc: &Services{
|
svc: &Services{
|
||||||
Collector: collector.New(cfg, &collector.Services{}),
|
Collector: collector.New(cfg),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ func TestGetUpdateParams(t *testing.T) {
|
|||||||
ActiveVersion: 1,
|
ActiveVersion: 1,
|
||||||
LatestVersion: 10,
|
LatestVersion: 10,
|
||||||
}
|
}
|
||||||
params := UpdateParams{
|
params := SetParams{
|
||||||
ClientID: uuid.New(),
|
ClientID: uuid.New(),
|
||||||
ActiveVersion: &aV,
|
ActiveVersion: &aV,
|
||||||
MinCleanVersion: &minCleanV,
|
MinCleanVersion: &minCleanV,
|
||||||
@@ -68,9 +68,9 @@ func TestGetUpdateParams(t *testing.T) {
|
|||||||
AddRow(true),
|
AddRow(true),
|
||||||
)
|
)
|
||||||
|
|
||||||
dbparams, err := svc.getUpdateParams(ctx, ¤t, ¶ms)
|
dbparams, err := svc.getSetParams(ctx, ¤t, ¶ms)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualExportedValues(t, &dbUpdateParams{
|
assert.EqualExportedValues(t, &dbSetParams{
|
||||||
ClientID: database.MustToDBUUID(params.ClientID),
|
ClientID: database.MustToDBUUID(params.ClientID),
|
||||||
ActiveVersion: &aV,
|
ActiveVersion: &aV,
|
||||||
MinCleanVersion: &minCleanV,
|
MinCleanVersion: &minCleanV,
|
||||||
@@ -82,7 +82,7 @@ func TestGetUpdateParams(t *testing.T) {
|
|||||||
|
|
||||||
(*params.Fields)["second_key"] = (*params.Fields)["example_key"]
|
(*params.Fields)["second_key"] = (*params.Fields)["example_key"]
|
||||||
assert.Len(t, *params.Fields, 2)
|
assert.Len(t, *params.Fields, 2)
|
||||||
_, err = svc.getUpdateParams(ctx, ¤t, ¶ms)
|
_, err = svc.getSetParams(ctx, ¤t, ¶ms)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ func TestGetUpdateParams(t *testing.T) {
|
|||||||
|
|
||||||
pool, err := pgxmock.NewPool()
|
pool, err := pgxmock.NewPool()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cfg := &CollectorUpdateConfig{}
|
cfg := &CollectorSetConfig{}
|
||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
@@ -101,10 +101,10 @@ func TestGetUpdateParams(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
current := collector.Collector{}
|
current := collector.Collector{}
|
||||||
params := UpdateParams{
|
params := SetParams{
|
||||||
ClientID: current.ClientID,
|
ClientID: current.ClientID,
|
||||||
}
|
}
|
||||||
_, err = svc.getUpdateParams(ctx, ¤t, ¶ms)
|
_, err = svc.getSetParams(ctx, ¤t, ¶ms)
|
||||||
assert.EqualError(t, err, "no changes")
|
assert.EqualError(t, err, "no changes")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ func TestGetUpdateParams(t *testing.T) {
|
|||||||
|
|
||||||
pool, err := pgxmock.NewPool()
|
pool, err := pgxmock.NewPool()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cfg := &CollectorUpdateConfig{}
|
cfg := &CollectorSetConfig{}
|
||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
@@ -127,11 +127,11 @@ func TestGetUpdateParams(t *testing.T) {
|
|||||||
LatestVersion: 4,
|
LatestVersion: 4,
|
||||||
}
|
}
|
||||||
version := int32(5)
|
version := int32(5)
|
||||||
params := UpdateParams{
|
params := SetParams{
|
||||||
ClientID: current.ClientID,
|
ClientID: current.ClientID,
|
||||||
ActiveVersion: &version,
|
ActiveVersion: &version,
|
||||||
}
|
}
|
||||||
_, err = svc.getUpdateParams(ctx, ¤t, ¶ms)
|
_, err = svc.getSetParams(ctx, ¤t, ¶ms)
|
||||||
assert.EqualError(t, err, "no changes")
|
assert.EqualError(t, err, "no changes")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ func TestGetUpdateParams(t *testing.T) {
|
|||||||
|
|
||||||
pool, err := pgxmock.NewPool()
|
pool, err := pgxmock.NewPool()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cfg := &CollectorUpdateConfig{}
|
cfg := &CollectorSetConfig{}
|
||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
@@ -154,25 +154,25 @@ func TestGetUpdateParams(t *testing.T) {
|
|||||||
"example": uuid.New(),
|
"example": uuid.New(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
params := UpdateParams{
|
params := SetParams{
|
||||||
ClientID: current.ClientID,
|
ClientID: current.ClientID,
|
||||||
Fields: &map[string]uuid.UUID{
|
Fields: &map[string]uuid.UUID{
|
||||||
"example": current.Fields["example"],
|
"example": current.Fields["example"],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err = svc.getUpdateParams(ctx, ¤t, ¶ms)
|
_, err = svc.getSetParams(ctx, ¤t, ¶ms)
|
||||||
assert.EqualError(t, err, "no changes")
|
assert.EqualError(t, err, "no changes")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSubmitUpdate(t *testing.T) {
|
func TestSubmitSet(t *testing.T) {
|
||||||
t.Run("all fields", func(t *testing.T) {
|
t.Run("all fields", func(t *testing.T) {
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
pool, err := pgxmock.NewPool()
|
pool, err := pgxmock.NewPool()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cfg := &CollectorUpdateConfig{}
|
cfg := &CollectorSetConfig{}
|
||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ func TestSubmitUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
aV := int32(2)
|
aV := int32(2)
|
||||||
params := dbUpdateParams{
|
params := dbSetParams{
|
||||||
ClientID: database.MustToDBUUID(current.ClientID),
|
ClientID: database.MustToDBUUID(current.ClientID),
|
||||||
ActiveVersion: &aV,
|
ActiveVersion: &aV,
|
||||||
MinCleanVersion: &minCleanV,
|
MinCleanVersion: &minCleanV,
|
||||||
@@ -231,7 +231,7 @@ func TestSubmitUpdate(t *testing.T) {
|
|||||||
WillReturnResult(pgxmock.NewResult("", 1))
|
WillReturnResult(pgxmock.NewResult("", 1))
|
||||||
pool.ExpectCommit()
|
pool.ExpectCommit()
|
||||||
|
|
||||||
err = svc.submitUpdate(ctx, ¤t, ¶ms)
|
err = svc.submitSet(ctx, ¤t, ¶ms)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
t.Run("only active version", func(t *testing.T) {
|
t.Run("only active version", func(t *testing.T) {
|
||||||
@@ -240,7 +240,7 @@ func TestSubmitUpdate(t *testing.T) {
|
|||||||
|
|
||||||
pool, err := pgxmock.NewPool()
|
pool, err := pgxmock.NewPool()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cfg := &CollectorUpdateConfig{}
|
cfg := &CollectorSetConfig{}
|
||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
@@ -258,7 +258,7 @@ func TestSubmitUpdate(t *testing.T) {
|
|||||||
Fields: map[string]uuid.UUID{},
|
Fields: map[string]uuid.UUID{},
|
||||||
}
|
}
|
||||||
av := int32(2)
|
av := int32(2)
|
||||||
params := dbUpdateParams{
|
params := dbSetParams{
|
||||||
ClientID: database.MustToDBUUID(current.ClientID),
|
ClientID: database.MustToDBUUID(current.ClientID),
|
||||||
ActiveVersion: &av,
|
ActiveVersion: &av,
|
||||||
}
|
}
|
||||||
@@ -268,7 +268,7 @@ func TestSubmitUpdate(t *testing.T) {
|
|||||||
WillReturnResult(pgxmock.NewResult("", 1))
|
WillReturnResult(pgxmock.NewResult("", 1))
|
||||||
pool.ExpectCommit()
|
pool.ExpectCommit()
|
||||||
|
|
||||||
err = svc.submitUpdate(ctx, ¤t, ¶ms)
|
err = svc.submitSet(ctx, ¤t, ¶ms)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -296,7 +296,7 @@ func TestNormalizeActiveVersion(t *testing.T) {
|
|||||||
ActiveVersion: 1,
|
ActiveVersion: 1,
|
||||||
LatestVersion: 4,
|
LatestVersion: 4,
|
||||||
}
|
}
|
||||||
update := UpdateParams{}
|
update := SetParams{}
|
||||||
err := svc.normalizeActiveVersion(¤t, &update)
|
err := svc.normalizeActiveVersion(¤t, &update)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Nil(t, update.ActiveVersion)
|
assert.Nil(t, update.ActiveVersion)
|
||||||
@@ -308,7 +308,7 @@ func TestNormalizeActiveVersion(t *testing.T) {
|
|||||||
ActiveVersion: version,
|
ActiveVersion: version,
|
||||||
LatestVersion: 4,
|
LatestVersion: 4,
|
||||||
}
|
}
|
||||||
update := UpdateParams{
|
update := SetParams{
|
||||||
ActiveVersion: &version,
|
ActiveVersion: &version,
|
||||||
}
|
}
|
||||||
err := svc.normalizeActiveVersion(¤t, &update)
|
err := svc.normalizeActiveVersion(¤t, &update)
|
||||||
@@ -322,7 +322,7 @@ func TestNormalizeActiveVersion(t *testing.T) {
|
|||||||
LatestVersion: 4,
|
LatestVersion: 4,
|
||||||
}
|
}
|
||||||
version := int32(5)
|
version := int32(5)
|
||||||
update := UpdateParams{
|
update := SetParams{
|
||||||
ActiveVersion: &version,
|
ActiveVersion: &version,
|
||||||
}
|
}
|
||||||
err := svc.normalizeActiveVersion(¤t, &update)
|
err := svc.normalizeActiveVersion(¤t, &update)
|
||||||
@@ -336,7 +336,7 @@ func TestNormalizeActiveVersion(t *testing.T) {
|
|||||||
LatestVersion: 4,
|
LatestVersion: 4,
|
||||||
}
|
}
|
||||||
version := int32(6)
|
version := int32(6)
|
||||||
update := UpdateParams{
|
update := SetParams{
|
||||||
ActiveVersion: &version,
|
ActiveVersion: &version,
|
||||||
}
|
}
|
||||||
err := svc.normalizeActiveVersion(¤t, &update)
|
err := svc.normalizeActiveVersion(¤t, &update)
|
||||||
@@ -345,7 +345,7 @@ func TestNormalizeActiveVersion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNormalizeCodeVersions(t *testing.T) {
|
func TestNormalizeCodeVersions(t *testing.T) {
|
||||||
cfg := &CollectorUpdateConfig{}
|
cfg := &CollectorSetConfig{}
|
||||||
svc := Service{
|
svc := Service{
|
||||||
svc: &Services{
|
svc: &Services{
|
||||||
CleanVersion: cleanversion.New(cfg),
|
CleanVersion: cleanversion.New(cfg),
|
||||||
@@ -366,7 +366,7 @@ func TestNormalizeCodeVersions(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("empty", func(t *testing.T) {
|
t.Run("empty", func(t *testing.T) {
|
||||||
current := collector.Collector{}
|
current := collector.Collector{}
|
||||||
update := UpdateParams{}
|
update := SetParams{}
|
||||||
|
|
||||||
err := svc.normalizeCodeVersions(¤t, &update)
|
err := svc.normalizeCodeVersions(¤t, &update)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@@ -376,7 +376,7 @@ func TestNormalizeCodeVersions(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("valid clean", func(t *testing.T) {
|
t.Run("valid clean", func(t *testing.T) {
|
||||||
current := collector.Collector{}
|
current := collector.Collector{}
|
||||||
update := UpdateParams{}
|
update := SetParams{}
|
||||||
|
|
||||||
cv := int32(1)
|
cv := int32(1)
|
||||||
update.MinCleanVersion = &cv
|
update.MinCleanVersion = &cv
|
||||||
@@ -388,7 +388,7 @@ func TestNormalizeCodeVersions(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("valid text", func(t *testing.T) {
|
t.Run("valid text", func(t *testing.T) {
|
||||||
current := collector.Collector{}
|
current := collector.Collector{}
|
||||||
update := UpdateParams{}
|
update := SetParams{}
|
||||||
|
|
||||||
tv := int32(1)
|
tv := int32(1)
|
||||||
update.MinTextVersion = &tv
|
update.MinTextVersion = &tv
|
||||||
@@ -400,7 +400,7 @@ func TestNormalizeCodeVersions(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("valid clean and text", func(t *testing.T) {
|
t.Run("valid clean and text", func(t *testing.T) {
|
||||||
current := collector.Collector{}
|
current := collector.Collector{}
|
||||||
update := UpdateParams{}
|
update := SetParams{}
|
||||||
|
|
||||||
current.MinCleanVersion = 1
|
current.MinCleanVersion = 1
|
||||||
current.MinTextVersion = 1
|
current.MinTextVersion = 1
|
||||||
@@ -414,7 +414,7 @@ func TestNormalizeCodeVersions(t *testing.T) {
|
|||||||
current := collector.Collector{
|
current := collector.Collector{
|
||||||
MinCleanVersion: 1,
|
MinCleanVersion: 1,
|
||||||
}
|
}
|
||||||
update := UpdateParams{}
|
update := SetParams{}
|
||||||
|
|
||||||
update.MinCleanVersion = ¤t.MinCleanVersion
|
update.MinCleanVersion = ¤t.MinCleanVersion
|
||||||
err := svc.normalizeCodeVersions(¤t, &update)
|
err := svc.normalizeCodeVersions(¤t, &update)
|
||||||
@@ -427,7 +427,7 @@ func TestNormalizeCodeVersions(t *testing.T) {
|
|||||||
current := collector.Collector{
|
current := collector.Collector{
|
||||||
MinTextVersion: 1,
|
MinTextVersion: 1,
|
||||||
}
|
}
|
||||||
update := UpdateParams{}
|
update := SetParams{}
|
||||||
|
|
||||||
update.MinTextVersion = ¤t.MinTextVersion
|
update.MinTextVersion = ¤t.MinTextVersion
|
||||||
err := svc.normalizeCodeVersions(¤t, &update)
|
err := svc.normalizeCodeVersions(¤t, &update)
|
||||||
@@ -441,7 +441,7 @@ func TestNormalizeCodeVersions(t *testing.T) {
|
|||||||
MinCleanVersion: 1,
|
MinCleanVersion: 1,
|
||||||
MinTextVersion: 1,
|
MinTextVersion: 1,
|
||||||
}
|
}
|
||||||
update := UpdateParams{}
|
update := SetParams{}
|
||||||
|
|
||||||
update.MinCleanVersion = ¤t.MinCleanVersion
|
update.MinCleanVersion = ¤t.MinCleanVersion
|
||||||
update.MinTextVersion = ¤t.MinTextVersion
|
update.MinTextVersion = ¤t.MinTextVersion
|
||||||
@@ -527,21 +527,21 @@ func TestGetAddFields(t *testing.T) {
|
|||||||
}, add)
|
}, add)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNormalizeUpdateFieldsToDB(t *testing.T) {
|
func TestNormalizeSetFieldsToDB(t *testing.T) {
|
||||||
t.Run("valid key", func(t *testing.T) {
|
t.Run("valid key", func(t *testing.T) {
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
pool, err := pgxmock.NewPool()
|
pool, err := pgxmock.NewPool()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cfg := &CollectorUpdateConfig{}
|
cfg := &CollectorSetConfig{}
|
||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
svc := Service{
|
svc := Service{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
svc: &Services{
|
svc: &Services{
|
||||||
Collector: collector.New(cfg, &collector.Services{}),
|
Collector: collector.New(cfg),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,7 +555,7 @@ func TestNormalizeUpdateFieldsToDB(t *testing.T) {
|
|||||||
AddRow(true),
|
AddRow(true),
|
||||||
)
|
)
|
||||||
|
|
||||||
dbparams, err := svc.normalizeUpdateFieldsToDB(ctx, current, &fields)
|
dbparams, err := svc.normalizeSetFieldsToDB(ctx, current, &fields)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualExportedValues(t, &map[string]pgtype.UUID{
|
assert.EqualExportedValues(t, &map[string]pgtype.UUID{
|
||||||
"example_key": database.MustToDBUUID(fields["example_key"]),
|
"example_key": database.MustToDBUUID(fields["example_key"]),
|
||||||
@@ -567,7 +567,7 @@ func TestNormalizeUpdateFieldsToDB(t *testing.T) {
|
|||||||
|
|
||||||
pool, err := pgxmock.NewPool()
|
pool, err := pgxmock.NewPool()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cfg := &CollectorUpdateConfig{}
|
cfg := &CollectorSetConfig{}
|
||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
@@ -587,17 +587,17 @@ func TestNormalizeUpdateFieldsToDB(t *testing.T) {
|
|||||||
AddRow(true),
|
AddRow(true),
|
||||||
)
|
)
|
||||||
|
|
||||||
_, err = svc.normalizeUpdateFieldsToDB(ctx, current, &fields)
|
_, err = svc.normalizeSetFieldsToDB(ctx, current, &fields)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
})
|
})
|
||||||
t.Run("no changes", func(t *testing.T) {
|
t.Run("no changes", func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
cfg := &CollectorUpdateConfig{}
|
cfg := &CollectorSetConfig{}
|
||||||
|
|
||||||
svc := Service{
|
svc := Service{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
svc: &Services{
|
svc: &Services{
|
||||||
Collector: collector.New(cfg, &collector.Services{}),
|
Collector: collector.New(cfg),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -608,19 +608,19 @@ func TestNormalizeUpdateFieldsToDB(t *testing.T) {
|
|||||||
"example_key": current["example_key"],
|
"example_key": current["example_key"],
|
||||||
}
|
}
|
||||||
|
|
||||||
val, err := svc.normalizeUpdateFieldsToDB(ctx, current, &fields)
|
val, err := svc.normalizeSetFieldsToDB(ctx, current, &fields)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Nil(t, val)
|
assert.Nil(t, val)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInformUpdate(t *testing.T) {
|
func TestInformSet(t *testing.T) {
|
||||||
t.Run("with version update", func(t *testing.T) {
|
t.Run("with version update", func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
pool, err := pgxmock.NewPool()
|
pool, err := pgxmock.NewPool()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cfg := &CollectorUpdateConfig{}
|
cfg := &CollectorSetConfig{}
|
||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
mockSQS := queuemock.NewMockSQSClient(t)
|
mockSQS := queuemock.NewMockSQSClient(t)
|
||||||
@@ -630,7 +630,7 @@ func TestInformUpdate(t *testing.T) {
|
|||||||
svc := New(cfg, &Services{})
|
svc := New(cfg, &Services{})
|
||||||
|
|
||||||
av := int32(2)
|
av := int32(2)
|
||||||
update := dbUpdateParams{
|
update := dbSetParams{
|
||||||
ClientID: database.MustToDBUUID(uuid.New()),
|
ClientID: database.MustToDBUUID(uuid.New()),
|
||||||
ActiveVersion: &av,
|
ActiveVersion: &av,
|
||||||
}
|
}
|
||||||
@@ -645,7 +645,7 @@ func TestInformUpdate(t *testing.T) {
|
|||||||
).
|
).
|
||||||
Return(&sqs.SendMessageOutput{}, nil)
|
Return(&sqs.SendMessageOutput{}, nil)
|
||||||
|
|
||||||
err = svc.informUpdate(ctx, &update)
|
err = svc.informSet(ctx, &update)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
t.Run("with no update", func(t *testing.T) {
|
t.Run("with no update", func(t *testing.T) {
|
||||||
@@ -653,7 +653,7 @@ func TestInformUpdate(t *testing.T) {
|
|||||||
|
|
||||||
pool, err := pgxmock.NewPool()
|
pool, err := pgxmock.NewPool()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cfg := &CollectorUpdateConfig{}
|
cfg := &CollectorSetConfig{}
|
||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
mockSQS := queuemock.NewMockSQSClient(t)
|
mockSQS := queuemock.NewMockSQSClient(t)
|
||||||
@@ -662,11 +662,51 @@ func TestInformUpdate(t *testing.T) {
|
|||||||
|
|
||||||
svc := New(cfg, &Services{})
|
svc := New(cfg, &Services{})
|
||||||
|
|
||||||
update := dbUpdateParams{
|
update := dbSetParams{
|
||||||
ClientID: database.MustToDBUUID(uuid.New()),
|
ClientID: database.MustToDBUUID(uuid.New()),
|
||||||
}
|
}
|
||||||
|
|
||||||
err = svc.informUpdate(ctx, &update)
|
err = svc.informSet(ctx, &update)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNormalizeFieldsToDB(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
pool, err := pgxmock.NewPool()
|
||||||
|
require.NoError(t, err)
|
||||||
|
cfg := &CollectorSetConfig{}
|
||||||
|
cfg.DBPool = pool
|
||||||
|
cfg.DBQueries = repository.New(pool)
|
||||||
|
|
||||||
|
svc := Service{
|
||||||
|
cfg: cfg,
|
||||||
|
svc: &Services{},
|
||||||
|
}
|
||||||
|
|
||||||
|
fields := map[string]uuid.UUID{
|
||||||
|
"example_key": uuid.New(),
|
||||||
|
}
|
||||||
|
|
||||||
|
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(database.MustToDBUUIDArray([]uuid.UUID{fields["example_key"]})).WillReturnRows(
|
||||||
|
pgxmock.NewRows([]string{"all_exist"}).
|
||||||
|
AddRow(true),
|
||||||
|
)
|
||||||
|
|
||||||
|
dbparams, err := svc.normalizeFieldsToDB(ctx, &fields)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualExportedValues(t, &map[string]pgtype.UUID{
|
||||||
|
"example_key": database.MustToDBUUID(fields["example_key"]),
|
||||||
|
}, dbparams)
|
||||||
|
|
||||||
|
fields["second_key"] = fields["example_key"]
|
||||||
|
|
||||||
|
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(database.MustToDBUUIDArray([]uuid.UUID{fields["example_key"]})).WillReturnRows(
|
||||||
|
pgxmock.NewRows([]string{"all_exist"}).
|
||||||
|
AddRow(true),
|
||||||
|
)
|
||||||
|
|
||||||
|
_, err = svc.normalizeFieldsToDB(ctx, &fields)
|
||||||
|
assert.Error(t, err)
|
||||||
|
}
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
package collectorupdate_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"queryorchestration/internal/collector"
|
|
||||||
collectorupdate "queryorchestration/internal/collector/update"
|
|
||||||
"queryorchestration/internal/database"
|
|
||||||
"queryorchestration/internal/database/repository"
|
|
||||||
"queryorchestration/internal/serviceconfig"
|
|
||||||
"queryorchestration/internal/serviceconfig/queue/clientsync"
|
|
||||||
queuemock "queryorchestration/mocks/queue"
|
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/jackc/pgx/v5"
|
|
||||||
"github.com/pashagolub/pgxmock/v3"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/mock"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CollectorUpdateConfig struct {
|
|
||||||
serviceconfig.BaseConfig
|
|
||||||
clientsync.ClientSyncConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
pool, err := pgxmock.NewPool()
|
|
||||||
require.NoError(t, err)
|
|
||||||
cfg := &CollectorUpdateConfig{}
|
|
||||||
cfg.DBPool = pool
|
|
||||||
cfg.DBQueries = repository.New(pool)
|
|
||||||
mockSQS := queuemock.NewMockSQSClient(t)
|
|
||||||
cfg.QueueClient = mockSQS
|
|
||||||
cfg.ClientSyncURL = "here"
|
|
||||||
|
|
||||||
svc := collectorupdate.New(cfg, &collectorupdate.Services{
|
|
||||||
Collector: collector.New(cfg, &collector.Services{}),
|
|
||||||
})
|
|
||||||
|
|
||||||
current := collector.Collector{
|
|
||||||
ClientID: uuid.New(),
|
|
||||||
ActiveVersion: 1,
|
|
||||||
LatestVersion: 4,
|
|
||||||
}
|
|
||||||
av := int32(2)
|
|
||||||
mv := int32(1)
|
|
||||||
update := collectorupdate.UpdateParams{
|
|
||||||
ClientID: current.ClientID,
|
|
||||||
ActiveVersion: &av,
|
|
||||||
MinCleanVersion: &mv,
|
|
||||||
}
|
|
||||||
|
|
||||||
pool.ExpectQuery("name: GetCollectorByClientID :one").WithArgs(database.MustToDBUUID(update.ClientID)).
|
|
||||||
WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"clientId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
|
|
||||||
AddRow(database.MustToDBUUID(current.ClientID), current.MinCleanVersion, current.MinTextVersion, current.ActiveVersion, current.LatestVersion, []byte("")),
|
|
||||||
)
|
|
||||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
|
||||||
rv := current.LatestVersion + 1
|
|
||||||
pool.ExpectQuery("name: AddLatestCollectorVersion :one").WithArgs(database.MustToDBUUID(current.ClientID)).WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"version"}).
|
|
||||||
AddRow(rv),
|
|
||||||
)
|
|
||||||
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), int32(2)).
|
|
||||||
WillReturnResult(pgxmock.NewResult("", 1))
|
|
||||||
pool.ExpectExec("name: SetCollectorCleanVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), rv, *update.MinCleanVersion).
|
|
||||||
WillReturnResult(pgxmock.NewResult("", 1))
|
|
||||||
pool.ExpectCommit()
|
|
||||||
|
|
||||||
mockSQS.EXPECT().
|
|
||||||
SendMessage(
|
|
||||||
mock.Anything,
|
|
||||||
mock.MatchedBy(func(in *sqs.SendMessageInput) bool {
|
|
||||||
return *in.QueueUrl == cfg.ClientSyncURL && *in.MessageBody == fmt.Sprintf("{\"id\":\"%s\"}", update.ClientID.String())
|
|
||||||
}),
|
|
||||||
mock.Anything,
|
|
||||||
).
|
|
||||||
Return(&sqs.SendMessageOutput{}, nil)
|
|
||||||
|
|
||||||
err = svc.UpdateByClientId(ctx, &update)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
}
|
|
||||||
@@ -35,7 +35,7 @@ func TestSync(t *testing.T) {
|
|||||||
|
|
||||||
svc := documentsync.New(cfg, &documentsync.Services{
|
svc := documentsync.New(cfg, &documentsync.Services{
|
||||||
Document: document.New(cfg),
|
Document: document.New(cfg),
|
||||||
Client: client.New(cfg, &client.Services{}),
|
Client: client.New(cfg),
|
||||||
})
|
})
|
||||||
|
|
||||||
j := client.Client{
|
j := client.Client{
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import (
|
|||||||
"queryorchestration/internal/database"
|
"queryorchestration/internal/database"
|
||||||
"queryorchestration/internal/database/repository"
|
"queryorchestration/internal/database/repository"
|
||||||
"queryorchestration/internal/document"
|
"queryorchestration/internal/document"
|
||||||
cleanversion "queryorchestration/internal/document/clean/version"
|
|
||||||
textversion "queryorchestration/internal/document/text/version"
|
|
||||||
"queryorchestration/internal/query"
|
"queryorchestration/internal/query"
|
||||||
"queryorchestration/internal/query/result"
|
"queryorchestration/internal/query/result"
|
||||||
querytest "queryorchestration/internal/query/test"
|
querytest "queryorchestration/internal/query/test"
|
||||||
@@ -31,10 +29,7 @@ func TestTest(t *testing.T) {
|
|||||||
cfg := &serviceconfig.BaseConfig{}
|
cfg := &serviceconfig.BaseConfig{}
|
||||||
cfg.DBPool = pool
|
cfg.DBPool = pool
|
||||||
cfg.DBQueries = repository.New(pool)
|
cfg.DBQueries = repository.New(pool)
|
||||||
col := collector.New(cfg, &collector.Services{
|
col := collector.New(cfg)
|
||||||
TextVersion: textversion.New(cfg),
|
|
||||||
CleanVersion: cleanversion.New(cfg),
|
|
||||||
})
|
|
||||||
docsvc := document.New(cfg)
|
docsvc := document.New(cfg)
|
||||||
svc := querytest.New(cfg, &querytest.Services{
|
svc := querytest.New(cfg, &querytest.Services{
|
||||||
Document: docsvc,
|
Document: docsvc,
|
||||||
|
|||||||
+32
-32
@@ -106,8 +106,8 @@ type CollectorField struct {
|
|||||||
QueryId openapi_types.UUID `json:"query_id"`
|
QueryId openapi_types.UUID `json:"query_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CollectorUpdate Payload for updating a Collector.
|
// CollectorSet Payload for updating a Collector.
|
||||||
type CollectorUpdate struct {
|
type CollectorSet struct {
|
||||||
// ActiveVersion The active version of the collector.
|
// ActiveVersion The active version of the collector.
|
||||||
ActiveVersion *int32 `json:"active_version,omitempty"`
|
ActiveVersion *int32 `json:"active_version,omitempty"`
|
||||||
|
|
||||||
@@ -274,8 +274,8 @@ type CreateClientJSONRequestBody = ClientCreate
|
|||||||
// UpdateClientJSONRequestBody defines body for UpdateClient for application/json ContentType.
|
// UpdateClientJSONRequestBody defines body for UpdateClient for application/json ContentType.
|
||||||
type UpdateClientJSONRequestBody = ClientUpdate
|
type UpdateClientJSONRequestBody = ClientUpdate
|
||||||
|
|
||||||
// UpdateCollectorByClientIdJSONRequestBody defines body for UpdateCollectorByClientId for application/json ContentType.
|
// SetCollectorByClientIdJSONRequestBody defines body for SetCollectorByClientId for application/json ContentType.
|
||||||
type UpdateCollectorByClientIdJSONRequestBody = CollectorUpdate
|
type SetCollectorByClientIdJSONRequestBody = CollectorSet
|
||||||
|
|
||||||
// TriggerExportJSONRequestBody defines body for TriggerExport for application/json ContentType.
|
// TriggerExportJSONRequestBody defines body for TriggerExport for application/json ContentType.
|
||||||
type TriggerExportJSONRequestBody = ExportTrigger
|
type TriggerExportJSONRequestBody = ExportTrigger
|
||||||
@@ -378,10 +378,10 @@ type ClientInterface interface {
|
|||||||
// GetCollectorByClientId request
|
// GetCollectorByClientId request
|
||||||
GetCollectorByClientId(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error)
|
GetCollectorByClientId(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error)
|
||||||
|
|
||||||
// UpdateCollectorByClientIdWithBody request with any body
|
// SetCollectorByClientIdWithBody request with any body
|
||||||
UpdateCollectorByClientIdWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
|
SetCollectorByClientIdWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
|
||||||
|
|
||||||
UpdateCollectorByClientId(ctx context.Context, id openapi_types.UUID, body UpdateCollectorByClientIdJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
|
SetCollectorByClientId(ctx context.Context, id openapi_types.UUID, body SetCollectorByClientIdJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
|
||||||
|
|
||||||
// ListDocumentsByClientId request
|
// ListDocumentsByClientId request
|
||||||
ListDocumentsByClientId(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error)
|
ListDocumentsByClientId(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error)
|
||||||
@@ -491,8 +491,8 @@ func (c *Client) GetCollectorByClientId(ctx context.Context, id openapi_types.UU
|
|||||||
return c.Client.Do(req)
|
return c.Client.Do(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) UpdateCollectorByClientIdWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
func (c *Client) SetCollectorByClientIdWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
||||||
req, err := NewUpdateCollectorByClientIdRequestWithBody(c.Server, id, contentType, body)
|
req, err := NewSetCollectorByClientIdRequestWithBody(c.Server, id, contentType, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -503,8 +503,8 @@ func (c *Client) UpdateCollectorByClientIdWithBody(ctx context.Context, id opena
|
|||||||
return c.Client.Do(req)
|
return c.Client.Do(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) UpdateCollectorByClientId(ctx context.Context, id openapi_types.UUID, body UpdateCollectorByClientIdJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
func (c *Client) SetCollectorByClientId(ctx context.Context, id openapi_types.UUID, body SetCollectorByClientIdJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
||||||
req, err := NewUpdateCollectorByClientIdRequest(c.Server, id, body)
|
req, err := NewSetCollectorByClientIdRequest(c.Server, id, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -826,19 +826,19 @@ func NewGetCollectorByClientIdRequest(server string, id openapi_types.UUID) (*ht
|
|||||||
return req, nil
|
return req, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUpdateCollectorByClientIdRequest calls the generic UpdateCollectorByClientId builder with application/json body
|
// NewSetCollectorByClientIdRequest calls the generic SetCollectorByClientId builder with application/json body
|
||||||
func NewUpdateCollectorByClientIdRequest(server string, id openapi_types.UUID, body UpdateCollectorByClientIdJSONRequestBody) (*http.Request, error) {
|
func NewSetCollectorByClientIdRequest(server string, id openapi_types.UUID, body SetCollectorByClientIdJSONRequestBody) (*http.Request, error) {
|
||||||
var bodyReader io.Reader
|
var bodyReader io.Reader
|
||||||
buf, err := json.Marshal(body)
|
buf, err := json.Marshal(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
bodyReader = bytes.NewReader(buf)
|
bodyReader = bytes.NewReader(buf)
|
||||||
return NewUpdateCollectorByClientIdRequestWithBody(server, id, "application/json", bodyReader)
|
return NewSetCollectorByClientIdRequestWithBody(server, id, "application/json", bodyReader)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUpdateCollectorByClientIdRequestWithBody generates requests for UpdateCollectorByClientId with any type of body
|
// NewSetCollectorByClientIdRequestWithBody generates requests for SetCollectorByClientId with any type of body
|
||||||
func NewUpdateCollectorByClientIdRequestWithBody(server string, id openapi_types.UUID, contentType string, body io.Reader) (*http.Request, error) {
|
func NewSetCollectorByClientIdRequestWithBody(server string, id openapi_types.UUID, contentType string, body io.Reader) (*http.Request, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
var pathParam0 string
|
var pathParam0 string
|
||||||
@@ -1276,10 +1276,10 @@ type ClientWithResponsesInterface interface {
|
|||||||
// GetCollectorByClientIdWithResponse request
|
// GetCollectorByClientIdWithResponse request
|
||||||
GetCollectorByClientIdWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*GetCollectorByClientIdResponse, error)
|
GetCollectorByClientIdWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*GetCollectorByClientIdResponse, error)
|
||||||
|
|
||||||
// UpdateCollectorByClientIdWithBodyWithResponse request with any body
|
// SetCollectorByClientIdWithBodyWithResponse request with any body
|
||||||
UpdateCollectorByClientIdWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateCollectorByClientIdResponse, error)
|
SetCollectorByClientIdWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SetCollectorByClientIdResponse, error)
|
||||||
|
|
||||||
UpdateCollectorByClientIdWithResponse(ctx context.Context, id openapi_types.UUID, body UpdateCollectorByClientIdJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateCollectorByClientIdResponse, error)
|
SetCollectorByClientIdWithResponse(ctx context.Context, id openapi_types.UUID, body SetCollectorByClientIdJSONRequestBody, reqEditors ...RequestEditorFn) (*SetCollectorByClientIdResponse, error)
|
||||||
|
|
||||||
// ListDocumentsByClientIdWithResponse request
|
// ListDocumentsByClientIdWithResponse request
|
||||||
ListDocumentsByClientIdWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*ListDocumentsByClientIdResponse, error)
|
ListDocumentsByClientIdWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*ListDocumentsByClientIdResponse, error)
|
||||||
@@ -1404,13 +1404,13 @@ func (r GetCollectorByClientIdResponse) StatusCode() int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateCollectorByClientIdResponse struct {
|
type SetCollectorByClientIdResponse struct {
|
||||||
Body []byte
|
Body []byte
|
||||||
HTTPResponse *http.Response
|
HTTPResponse *http.Response
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status returns HTTPResponse.Status
|
// Status returns HTTPResponse.Status
|
||||||
func (r UpdateCollectorByClientIdResponse) Status() string {
|
func (r SetCollectorByClientIdResponse) Status() string {
|
||||||
if r.HTTPResponse != nil {
|
if r.HTTPResponse != nil {
|
||||||
return r.HTTPResponse.Status
|
return r.HTTPResponse.Status
|
||||||
}
|
}
|
||||||
@@ -1418,7 +1418,7 @@ func (r UpdateCollectorByClientIdResponse) Status() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StatusCode returns HTTPResponse.StatusCode
|
// StatusCode returns HTTPResponse.StatusCode
|
||||||
func (r UpdateCollectorByClientIdResponse) StatusCode() int {
|
func (r SetCollectorByClientIdResponse) StatusCode() int {
|
||||||
if r.HTTPResponse != nil {
|
if r.HTTPResponse != nil {
|
||||||
return r.HTTPResponse.StatusCode
|
return r.HTTPResponse.StatusCode
|
||||||
}
|
}
|
||||||
@@ -1674,21 +1674,21 @@ func (c *ClientWithResponses) GetCollectorByClientIdWithResponse(ctx context.Con
|
|||||||
return ParseGetCollectorByClientIdResponse(rsp)
|
return ParseGetCollectorByClientIdResponse(rsp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateCollectorByClientIdWithBodyWithResponse request with arbitrary body returning *UpdateCollectorByClientIdResponse
|
// SetCollectorByClientIdWithBodyWithResponse request with arbitrary body returning *SetCollectorByClientIdResponse
|
||||||
func (c *ClientWithResponses) UpdateCollectorByClientIdWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateCollectorByClientIdResponse, error) {
|
func (c *ClientWithResponses) SetCollectorByClientIdWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SetCollectorByClientIdResponse, error) {
|
||||||
rsp, err := c.UpdateCollectorByClientIdWithBody(ctx, id, contentType, body, reqEditors...)
|
rsp, err := c.SetCollectorByClientIdWithBody(ctx, id, contentType, body, reqEditors...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return ParseUpdateCollectorByClientIdResponse(rsp)
|
return ParseSetCollectorByClientIdResponse(rsp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientWithResponses) UpdateCollectorByClientIdWithResponse(ctx context.Context, id openapi_types.UUID, body UpdateCollectorByClientIdJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateCollectorByClientIdResponse, error) {
|
func (c *ClientWithResponses) SetCollectorByClientIdWithResponse(ctx context.Context, id openapi_types.UUID, body SetCollectorByClientIdJSONRequestBody, reqEditors ...RequestEditorFn) (*SetCollectorByClientIdResponse, error) {
|
||||||
rsp, err := c.UpdateCollectorByClientId(ctx, id, body, reqEditors...)
|
rsp, err := c.SetCollectorByClientId(ctx, id, body, reqEditors...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return ParseUpdateCollectorByClientIdResponse(rsp)
|
return ParseSetCollectorByClientIdResponse(rsp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListDocumentsByClientIdWithResponse request returning *ListDocumentsByClientIdResponse
|
// ListDocumentsByClientIdWithResponse request returning *ListDocumentsByClientIdResponse
|
||||||
@@ -1898,15 +1898,15 @@ func ParseGetCollectorByClientIdResponse(rsp *http.Response) (*GetCollectorByCli
|
|||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseUpdateCollectorByClientIdResponse parses an HTTP response from a UpdateCollectorByClientIdWithResponse call
|
// ParseSetCollectorByClientIdResponse parses an HTTP response from a SetCollectorByClientIdWithResponse call
|
||||||
func ParseUpdateCollectorByClientIdResponse(rsp *http.Response) (*UpdateCollectorByClientIdResponse, error) {
|
func ParseSetCollectorByClientIdResponse(rsp *http.Response) (*SetCollectorByClientIdResponse, error) {
|
||||||
bodyBytes, err := io.ReadAll(rsp.Body)
|
bodyBytes, err := io.ReadAll(rsp.Body)
|
||||||
defer func() { _ = rsp.Body.Close() }()
|
defer func() { _ = rsp.Body.Close() }()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response := &UpdateCollectorByClientIdResponse{
|
response := &SetCollectorByClientIdResponse{
|
||||||
Body: bodyBytes,
|
Body: bodyBytes,
|
||||||
HTTPResponse: rsp,
|
HTTPResponse: rsp,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -246,20 +246,20 @@ paths:
|
|||||||
"400":
|
"400":
|
||||||
description: Invalid body.
|
description: Invalid body.
|
||||||
patch:
|
patch:
|
||||||
operationId: updateCollectorByClientId
|
operationId: setCollectorByClientId
|
||||||
tags:
|
tags:
|
||||||
- CollectorService
|
- CollectorService
|
||||||
summary: Update a collector
|
summary: Set a collector
|
||||||
description: Updates an existing collector with new details.
|
description: Set client collector with new details.
|
||||||
requestBody:
|
requestBody:
|
||||||
required: true
|
required: true
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/CollectorUpdate"
|
$ref: "#/components/schemas/CollectorSet"
|
||||||
responses:
|
responses:
|
||||||
"204":
|
"204":
|
||||||
description: Collector updated successfully.
|
description: Collector set successfully.
|
||||||
"400":
|
"400":
|
||||||
description: Invalid request body.
|
description: Invalid request body.
|
||||||
|
|
||||||
@@ -573,7 +573,7 @@ components:
|
|||||||
- latest_version
|
- latest_version
|
||||||
- active_version
|
- active_version
|
||||||
|
|
||||||
CollectorUpdate:
|
CollectorSet:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
minimum_cleaner_version:
|
minimum_cleaner_version:
|
||||||
|
|||||||
@@ -174,8 +174,8 @@ func TestProcess(t *testing.T) {
|
|||||||
RequiredQueries: &[]types.UUID{contextQueryRes.JSON201.Id},
|
RequiredQueries: &[]types.UUID{contextQueryRes.JSON201.Id},
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
newActiveVersion := int32(2)
|
newActiveVersion := int32(1)
|
||||||
_, err = qService.UpdateCollectorByClientIdWithResponse(ctx, clientRes.JSON201.Id, queryservice.CollectorUpdate{
|
_, err = qService.SetCollectorByClientIdWithResponse(ctx, clientRes.JSON201.Id, queryservice.CollectorSet{
|
||||||
ActiveVersion: &newActiveVersion,
|
ActiveVersion: &newActiveVersion,
|
||||||
Fields: &[]queryservice.CollectorField{
|
Fields: &[]queryservice.CollectorField{
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -80,20 +80,20 @@ func TestCollectorService(t *testing.T) {
|
|||||||
collRes, err := client.GetCollectorByClientIdWithResponse(ctx, id)
|
collRes, err := client.GetCollectorByClientIdWithResponse(ctx, id)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, id, collRes.JSON200.ClientId)
|
assert.Equal(t, id, collRes.JSON200.ClientId)
|
||||||
assert.Equal(t, int32(1), collRes.JSON200.ActiveVersion)
|
assert.Equal(t, int32(0), collRes.JSON200.ActiveVersion)
|
||||||
assert.Equal(t, int32(1), collRes.JSON200.LatestVersion)
|
assert.Equal(t, int32(0), collRes.JSON200.LatestVersion)
|
||||||
assert.Equal(t, int32(0), collRes.JSON200.MinimumCleanerVersion)
|
assert.Equal(t, int32(0), collRes.JSON200.MinimumCleanerVersion)
|
||||||
assert.Equal(t, int32(0), collRes.JSON200.MinimumTextVersion)
|
assert.Equal(t, int32(0), collRes.JSON200.MinimumTextVersion)
|
||||||
assert.Len(t, collRes.JSON200.Fields, 0)
|
assert.Len(t, collRes.JSON200.Fields, 0)
|
||||||
|
|
||||||
av := int32(2)
|
av := int32(1)
|
||||||
fields := []queryservice.CollectorField{
|
fields := []queryservice.CollectorField{
|
||||||
{
|
{
|
||||||
Name: "json",
|
Name: "json",
|
||||||
QueryId: jsonRes.JSON201.Id,
|
QueryId: jsonRes.JSON201.Id,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
uRes, err := client.UpdateCollectorByClientIdWithResponse(ctx, id, queryservice.CollectorUpdate{
|
uRes, err := client.SetCollectorByClientIdWithResponse(ctx, id, queryservice.CollectorSet{
|
||||||
ActiveVersion: &av,
|
ActiveVersion: &av,
|
||||||
Fields: &fields,
|
Fields: &fields,
|
||||||
})
|
})
|
||||||
@@ -106,8 +106,8 @@ func TestCollectorService(t *testing.T) {
|
|||||||
collRes, err = client.GetCollectorByClientIdWithResponse(ctx, id)
|
collRes, err = client.GetCollectorByClientIdWithResponse(ctx, id)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, id, collRes.JSON200.ClientId)
|
assert.Equal(t, id, collRes.JSON200.ClientId)
|
||||||
assert.Equal(t, int32(2), collRes.JSON200.ActiveVersion)
|
assert.Equal(t, int32(1), collRes.JSON200.ActiveVersion)
|
||||||
assert.Equal(t, int32(2), collRes.JSON200.LatestVersion)
|
assert.Equal(t, int32(1), collRes.JSON200.LatestVersion)
|
||||||
assert.Equal(t, int32(0), collRes.JSON200.MinimumCleanerVersion)
|
assert.Equal(t, int32(0), collRes.JSON200.MinimumCleanerVersion)
|
||||||
assert.Equal(t, int32(0), collRes.JSON200.MinimumTextVersion)
|
assert.Equal(t, int32(0), collRes.JSON200.MinimumTextVersion)
|
||||||
assert.Len(t, collRes.JSON200.Fields, 1)
|
assert.Len(t, collRes.JSON200.Fields, 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user