@@ -46,7 +46,7 @@ func TestDocInitRunner(t *testing.T) {
|
||||
runner := docsyncrunner.New(validator.New(), &docsyncrunner.Services{
|
||||
Document: documentsync.New(cfg, &documentsync.Services{
|
||||
Document: document.New(cfg),
|
||||
Client: client.New(cfg, &client.Services{}),
|
||||
Client: client.New(cfg),
|
||||
}),
|
||||
})
|
||||
assert.NotNil(t, runner)
|
||||
|
||||
+51
-51
@@ -108,8 +108,8 @@ type CollectorField struct {
|
||||
QueryId openapi_types.UUID `json:"query_id"`
|
||||
}
|
||||
|
||||
// CollectorUpdate Payload for updating a Collector.
|
||||
type CollectorUpdate struct {
|
||||
// CollectorSet Payload for updating a Collector.
|
||||
type CollectorSet struct {
|
||||
// ActiveVersion The active version of the collector.
|
||||
ActiveVersion *int32 `json:"active_version,omitempty"`
|
||||
|
||||
@@ -276,8 +276,8 @@ type CreateClientJSONRequestBody = ClientCreate
|
||||
// UpdateClientJSONRequestBody defines body for UpdateClient for application/json ContentType.
|
||||
type UpdateClientJSONRequestBody = ClientUpdate
|
||||
|
||||
// UpdateCollectorByClientIdJSONRequestBody defines body for UpdateCollectorByClientId for application/json ContentType.
|
||||
type UpdateCollectorByClientIdJSONRequestBody = CollectorUpdate
|
||||
// SetCollectorByClientIdJSONRequestBody defines body for SetCollectorByClientId for application/json ContentType.
|
||||
type SetCollectorByClientIdJSONRequestBody = CollectorSet
|
||||
|
||||
// TriggerExportJSONRequestBody defines body for TriggerExport for application/json ContentType.
|
||||
type TriggerExportJSONRequestBody = ExportTrigger
|
||||
@@ -305,9 +305,9 @@ type ServerInterface interface {
|
||||
// Get a collector by client ID
|
||||
// (GET /client/{id}/collector)
|
||||
GetCollectorByClientId(ctx echo.Context, id openapi_types.UUID) error
|
||||
// Update a collector
|
||||
// Set a 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
|
||||
// (GET /client/{id}/documents)
|
||||
ListDocumentsByClientId(ctx echo.Context, id openapi_types.UUID) error
|
||||
@@ -399,8 +399,8 @@ func (w *ServerInterfaceWrapper) GetCollectorByClientId(ctx echo.Context) error
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateCollectorByClientId converts echo context to params.
|
||||
func (w *ServerInterfaceWrapper) UpdateCollectorByClientId(ctx echo.Context) error {
|
||||
// SetCollectorByClientId converts echo context to params.
|
||||
func (w *ServerInterfaceWrapper) SetCollectorByClientId(ctx echo.Context) error {
|
||||
var err error
|
||||
// ------------- Path parameter "id" -------------
|
||||
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
|
||||
err = w.Handler.UpdateCollectorByClientId(ctx, id)
|
||||
err = w.Handler.SetCollectorByClientId(ctx, id)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -577,7 +577,7 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL
|
||||
router.GET(baseURL+"/client/:id", wrapper.GetClient)
|
||||
router.PATCH(baseURL+"/client/:id", wrapper.UpdateClient)
|
||||
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/export", wrapper.ExportState)
|
||||
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
|
||||
var swaggerSpec = []string{
|
||||
|
||||
"H4sIAAAAAAAC/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x4membdY9eWcp",
|
||||
"KF27wTZDpX/NExrjP/rGWgndHrfVs0fsK/tIzv9nvJe+KLJGuhjs/TTAiCbz6ycgucvmdoIoc+7+pact",
|
||||
"r9c/t9orlUHps8OkOjjtj5VT8/eDyEgemloz+u/eX1Uf24nuQdiZPSA3cYB9kSLNSZhNgUwGSS5ZMk5W",
|
||||
"WmdqPBrhjA79F5tDItajzbvEoMVz26d3W/hbua9PIUVa+JJPlWitl427QU8yRZOnSmm/8dOXWNkOCrQa",
|
||||
"zYq+tMpSyVOq+aAvFXfJqVCpX3J297v/BgAA//8NIKB+FzgAAA==",
|
||||
"H4sIAAAAAAAC/+RbX2/juBH/KoTaR8PO3d6T3/aS7MLFNtkm3uKKa2DQ1NjmLU0qJOXEDfzdC/4RJVmU",
|
||||
"rDh2bou+RRY5f38zHM4oLwkR60xw4Fol45dEkRWssf3zklHg+lIC1mCeMykykJqCfcvx2v6agiKSZpoK",
|
||||
"noyT6QoQsfuQXTBI9DaDZJwoLSlfJrvdIJHwmFMJaTL+3VF5CKvE/A8gOtkNPPN7jXWummzuMyB0QUEh",
|
||||
"vQKk7CokFgh75sNkkADP14bF5GZ2/6+by2SQ3NxO7Z/XV5WHyc3nigCFmHUBfhXptmkBx2pG004z0DQZ",
|
||||
"JAsh11gn4yTP7XODmwqK/lXCIhknfxmVfhl5p4xqRtk3ZSlOINdu2G9ZGvUqwXymtpw0VZosrK0LrRTC",
|
||||
"jIknypcIE003gMw2Veo2F4IB5obl8VBpSi8YA6KFbNILr9BapMAMBOq6OTlnG5DK7ogJ5HXxawykrNIF",
|
||||
"6WHVl5TrDz+XYlOuYQnSSHkAGZOrgjBWShCKNaQV4B4Ey4ICS1WctnuHKG8KTjWsD0Os2PHJEEpKH2Ap",
|
||||
"8dY8M6xB6W4zujVvNeOacrrO1zNigASym6VfHHguhLRMU0HytQGZp/JK3hqe9XGMzU6UYal68uwIZ+/w",
|
||||
"dou0yNtw1mA/CB66YsxBoB1mqIyvoHXNx31PDJH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GZ4rZfbC4iUgrUi5XQL47mJBcSiOs",
|
||||
"neHYj9qq85Q6PMrJEJwTEvXxYgQSbgFaYYXmAByFadNx+dtaozbLGlYg4JU+rpoqLXmeRB29Ek041dSW",
|
||||
"UJXJZSaFyWJNp/p5m1PzTFm5Ptn7ka5A17X59EkrMa9uGVAdoNqP33La2yPTqy0nxVepvWow/5np+xRg",
|
||||
"+x+2tqd4r8KJr0neFBUjve2qFL5EOGMqfywGHAfLcFYfwlRH2HaITCTVICmOn/XF0OfM53vBJuL6j/sa",
|
||||
"nMLt9nx/DLoVzrY9qZqve3SUXO/t1Q0lN6I6TzatziB+pFzqen5n7iY9esO2ODVEzxGtJOfq7k5S6dcz",
|
||||
"xYufjrZZ9+Q9pKB07a7aDJX+NU9ogf/ZTaNK6PboGZ09Yt/YMXL+P2PD6FWRNdLFCO+HAUY0mV8/A8ld",
|
||||
"NrezQplz9587bXm9/mHVXqkMSp8dJtURaX+snJq/HzlG8tDUmtF/3v6m+tjObg/CzuwBuYkD7KsUaU7C",
|
||||
"FApkMkhyyZJxstI6U+PRCGd06L/NHBKxHm1+SgxaPLd9ereFv5X7zhRSpIUv+VSJ1nrZuBv0JFM0eaqU",
|
||||
"9hs/fYmV7aBAq9Gs6EurLJU8pZoP+lJxl5wKlfolZ/ew+28AAAD//9G30tr+NwAA",
|
||||
}
|
||||
|
||||
// GetSwagger returns the content of the embedded swagger specification file
|
||||
|
||||
@@ -10,16 +10,12 @@ import (
|
||||
|
||||
queryservice "queryorchestration/api/queryService"
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/collector"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
cleanversion "queryorchestration/internal/document/clean/version"
|
||||
textversion "queryorchestration/internal/document/text/version"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -35,12 +31,7 @@ func TestCreateClient(t *testing.T) {
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Client: client.New(cfg, &client.Services{
|
||||
Collector: collector.New(cfg, &collector.Services{
|
||||
TextVersion: textversion.New(cfg),
|
||||
CleanVersion: cleanversion.New(cfg),
|
||||
}),
|
||||
}),
|
||||
Client: client.New(cfg),
|
||||
})
|
||||
|
||||
body := queryservice.ClientCreate{
|
||||
@@ -61,14 +52,6 @@ func TestCreateClient(t *testing.T) {
|
||||
pgxmock.NewRows([]string{"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)
|
||||
assert.NoError(t, err)
|
||||
@@ -85,12 +68,7 @@ func TestGetClient(t *testing.T) {
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Client: client.New(cfg, &client.Services{
|
||||
Collector: collector.New(cfg, &collector.Services{
|
||||
TextVersion: textversion.New(cfg),
|
||||
CleanVersion: cleanversion.New(cfg),
|
||||
}),
|
||||
}),
|
||||
Client: client.New(cfg),
|
||||
})
|
||||
|
||||
e := echo.New()
|
||||
@@ -130,12 +108,7 @@ func TestUpdateClient(t *testing.T) {
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Client: client.New(cfg, &client.Services{
|
||||
Collector: collector.New(cfg, &collector.Services{
|
||||
TextVersion: textversion.New(cfg),
|
||||
CleanVersion: cleanversion.New(cfg),
|
||||
}),
|
||||
}),
|
||||
Client: client.New(cfg),
|
||||
})
|
||||
|
||||
cs := false
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
collectorupdate "queryorchestration/internal/collector/update"
|
||||
collectorset "queryorchestration/internal/collector/set"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"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 {
|
||||
req := CollectorUpdate{}
|
||||
func (s *Controllers) SetCollectorByClientId(ctx echo.Context, clientId types.UUID) error {
|
||||
req := CollectorSet{}
|
||||
if err := ctx.Bind(&req); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err)
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func (s *Controllers) UpdateCollectorByClientId(ctx echo.Context, clientId types
|
||||
fields = &fs
|
||||
}
|
||||
|
||||
err := s.svc.CollectorUpdate.UpdateByClientId(ctx.Request().Context(), &collectorupdate.UpdateParams{
|
||||
err := s.svc.CollectorSet.SetByClientId(ctx.Request().Context(), &collectorset.SetParams{
|
||||
ClientID: clientId,
|
||||
ActiveVersion: req.ActiveVersion,
|
||||
MinCleanVersion: req.MinimumCleanerVersion,
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
queryservice "queryorchestration/api/queryService"
|
||||
"queryorchestration/internal/collector"
|
||||
collectorupdate "queryorchestration/internal/collector/update"
|
||||
collectorset "queryorchestration/internal/collector/set"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
cleanversion "queryorchestration/internal/document/clean/version"
|
||||
@@ -31,7 +31,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestUpdateCollector(t *testing.T) {
|
||||
func TestSetCollector(t *testing.T) {
|
||||
pool, err := pgxmock.NewPool()
|
||||
require.NoError(t, err)
|
||||
cfg := &struct {
|
||||
@@ -51,7 +51,7 @@ func TestUpdateCollector(t *testing.T) {
|
||||
|
||||
av := int32(2)
|
||||
cv := int32(1)
|
||||
body := queryservice.CollectorUpdate{
|
||||
body := queryservice.CollectorSet{
|
||||
ActiveVersion: &av,
|
||||
MinimumCleanerVersion: &cv,
|
||||
Fields: &[]queryservice.CollectorField{
|
||||
@@ -71,11 +71,10 @@ func TestUpdateCollector(t *testing.T) {
|
||||
ctx := e.NewContext(req, rec)
|
||||
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
CollectorUpdate: collectorupdate.New(cfg, &collectorupdate.Services{
|
||||
Collector: collector.New(cfg, &collector.Services{
|
||||
CleanVersion: cleanversion.New(cfg),
|
||||
TextVersion: textversion.New(cfg),
|
||||
}),
|
||||
CollectorSet: collectorset.New(cfg, &collectorset.Services{
|
||||
CleanVersion: cleanversion.New(cfg),
|
||||
TextVersion: textversion.New(cfg),
|
||||
Collector: collector.New(cfg),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -114,7 +113,7 @@ func TestUpdateCollector(t *testing.T) {
|
||||
).
|
||||
Return(&sqs.SendMessageOutput{}, nil)
|
||||
|
||||
err = cons.UpdateCollectorByClientId(ctx, current.ClientID)
|
||||
err = cons.SetCollectorByClientId(ctx, current.ClientID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, rec.Code)
|
||||
assert.Empty(t, rec.Body.String())
|
||||
@@ -132,10 +131,7 @@ func TestGetCollectorByclientId(t *testing.T) {
|
||||
rec := httptest.NewRecorder()
|
||||
ctx := e.NewContext(req, rec)
|
||||
|
||||
svc := collector.New(cfg, &collector.Services{
|
||||
CleanVersion: cleanversion.New(cfg),
|
||||
TextVersion: textversion.New(cfg),
|
||||
})
|
||||
svc := collector.New(cfg)
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Collector: svc,
|
||||
})
|
||||
|
||||
@@ -3,7 +3,7 @@ package queryservice
|
||||
import (
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/collector"
|
||||
collectorupdate "queryorchestration/internal/collector/update"
|
||||
collectorset "queryorchestration/internal/collector/set"
|
||||
"queryorchestration/internal/document"
|
||||
"queryorchestration/internal/export"
|
||||
"queryorchestration/internal/query"
|
||||
@@ -16,14 +16,14 @@ import (
|
||||
const Name = "queryService"
|
||||
|
||||
type Services struct {
|
||||
Export *export.Service
|
||||
Collector *collector.Service
|
||||
CollectorUpdate *collectorupdate.Service
|
||||
Query *query.Service
|
||||
QueryUpdate *queryupdate.Service
|
||||
QueryTest *querytest.Service
|
||||
Client *client.Service
|
||||
Document *document.Service
|
||||
Export *export.Service
|
||||
Collector *collector.Service
|
||||
CollectorSet *collectorset.Service
|
||||
Query *query.Service
|
||||
QueryUpdate *queryupdate.Service
|
||||
QueryTest *querytest.Service
|
||||
Client *client.Service
|
||||
Document *document.Service
|
||||
}
|
||||
|
||||
type Controllers struct {
|
||||
|
||||
@@ -13,8 +13,6 @@ import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
cleanversion "queryorchestration/internal/document/clean/version"
|
||||
textversion "queryorchestration/internal/document/text/version"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/query/result"
|
||||
querytest "queryorchestration/internal/query/test"
|
||||
@@ -230,10 +228,7 @@ func TestTestQuery(t *testing.T) {
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
docsvc := document.New(cfg)
|
||||
col := collector.New(cfg, &collector.Services{
|
||||
CleanVersion: cleanversion.New(cfg),
|
||||
TextVersion: textversion.New(cfg),
|
||||
})
|
||||
col := collector.New(cfg)
|
||||
que := query.New(cfg)
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Collector: col,
|
||||
|
||||
@@ -9,11 +9,8 @@ import (
|
||||
|
||||
queryservice "queryorchestration/api/queryService"
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/collector"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
cleanversion "queryorchestration/internal/document/clean/version"
|
||||
textversion "queryorchestration/internal/document/text/version"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
@@ -32,12 +29,7 @@ func TestGetClientStatus(t *testing.T) {
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Client: client.New(cfg, &client.Services{
|
||||
Collector: collector.New(cfg, &collector.Services{
|
||||
TextVersion: textversion.New(cfg),
|
||||
CleanVersion: cleanversion.New(cfg),
|
||||
}),
|
||||
}),
|
||||
Client: client.New(cfg),
|
||||
})
|
||||
|
||||
e := echo.New()
|
||||
|
||||
@@ -16,11 +16,8 @@ import (
|
||||
|
||||
docsyncrunner "queryorchestration/api/docSyncRunner"
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/collector"
|
||||
"queryorchestration/internal/document"
|
||||
cleanversion "queryorchestration/internal/document/clean/version"
|
||||
documentsync "queryorchestration/internal/document/sync"
|
||||
textversion "queryorchestration/internal/document/text/version"
|
||||
"queryorchestration/internal/server/runner"
|
||||
documentcleanc "queryorchestration/internal/serviceconfig/queue/documentclean"
|
||||
|
||||
@@ -38,13 +35,7 @@ func main() {
|
||||
cfg := &DocSyncConfig{}
|
||||
|
||||
cfg.ControllerFunc = func() runner.Controller {
|
||||
coll := collector.New(cfg, &collector.Services{
|
||||
CleanVersion: cleanversion.New(cfg),
|
||||
TextVersion: textversion.New(cfg),
|
||||
})
|
||||
cli := client.New(cfg, &client.Services{
|
||||
Collector: coll,
|
||||
})
|
||||
cli := client.New(cfg)
|
||||
doc := document.New(cfg)
|
||||
docsync := documentsync.New(cfg, &documentsync.Services{
|
||||
Document: doc,
|
||||
|
||||
+12
-17
@@ -22,7 +22,7 @@ import (
|
||||
queryservice "queryorchestration/api/queryService"
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/collector"
|
||||
collectorupdate "queryorchestration/internal/collector/update"
|
||||
collectorset "queryorchestration/internal/collector/set"
|
||||
"queryorchestration/internal/document"
|
||||
cleanversion "queryorchestration/internal/document/clean/version"
|
||||
textversion "queryorchestration/internal/document/text/version"
|
||||
@@ -58,18 +58,13 @@ func main() {
|
||||
})
|
||||
tev := textversion.New(cfg)
|
||||
clv := cleanversion.New(cfg)
|
||||
col := collector.New(cfg, &collector.Services{
|
||||
CleanVersion: clv,
|
||||
TextVersion: tev,
|
||||
})
|
||||
colupdate := collectorupdate.New(cfg, &collectorupdate.Services{
|
||||
col := collector.New(cfg)
|
||||
colupdate := collectorset.New(cfg, &collectorset.Services{
|
||||
Collector: col,
|
||||
CleanVersion: clv,
|
||||
TextVersion: tev,
|
||||
})
|
||||
cli := client.New(cfg, &client.Services{
|
||||
Collector: col,
|
||||
})
|
||||
cli := client.New(cfg)
|
||||
doc := document.New(cfg)
|
||||
quetest := querytest.New(cfg, &querytest.Services{
|
||||
Collector: col,
|
||||
@@ -81,14 +76,14 @@ func main() {
|
||||
})
|
||||
|
||||
services := &queryservice.Services{
|
||||
Export: exp,
|
||||
Collector: col,
|
||||
CollectorUpdate: colupdate,
|
||||
Query: que,
|
||||
QueryUpdate: qupdate,
|
||||
QueryTest: quetest,
|
||||
Client: cli,
|
||||
Document: doc,
|
||||
Export: exp,
|
||||
Collector: col,
|
||||
CollectorSet: colupdate,
|
||||
Query: que,
|
||||
QueryUpdate: qupdate,
|
||||
QueryTest: quetest,
|
||||
Client: cli,
|
||||
Document: doc,
|
||||
}
|
||||
|
||||
cons := queryservice.NewControllers(cfg.GetValidator(), services)
|
||||
|
||||
@@ -3,7 +3,6 @@ package client
|
||||
import (
|
||||
"context"
|
||||
|
||||
"queryorchestration/internal/collector"
|
||||
"queryorchestration/internal/database"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -20,12 +19,5 @@ func (s *Service) Create(ctx context.Context, name string) (uuid.UUID, error) {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -5,15 +5,11 @@ import (
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/collector"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
cleanversion "queryorchestration/internal/document/clean/version"
|
||||
textversion "queryorchestration/internal/document/text/version"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -28,12 +24,7 @@ func TestCreate(t *testing.T) {
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := client.New(cfg, &client.Services{
|
||||
Collector: collector.New(cfg, &collector.Services{
|
||||
CleanVersion: cleanversion.New(cfg),
|
||||
TextVersion: textversion.New(cfg),
|
||||
}),
|
||||
})
|
||||
svc := client.New(cfg)
|
||||
|
||||
name := "client_name"
|
||||
aid := uuid.New()
|
||||
@@ -43,14 +34,6 @@ func TestCreate(t *testing.T) {
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
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)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -25,7 +25,7 @@ func TestGet(t *testing.T) {
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := client.New(cfg, &client.Services{})
|
||||
svc := client.New(cfg)
|
||||
|
||||
id := uuid.New()
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"queryorchestration/internal/collector"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -71,18 +70,12 @@ func normalizeName(name *string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type Services struct {
|
||||
Collector *collector.Service
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
cfg serviceconfig.ConfigProvider
|
||||
svc *Services
|
||||
}
|
||||
|
||||
func New(cfg serviceconfig.ConfigProvider, svc *Services) *Service {
|
||||
func New(cfg serviceconfig.ConfigProvider) *Service {
|
||||
return &Service{
|
||||
cfg,
|
||||
svc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,6 @@ func TestService(t *testing.T) {
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := client.New(cfg, &client.Services{})
|
||||
svc := client.New(cfg)
|
||||
assert.NotNil(t, svc)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func TestGetStatus(t *testing.T) {
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := client.New(cfg, &client.Services{})
|
||||
svc := client.New(cfg)
|
||||
|
||||
clientId := uuid.New()
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestUpdate(t *testing.T) {
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := New(cfg, &Services{})
|
||||
svc := New(cfg)
|
||||
|
||||
c := Client{
|
||||
ID: uuid.New(),
|
||||
@@ -120,7 +120,7 @@ func TestSubmitUpdate(t *testing.T) {
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := New(cfg, &Services{})
|
||||
svc := New(cfg)
|
||||
|
||||
c := Client{
|
||||
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.DBQueries = repository.New(pool)
|
||||
|
||||
svc := collector.New(cfg, &collector.Services{})
|
||||
svc := collector.New(cfg)
|
||||
|
||||
minCleanV := int32(2)
|
||||
minTextV := int32(4)
|
||||
@@ -59,7 +59,7 @@ func TestListQueries(t *testing.T) {
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := collector.New(cfg, &collector.Services{})
|
||||
svc := collector.New(cfg)
|
||||
|
||||
clientId := uuid.New()
|
||||
ogc := []*resultprocessor.Query{
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package collector
|
||||
|
||||
import (
|
||||
cleanversion "queryorchestration/internal/document/clean/version"
|
||||
textversion "queryorchestration/internal/document/text/version"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -17,19 +15,12 @@ type Collector struct {
|
||||
Fields map[string]uuid.UUID
|
||||
}
|
||||
|
||||
type Services struct {
|
||||
CleanVersion *cleanversion.Service
|
||||
TextVersion *textversion.Service
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
cfg serviceconfig.ConfigProvider
|
||||
svc *Services
|
||||
}
|
||||
|
||||
func New(cfg serviceconfig.ConfigProvider, svc *Services) *Service {
|
||||
func New(cfg serviceconfig.ConfigProvider) *Service {
|
||||
return &Service{
|
||||
cfg,
|
||||
svc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,6 @@ func TestService(t *testing.T) {
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := collector.New(cfg, &collector.Services{})
|
||||
svc := collector.New(cfg)
|
||||
assert.NotNil(t, svc)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package collectorupdate
|
||||
package collectorset
|
||||
|
||||
import (
|
||||
collector "queryorchestration/internal/collector"
|
||||
@@ -1,11 +1,10 @@
|
||||
package collectorupdate_test
|
||||
package collectorset_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/collector"
|
||||
collectorset "queryorchestration/internal/collector/set"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -15,10 +14,10 @@ import (
|
||||
func TestService(t *testing.T) {
|
||||
pool, err := pgxmock.NewPool()
|
||||
require.NoError(t, err)
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg := &CollectorSetConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := collector.New(cfg, &collector.Services{})
|
||||
svc := collectorset.New(cfg, &collectorset.Services{})
|
||||
assert.NotNil(t, svc)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package collectorupdate
|
||||
package collectorset
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type UpdateParams struct {
|
||||
type SetParams struct {
|
||||
ClientID uuid.UUID
|
||||
ActiveVersion *int32
|
||||
MinCleanVersion *int32
|
||||
@@ -24,23 +24,23 @@ type UpdateParams struct {
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dbparams, err := s.getUpdateParams(ctx, current, params)
|
||||
dbparams, err := s.getSetParams(ctx, current, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.submitUpdate(ctx, current, dbparams)
|
||||
err = s.submitSet(ctx, current, dbparams)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.informUpdate(ctx, dbparams)
|
||||
err = s.informSet(ctx, dbparams)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func (s *Service) UpdateByClientId(ctx context.Context, params *UpdateParams) er
|
||||
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 {
|
||||
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
|
||||
ActiveVersion *int32
|
||||
MinCleanVersion *int32
|
||||
@@ -69,13 +69,13 @@ type dbUpdateParams struct {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fields, err := s.normalizeUpdateFieldsToDB(ctx, current.Fields, params.Fields)
|
||||
fields, err := s.normalizeSetFieldsToDB(ctx, current.Fields, params.Fields)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func (s *Service) getUpdateParams(ctx context.Context, current *collector.Collec
|
||||
return nil, errors.New("no changes")
|
||||
}
|
||||
|
||||
return &dbUpdateParams{
|
||||
return &dbSetParams{
|
||||
ClientID: database.MustToDBUUID(params.ClientID),
|
||||
ActiveVersion: params.ActiveVersion,
|
||||
MinCleanVersion: params.MinCleanVersion,
|
||||
@@ -109,7 +109,7 @@ func (s *Service) getUpdateParams(ctx context.Context, current *collector.Collec
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Service) normalizeCodeVersions(current *collector.Collector, params *UpdateParams) error {
|
||||
func (s *Service) normalizeCodeVersions(current *collector.Collector, params *SetParams) error {
|
||||
if current == nil {
|
||||
return errors.New("current collector required")
|
||||
}
|
||||
@@ -143,7 +143,7 @@ func (s *Service) normalizeCodeVersions(current *collector.Collector, params *Up
|
||||
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 {
|
||||
return errors.New("current collector required")
|
||||
}
|
||||
@@ -160,7 +160,7 @@ func (s *Service) normalizeActiveVersion(current *collector.Collector, params *U
|
||||
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 {
|
||||
return nil, nil
|
||||
} else if len(*ofields) == 0 {
|
||||
@@ -179,10 +179,10 @@ func (s *Service) normalizeUpdateFieldsToDB(ctx context.Context, current map[str
|
||||
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 {
|
||||
activeName, err := validation.GetFieldName(params, params.ActiveVersion)
|
||||
if err != nil {
|
||||
@@ -304,3 +304,36 @@ func getAddFields(current map[string]uuid.UUID, update *map[string]pgtype.UUID)
|
||||
|
||||
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 (
|
||||
"context"
|
||||
@@ -24,25 +24,25 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type CollectorUpdateConfig struct {
|
||||
type CollectorSetConfig struct {
|
||||
serviceconfig.BaseConfig
|
||||
clientsync.ClientSyncConfig
|
||||
}
|
||||
|
||||
func TestGetUpdateParams(t *testing.T) {
|
||||
func TestGetSetParams(t *testing.T) {
|
||||
t.Run("all params", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
pool, err := pgxmock.NewPool()
|
||||
require.NoError(t, err)
|
||||
cfg := &CollectorUpdateConfig{}
|
||||
cfg := &CollectorSetConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := Service{
|
||||
cfg: cfg,
|
||||
svc: &Services{
|
||||
Collector: collector.New(cfg, &collector.Services{}),
|
||||
Collector: collector.New(cfg),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestGetUpdateParams(t *testing.T) {
|
||||
ActiveVersion: 1,
|
||||
LatestVersion: 10,
|
||||
}
|
||||
params := UpdateParams{
|
||||
params := SetParams{
|
||||
ClientID: uuid.New(),
|
||||
ActiveVersion: &aV,
|
||||
MinCleanVersion: &minCleanV,
|
||||
@@ -68,9 +68,9 @@ func TestGetUpdateParams(t *testing.T) {
|
||||
AddRow(true),
|
||||
)
|
||||
|
||||
dbparams, err := svc.getUpdateParams(ctx, ¤t, ¶ms)
|
||||
dbparams, err := svc.getSetParams(ctx, ¤t, ¶ms)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &dbUpdateParams{
|
||||
assert.EqualExportedValues(t, &dbSetParams{
|
||||
ClientID: database.MustToDBUUID(params.ClientID),
|
||||
ActiveVersion: &aV,
|
||||
MinCleanVersion: &minCleanV,
|
||||
@@ -82,7 +82,7 @@ func TestGetUpdateParams(t *testing.T) {
|
||||
|
||||
(*params.Fields)["second_key"] = (*params.Fields)["example_key"]
|
||||
assert.Len(t, *params.Fields, 2)
|
||||
_, err = svc.getUpdateParams(ctx, ¤t, ¶ms)
|
||||
_, err = svc.getSetParams(ctx, ¤t, ¶ms)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
@@ -91,7 +91,7 @@ func TestGetUpdateParams(t *testing.T) {
|
||||
|
||||
pool, err := pgxmock.NewPool()
|
||||
require.NoError(t, err)
|
||||
cfg := &CollectorUpdateConfig{}
|
||||
cfg := &CollectorSetConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
@@ -101,10 +101,10 @@ func TestGetUpdateParams(t *testing.T) {
|
||||
}
|
||||
|
||||
current := collector.Collector{}
|
||||
params := UpdateParams{
|
||||
params := SetParams{
|
||||
ClientID: current.ClientID,
|
||||
}
|
||||
_, err = svc.getUpdateParams(ctx, ¤t, ¶ms)
|
||||
_, err = svc.getSetParams(ctx, ¤t, ¶ms)
|
||||
assert.EqualError(t, err, "no changes")
|
||||
})
|
||||
|
||||
@@ -113,7 +113,7 @@ func TestGetUpdateParams(t *testing.T) {
|
||||
|
||||
pool, err := pgxmock.NewPool()
|
||||
require.NoError(t, err)
|
||||
cfg := &CollectorUpdateConfig{}
|
||||
cfg := &CollectorSetConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
@@ -127,11 +127,11 @@ func TestGetUpdateParams(t *testing.T) {
|
||||
LatestVersion: 4,
|
||||
}
|
||||
version := int32(5)
|
||||
params := UpdateParams{
|
||||
params := SetParams{
|
||||
ClientID: current.ClientID,
|
||||
ActiveVersion: &version,
|
||||
}
|
||||
_, err = svc.getUpdateParams(ctx, ¤t, ¶ms)
|
||||
_, err = svc.getSetParams(ctx, ¤t, ¶ms)
|
||||
assert.EqualError(t, err, "no changes")
|
||||
})
|
||||
|
||||
@@ -140,7 +140,7 @@ func TestGetUpdateParams(t *testing.T) {
|
||||
|
||||
pool, err := pgxmock.NewPool()
|
||||
require.NoError(t, err)
|
||||
cfg := &CollectorUpdateConfig{}
|
||||
cfg := &CollectorSetConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
@@ -154,25 +154,25 @@ func TestGetUpdateParams(t *testing.T) {
|
||||
"example": uuid.New(),
|
||||
},
|
||||
}
|
||||
params := UpdateParams{
|
||||
params := SetParams{
|
||||
ClientID: current.ClientID,
|
||||
Fields: &map[string]uuid.UUID{
|
||||
"example": current.Fields["example"],
|
||||
},
|
||||
}
|
||||
_, err = svc.getUpdateParams(ctx, ¤t, ¶ms)
|
||||
_, err = svc.getSetParams(ctx, ¤t, ¶ms)
|
||||
assert.EqualError(t, err, "no changes")
|
||||
})
|
||||
}
|
||||
|
||||
func TestSubmitUpdate(t *testing.T) {
|
||||
func TestSubmitSet(t *testing.T) {
|
||||
t.Run("all fields", func(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
pool, err := pgxmock.NewPool()
|
||||
require.NoError(t, err)
|
||||
cfg := &CollectorUpdateConfig{}
|
||||
cfg := &CollectorSetConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
@@ -195,7 +195,7 @@ func TestSubmitUpdate(t *testing.T) {
|
||||
},
|
||||
}
|
||||
aV := int32(2)
|
||||
params := dbUpdateParams{
|
||||
params := dbSetParams{
|
||||
ClientID: database.MustToDBUUID(current.ClientID),
|
||||
ActiveVersion: &aV,
|
||||
MinCleanVersion: &minCleanV,
|
||||
@@ -231,7 +231,7 @@ func TestSubmitUpdate(t *testing.T) {
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
err = svc.submitUpdate(ctx, ¤t, ¶ms)
|
||||
err = svc.submitSet(ctx, ¤t, ¶ms)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
t.Run("only active version", func(t *testing.T) {
|
||||
@@ -240,7 +240,7 @@ func TestSubmitUpdate(t *testing.T) {
|
||||
|
||||
pool, err := pgxmock.NewPool()
|
||||
require.NoError(t, err)
|
||||
cfg := &CollectorUpdateConfig{}
|
||||
cfg := &CollectorSetConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
@@ -258,7 +258,7 @@ func TestSubmitUpdate(t *testing.T) {
|
||||
Fields: map[string]uuid.UUID{},
|
||||
}
|
||||
av := int32(2)
|
||||
params := dbUpdateParams{
|
||||
params := dbSetParams{
|
||||
ClientID: database.MustToDBUUID(current.ClientID),
|
||||
ActiveVersion: &av,
|
||||
}
|
||||
@@ -268,7 +268,7 @@ func TestSubmitUpdate(t *testing.T) {
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
err = svc.submitUpdate(ctx, ¤t, ¶ms)
|
||||
err = svc.submitSet(ctx, ¤t, ¶ms)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
}
|
||||
@@ -296,7 +296,7 @@ func TestNormalizeActiveVersion(t *testing.T) {
|
||||
ActiveVersion: 1,
|
||||
LatestVersion: 4,
|
||||
}
|
||||
update := UpdateParams{}
|
||||
update := SetParams{}
|
||||
err := svc.normalizeActiveVersion(¤t, &update)
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, update.ActiveVersion)
|
||||
@@ -308,7 +308,7 @@ func TestNormalizeActiveVersion(t *testing.T) {
|
||||
ActiveVersion: version,
|
||||
LatestVersion: 4,
|
||||
}
|
||||
update := UpdateParams{
|
||||
update := SetParams{
|
||||
ActiveVersion: &version,
|
||||
}
|
||||
err := svc.normalizeActiveVersion(¤t, &update)
|
||||
@@ -322,7 +322,7 @@ func TestNormalizeActiveVersion(t *testing.T) {
|
||||
LatestVersion: 4,
|
||||
}
|
||||
version := int32(5)
|
||||
update := UpdateParams{
|
||||
update := SetParams{
|
||||
ActiveVersion: &version,
|
||||
}
|
||||
err := svc.normalizeActiveVersion(¤t, &update)
|
||||
@@ -336,7 +336,7 @@ func TestNormalizeActiveVersion(t *testing.T) {
|
||||
LatestVersion: 4,
|
||||
}
|
||||
version := int32(6)
|
||||
update := UpdateParams{
|
||||
update := SetParams{
|
||||
ActiveVersion: &version,
|
||||
}
|
||||
err := svc.normalizeActiveVersion(¤t, &update)
|
||||
@@ -345,7 +345,7 @@ func TestNormalizeActiveVersion(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNormalizeCodeVersions(t *testing.T) {
|
||||
cfg := &CollectorUpdateConfig{}
|
||||
cfg := &CollectorSetConfig{}
|
||||
svc := Service{
|
||||
svc: &Services{
|
||||
CleanVersion: cleanversion.New(cfg),
|
||||
@@ -366,7 +366,7 @@ func TestNormalizeCodeVersions(t *testing.T) {
|
||||
|
||||
t.Run("empty", func(t *testing.T) {
|
||||
current := collector.Collector{}
|
||||
update := UpdateParams{}
|
||||
update := SetParams{}
|
||||
|
||||
err := svc.normalizeCodeVersions(¤t, &update)
|
||||
assert.NoError(t, err)
|
||||
@@ -376,7 +376,7 @@ func TestNormalizeCodeVersions(t *testing.T) {
|
||||
|
||||
t.Run("valid clean", func(t *testing.T) {
|
||||
current := collector.Collector{}
|
||||
update := UpdateParams{}
|
||||
update := SetParams{}
|
||||
|
||||
cv := int32(1)
|
||||
update.MinCleanVersion = &cv
|
||||
@@ -388,7 +388,7 @@ func TestNormalizeCodeVersions(t *testing.T) {
|
||||
|
||||
t.Run("valid text", func(t *testing.T) {
|
||||
current := collector.Collector{}
|
||||
update := UpdateParams{}
|
||||
update := SetParams{}
|
||||
|
||||
tv := int32(1)
|
||||
update.MinTextVersion = &tv
|
||||
@@ -400,7 +400,7 @@ func TestNormalizeCodeVersions(t *testing.T) {
|
||||
|
||||
t.Run("valid clean and text", func(t *testing.T) {
|
||||
current := collector.Collector{}
|
||||
update := UpdateParams{}
|
||||
update := SetParams{}
|
||||
|
||||
current.MinCleanVersion = 1
|
||||
current.MinTextVersion = 1
|
||||
@@ -414,7 +414,7 @@ func TestNormalizeCodeVersions(t *testing.T) {
|
||||
current := collector.Collector{
|
||||
MinCleanVersion: 1,
|
||||
}
|
||||
update := UpdateParams{}
|
||||
update := SetParams{}
|
||||
|
||||
update.MinCleanVersion = ¤t.MinCleanVersion
|
||||
err := svc.normalizeCodeVersions(¤t, &update)
|
||||
@@ -427,7 +427,7 @@ func TestNormalizeCodeVersions(t *testing.T) {
|
||||
current := collector.Collector{
|
||||
MinTextVersion: 1,
|
||||
}
|
||||
update := UpdateParams{}
|
||||
update := SetParams{}
|
||||
|
||||
update.MinTextVersion = ¤t.MinTextVersion
|
||||
err := svc.normalizeCodeVersions(¤t, &update)
|
||||
@@ -441,7 +441,7 @@ func TestNormalizeCodeVersions(t *testing.T) {
|
||||
MinCleanVersion: 1,
|
||||
MinTextVersion: 1,
|
||||
}
|
||||
update := UpdateParams{}
|
||||
update := SetParams{}
|
||||
|
||||
update.MinCleanVersion = ¤t.MinCleanVersion
|
||||
update.MinTextVersion = ¤t.MinTextVersion
|
||||
@@ -527,21 +527,21 @@ func TestGetAddFields(t *testing.T) {
|
||||
}, add)
|
||||
}
|
||||
|
||||
func TestNormalizeUpdateFieldsToDB(t *testing.T) {
|
||||
func TestNormalizeSetFieldsToDB(t *testing.T) {
|
||||
t.Run("valid key", func(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
pool, err := pgxmock.NewPool()
|
||||
require.NoError(t, err)
|
||||
cfg := &CollectorUpdateConfig{}
|
||||
cfg := &CollectorSetConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := Service{
|
||||
cfg: cfg,
|
||||
svc: &Services{
|
||||
Collector: collector.New(cfg, &collector.Services{}),
|
||||
Collector: collector.New(cfg),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -555,7 +555,7 @@ func TestNormalizeUpdateFieldsToDB(t *testing.T) {
|
||||
AddRow(true),
|
||||
)
|
||||
|
||||
dbparams, err := svc.normalizeUpdateFieldsToDB(ctx, current, &fields)
|
||||
dbparams, err := svc.normalizeSetFieldsToDB(ctx, current, &fields)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &map[string]pgtype.UUID{
|
||||
"example_key": database.MustToDBUUID(fields["example_key"]),
|
||||
@@ -567,7 +567,7 @@ func TestNormalizeUpdateFieldsToDB(t *testing.T) {
|
||||
|
||||
pool, err := pgxmock.NewPool()
|
||||
require.NoError(t, err)
|
||||
cfg := &CollectorUpdateConfig{}
|
||||
cfg := &CollectorSetConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
@@ -587,17 +587,17 @@ func TestNormalizeUpdateFieldsToDB(t *testing.T) {
|
||||
AddRow(true),
|
||||
)
|
||||
|
||||
_, err = svc.normalizeUpdateFieldsToDB(ctx, current, &fields)
|
||||
_, err = svc.normalizeSetFieldsToDB(ctx, current, &fields)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
t.Run("no changes", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
cfg := &CollectorUpdateConfig{}
|
||||
cfg := &CollectorSetConfig{}
|
||||
|
||||
svc := Service{
|
||||
cfg: cfg,
|
||||
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"],
|
||||
}
|
||||
|
||||
val, err := svc.normalizeUpdateFieldsToDB(ctx, current, &fields)
|
||||
val, err := svc.normalizeSetFieldsToDB(ctx, current, &fields)
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, val)
|
||||
})
|
||||
}
|
||||
|
||||
func TestInformUpdate(t *testing.T) {
|
||||
func TestInformSet(t *testing.T) {
|
||||
t.Run("with version update", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
pool, err := pgxmock.NewPool()
|
||||
require.NoError(t, err)
|
||||
cfg := &CollectorUpdateConfig{}
|
||||
cfg := &CollectorSetConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
mockSQS := queuemock.NewMockSQSClient(t)
|
||||
@@ -630,7 +630,7 @@ func TestInformUpdate(t *testing.T) {
|
||||
svc := New(cfg, &Services{})
|
||||
|
||||
av := int32(2)
|
||||
update := dbUpdateParams{
|
||||
update := dbSetParams{
|
||||
ClientID: database.MustToDBUUID(uuid.New()),
|
||||
ActiveVersion: &av,
|
||||
}
|
||||
@@ -645,7 +645,7 @@ func TestInformUpdate(t *testing.T) {
|
||||
).
|
||||
Return(&sqs.SendMessageOutput{}, nil)
|
||||
|
||||
err = svc.informUpdate(ctx, &update)
|
||||
err = svc.informSet(ctx, &update)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
t.Run("with no update", func(t *testing.T) {
|
||||
@@ -653,7 +653,7 @@ func TestInformUpdate(t *testing.T) {
|
||||
|
||||
pool, err := pgxmock.NewPool()
|
||||
require.NoError(t, err)
|
||||
cfg := &CollectorUpdateConfig{}
|
||||
cfg := &CollectorSetConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
mockSQS := queuemock.NewMockSQSClient(t)
|
||||
@@ -662,11 +662,51 @@ func TestInformUpdate(t *testing.T) {
|
||||
|
||||
svc := New(cfg, &Services{})
|
||||
|
||||
update := dbUpdateParams{
|
||||
update := dbSetParams{
|
||||
ClientID: database.MustToDBUUID(uuid.New()),
|
||||
}
|
||||
|
||||
err = svc.informUpdate(ctx, &update)
|
||||
err = svc.informSet(ctx, &update)
|
||||
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{
|
||||
Document: document.New(cfg),
|
||||
Client: client.New(cfg, &client.Services{}),
|
||||
Client: client.New(cfg),
|
||||
})
|
||||
|
||||
j := client.Client{
|
||||
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
cleanversion "queryorchestration/internal/document/clean/version"
|
||||
textversion "queryorchestration/internal/document/text/version"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/query/result"
|
||||
querytest "queryorchestration/internal/query/test"
|
||||
@@ -31,10 +29,7 @@ func TestTest(t *testing.T) {
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
col := collector.New(cfg, &collector.Services{
|
||||
TextVersion: textversion.New(cfg),
|
||||
CleanVersion: cleanversion.New(cfg),
|
||||
})
|
||||
col := collector.New(cfg)
|
||||
docsvc := document.New(cfg)
|
||||
svc := querytest.New(cfg, &querytest.Services{
|
||||
Document: docsvc,
|
||||
|
||||
+32
-32
@@ -106,8 +106,8 @@ type CollectorField struct {
|
||||
QueryId openapi_types.UUID `json:"query_id"`
|
||||
}
|
||||
|
||||
// CollectorUpdate Payload for updating a Collector.
|
||||
type CollectorUpdate struct {
|
||||
// CollectorSet Payload for updating a Collector.
|
||||
type CollectorSet struct {
|
||||
// ActiveVersion The active version of the collector.
|
||||
ActiveVersion *int32 `json:"active_version,omitempty"`
|
||||
|
||||
@@ -274,8 +274,8 @@ type CreateClientJSONRequestBody = ClientCreate
|
||||
// UpdateClientJSONRequestBody defines body for UpdateClient for application/json ContentType.
|
||||
type UpdateClientJSONRequestBody = ClientUpdate
|
||||
|
||||
// UpdateCollectorByClientIdJSONRequestBody defines body for UpdateCollectorByClientId for application/json ContentType.
|
||||
type UpdateCollectorByClientIdJSONRequestBody = CollectorUpdate
|
||||
// SetCollectorByClientIdJSONRequestBody defines body for SetCollectorByClientId for application/json ContentType.
|
||||
type SetCollectorByClientIdJSONRequestBody = CollectorSet
|
||||
|
||||
// TriggerExportJSONRequestBody defines body for TriggerExport for application/json ContentType.
|
||||
type TriggerExportJSONRequestBody = ExportTrigger
|
||||
@@ -378,10 +378,10 @@ type ClientInterface interface {
|
||||
// GetCollectorByClientId request
|
||||
GetCollectorByClientId(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error)
|
||||
|
||||
// UpdateCollectorByClientIdWithBody request with any body
|
||||
UpdateCollectorByClientIdWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
|
||||
// SetCollectorByClientIdWithBody request with any body
|
||||
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(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)
|
||||
}
|
||||
|
||||
func (c *Client) UpdateCollectorByClientIdWithBody(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)
|
||||
func (c *Client) SetCollectorByClientIdWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
||||
req, err := NewSetCollectorByClientIdRequestWithBody(c.Server, id, contentType, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -503,8 +503,8 @@ func (c *Client) UpdateCollectorByClientIdWithBody(ctx context.Context, id opena
|
||||
return c.Client.Do(req)
|
||||
}
|
||||
|
||||
func (c *Client) UpdateCollectorByClientId(ctx context.Context, id openapi_types.UUID, body UpdateCollectorByClientIdJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
||||
req, err := NewUpdateCollectorByClientIdRequest(c.Server, id, body)
|
||||
func (c *Client) SetCollectorByClientId(ctx context.Context, id openapi_types.UUID, body SetCollectorByClientIdJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
||||
req, err := NewSetCollectorByClientIdRequest(c.Server, id, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -826,19 +826,19 @@ func NewGetCollectorByClientIdRequest(server string, id openapi_types.UUID) (*ht
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// NewUpdateCollectorByClientIdRequest calls the generic UpdateCollectorByClientId builder with application/json body
|
||||
func NewUpdateCollectorByClientIdRequest(server string, id openapi_types.UUID, body UpdateCollectorByClientIdJSONRequestBody) (*http.Request, error) {
|
||||
// NewSetCollectorByClientIdRequest calls the generic SetCollectorByClientId builder with application/json body
|
||||
func NewSetCollectorByClientIdRequest(server string, id openapi_types.UUID, body SetCollectorByClientIdJSONRequestBody) (*http.Request, error) {
|
||||
var bodyReader io.Reader
|
||||
buf, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
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
|
||||
func NewUpdateCollectorByClientIdRequestWithBody(server string, id openapi_types.UUID, contentType string, body io.Reader) (*http.Request, error) {
|
||||
// NewSetCollectorByClientIdRequestWithBody generates requests for SetCollectorByClientId with any type of body
|
||||
func NewSetCollectorByClientIdRequestWithBody(server string, id openapi_types.UUID, contentType string, body io.Reader) (*http.Request, error) {
|
||||
var err error
|
||||
|
||||
var pathParam0 string
|
||||
@@ -1276,10 +1276,10 @@ type ClientWithResponsesInterface interface {
|
||||
// GetCollectorByClientIdWithResponse request
|
||||
GetCollectorByClientIdWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*GetCollectorByClientIdResponse, error)
|
||||
|
||||
// UpdateCollectorByClientIdWithBodyWithResponse request with any body
|
||||
UpdateCollectorByClientIdWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateCollectorByClientIdResponse, error)
|
||||
// SetCollectorByClientIdWithBodyWithResponse request with any body
|
||||
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(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*ListDocumentsByClientIdResponse, error)
|
||||
@@ -1404,13 +1404,13 @@ func (r GetCollectorByClientIdResponse) StatusCode() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
type UpdateCollectorByClientIdResponse struct {
|
||||
type SetCollectorByClientIdResponse struct {
|
||||
Body []byte
|
||||
HTTPResponse *http.Response
|
||||
}
|
||||
|
||||
// Status returns HTTPResponse.Status
|
||||
func (r UpdateCollectorByClientIdResponse) Status() string {
|
||||
func (r SetCollectorByClientIdResponse) Status() string {
|
||||
if r.HTTPResponse != nil {
|
||||
return r.HTTPResponse.Status
|
||||
}
|
||||
@@ -1418,7 +1418,7 @@ func (r UpdateCollectorByClientIdResponse) Status() string {
|
||||
}
|
||||
|
||||
// StatusCode returns HTTPResponse.StatusCode
|
||||
func (r UpdateCollectorByClientIdResponse) StatusCode() int {
|
||||
func (r SetCollectorByClientIdResponse) StatusCode() int {
|
||||
if r.HTTPResponse != nil {
|
||||
return r.HTTPResponse.StatusCode
|
||||
}
|
||||
@@ -1674,21 +1674,21 @@ func (c *ClientWithResponses) GetCollectorByClientIdWithResponse(ctx context.Con
|
||||
return ParseGetCollectorByClientIdResponse(rsp)
|
||||
}
|
||||
|
||||
// UpdateCollectorByClientIdWithBodyWithResponse request with arbitrary body returning *UpdateCollectorByClientIdResponse
|
||||
func (c *ClientWithResponses) UpdateCollectorByClientIdWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateCollectorByClientIdResponse, error) {
|
||||
rsp, err := c.UpdateCollectorByClientIdWithBody(ctx, id, contentType, body, reqEditors...)
|
||||
// SetCollectorByClientIdWithBodyWithResponse request with arbitrary body returning *SetCollectorByClientIdResponse
|
||||
func (c *ClientWithResponses) SetCollectorByClientIdWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SetCollectorByClientIdResponse, error) {
|
||||
rsp, err := c.SetCollectorByClientIdWithBody(ctx, id, contentType, body, reqEditors...)
|
||||
if err != nil {
|
||||
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) {
|
||||
rsp, err := c.UpdateCollectorByClientId(ctx, id, body, reqEditors...)
|
||||
func (c *ClientWithResponses) SetCollectorByClientIdWithResponse(ctx context.Context, id openapi_types.UUID, body SetCollectorByClientIdJSONRequestBody, reqEditors ...RequestEditorFn) (*SetCollectorByClientIdResponse, error) {
|
||||
rsp, err := c.SetCollectorByClientId(ctx, id, body, reqEditors...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ParseUpdateCollectorByClientIdResponse(rsp)
|
||||
return ParseSetCollectorByClientIdResponse(rsp)
|
||||
}
|
||||
|
||||
// ListDocumentsByClientIdWithResponse request returning *ListDocumentsByClientIdResponse
|
||||
@@ -1898,15 +1898,15 @@ func ParseGetCollectorByClientIdResponse(rsp *http.Response) (*GetCollectorByCli
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// ParseUpdateCollectorByClientIdResponse parses an HTTP response from a UpdateCollectorByClientIdWithResponse call
|
||||
func ParseUpdateCollectorByClientIdResponse(rsp *http.Response) (*UpdateCollectorByClientIdResponse, error) {
|
||||
// ParseSetCollectorByClientIdResponse parses an HTTP response from a SetCollectorByClientIdWithResponse call
|
||||
func ParseSetCollectorByClientIdResponse(rsp *http.Response) (*SetCollectorByClientIdResponse, error) {
|
||||
bodyBytes, err := io.ReadAll(rsp.Body)
|
||||
defer func() { _ = rsp.Body.Close() }()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response := &UpdateCollectorByClientIdResponse{
|
||||
response := &SetCollectorByClientIdResponse{
|
||||
Body: bodyBytes,
|
||||
HTTPResponse: rsp,
|
||||
}
|
||||
|
||||
@@ -246,20 +246,20 @@ paths:
|
||||
"400":
|
||||
description: Invalid body.
|
||||
patch:
|
||||
operationId: updateCollectorByClientId
|
||||
operationId: setCollectorByClientId
|
||||
tags:
|
||||
- CollectorService
|
||||
summary: Update a collector
|
||||
description: Updates an existing collector with new details.
|
||||
summary: Set a collector
|
||||
description: Set client collector with new details.
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/CollectorUpdate"
|
||||
$ref: "#/components/schemas/CollectorSet"
|
||||
responses:
|
||||
"204":
|
||||
description: Collector updated successfully.
|
||||
description: Collector set successfully.
|
||||
"400":
|
||||
description: Invalid request body.
|
||||
|
||||
@@ -573,7 +573,7 @@ components:
|
||||
- latest_version
|
||||
- active_version
|
||||
|
||||
CollectorUpdate:
|
||||
CollectorSet:
|
||||
type: object
|
||||
properties:
|
||||
minimum_cleaner_version:
|
||||
|
||||
@@ -174,8 +174,8 @@ func TestProcess(t *testing.T) {
|
||||
RequiredQueries: &[]types.UUID{contextQueryRes.JSON201.Id},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
newActiveVersion := int32(2)
|
||||
_, err = qService.UpdateCollectorByClientIdWithResponse(ctx, clientRes.JSON201.Id, queryservice.CollectorUpdate{
|
||||
newActiveVersion := int32(1)
|
||||
_, err = qService.SetCollectorByClientIdWithResponse(ctx, clientRes.JSON201.Id, queryservice.CollectorSet{
|
||||
ActiveVersion: &newActiveVersion,
|
||||
Fields: &[]queryservice.CollectorField{
|
||||
{
|
||||
|
||||
@@ -80,20 +80,20 @@ func TestCollectorService(t *testing.T) {
|
||||
collRes, err := client.GetCollectorByClientIdWithResponse(ctx, id)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, id, collRes.JSON200.ClientId)
|
||||
assert.Equal(t, int32(1), collRes.JSON200.ActiveVersion)
|
||||
assert.Equal(t, int32(1), collRes.JSON200.LatestVersion)
|
||||
assert.Equal(t, int32(0), collRes.JSON200.ActiveVersion)
|
||||
assert.Equal(t, int32(0), collRes.JSON200.LatestVersion)
|
||||
assert.Equal(t, int32(0), collRes.JSON200.MinimumCleanerVersion)
|
||||
assert.Equal(t, int32(0), collRes.JSON200.MinimumTextVersion)
|
||||
assert.Len(t, collRes.JSON200.Fields, 0)
|
||||
|
||||
av := int32(2)
|
||||
av := int32(1)
|
||||
fields := []queryservice.CollectorField{
|
||||
{
|
||||
Name: "json",
|
||||
QueryId: jsonRes.JSON201.Id,
|
||||
},
|
||||
}
|
||||
uRes, err := client.UpdateCollectorByClientIdWithResponse(ctx, id, queryservice.CollectorUpdate{
|
||||
uRes, err := client.SetCollectorByClientIdWithResponse(ctx, id, queryservice.CollectorSet{
|
||||
ActiveVersion: &av,
|
||||
Fields: &fields,
|
||||
})
|
||||
@@ -106,8 +106,8 @@ func TestCollectorService(t *testing.T) {
|
||||
collRes, err = client.GetCollectorByClientIdWithResponse(ctx, id)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, id, collRes.JSON200.ClientId)
|
||||
assert.Equal(t, int32(2), collRes.JSON200.ActiveVersion)
|
||||
assert.Equal(t, int32(2), collRes.JSON200.LatestVersion)
|
||||
assert.Equal(t, int32(1), collRes.JSON200.ActiveVersion)
|
||||
assert.Equal(t, int32(1), collRes.JSON200.LatestVersion)
|
||||
assert.Equal(t, int32(0), collRes.JSON200.MinimumCleanerVersion)
|
||||
assert.Equal(t, int32(0), collRes.JSON200.MinimumTextVersion)
|
||||
assert.Len(t, collRes.JSON200.Fields, 1)
|
||||
|
||||
Reference in New Issue
Block a user