Merged in feature/jobcollector (pull request #30)
Initial Job Collector (changes pending) * movearroundtocleancollector * internalgetfunctions * completecollectorquery * simplify * fixtests * addvendor * noplaceholder
This commit is contained in:
@@ -1,32 +1,23 @@
|
||||
package queryservice_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
queryservice "queryorchestration/api/queryService"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/job/collector"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/google/uuid"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCreateJobCollector(t *testing.T) {
|
||||
e := echo.New()
|
||||
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(""))
|
||||
rec := httptest.NewRecorder()
|
||||
ctx := e.NewContext(req, rec)
|
||||
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{})
|
||||
|
||||
err := cons.CreateJobCollector(ctx)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, http.StatusOK, rec.Code)
|
||||
assert.NotEmpty(t, rec.Body.String())
|
||||
}
|
||||
|
||||
func TestUpdateJobCollector(t *testing.T) {
|
||||
e := echo.New()
|
||||
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(""))
|
||||
@@ -37,24 +28,59 @@ func TestUpdateJobCollector(t *testing.T) {
|
||||
|
||||
id := uuid.New()
|
||||
|
||||
err := cons.UpdateJobCollector(ctx, id.String())
|
||||
err := cons.UpdateJobCollectorByJobId(ctx, id.String())
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, http.StatusOK, rec.Code)
|
||||
assert.NotEmpty(t, rec.Body.String())
|
||||
}
|
||||
|
||||
func TestGetJobCollector(t *testing.T) {
|
||||
func TestGetJobCollectorByJobId(t *testing.T) {
|
||||
pool, err := pgxmock.NewPool()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
|
||||
e := echo.New()
|
||||
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(""))
|
||||
rec := httptest.NewRecorder()
|
||||
ctx := e.NewContext(req, rec)
|
||||
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{})
|
||||
svc := collector.New(db)
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
JobCollector: svc,
|
||||
})
|
||||
|
||||
id := uuid.New()
|
||||
coll := collector.Collector{
|
||||
ID: uuid.New(),
|
||||
JobID: uuid.New(),
|
||||
MinCleanVersion: int32(1),
|
||||
MinTextVersion: int32(2),
|
||||
}
|
||||
|
||||
err := cons.GetJobCollectorById(ctx, id.String())
|
||||
pool.ExpectQuery("name: GetCollectorByJobID :one").WithArgs(database.MustToDBUUID(coll.JobID)).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "jobId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
|
||||
AddRow(database.MustToDBUUID(coll.ID), database.MustToDBUUID(coll.JobID), coll.MinCleanVersion, coll.MinTextVersion, int32(1), int32(2), []byte("")),
|
||||
)
|
||||
|
||||
err = cons.GetJobCollectorByJobId(ctx, coll.JobID.String())
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, http.StatusOK, rec.Code)
|
||||
assert.NotEmpty(t, rec.Body.String())
|
||||
|
||||
var res queryservice.JobCollector
|
||||
err = json.Unmarshal(rec.Body.Bytes(), &res)
|
||||
assert.Nil(t, err)
|
||||
assert.EqualExportedValues(t, queryservice.JobCollector{
|
||||
JobId: coll.JobID.String(),
|
||||
MinimumCleanerVersion: coll.MinCleanVersion,
|
||||
MinimumTextVersion: coll.MinTextVersion,
|
||||
ActiveVersion: int32(1),
|
||||
LatestVersion: int32(2),
|
||||
Fields: []queryservice.JobCollectorField{},
|
||||
}, res)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user