Merged in feature/CollectorBuildVersion (pull request #100)
Collector Build Version * lint * fixtests
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
"queryorchestration/internal/serviceconfig/build"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"github.com/google/uuid"
|
||||
@@ -121,7 +122,7 @@ func (s *Service) clean(ctx context.Context, id uuid.UUID) error {
|
||||
|
||||
func (s *Service) storeClean(ctx context.Context, id uuid.UUID, out *ExecuteCleanResponse) error {
|
||||
docId := database.MustToDBUUID(id)
|
||||
version := s.svc.Version.GetVersion()
|
||||
version := build.GetVersionUnixTimestamp()
|
||||
|
||||
params := &repository.AddDocumentCleanParams{
|
||||
Documentid: docId,
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
cleanversion "queryorchestration/internal/document/clean/version"
|
||||
objectstoremock "queryorchestration/mocks/objectstore"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -34,9 +33,6 @@ func TestClean(t *testing.T) {
|
||||
|
||||
svc := Service{
|
||||
cfg: cfg,
|
||||
svc: &Services{
|
||||
Version: cleanversion.New(cfg),
|
||||
},
|
||||
}
|
||||
|
||||
doc := document.Document{
|
||||
@@ -75,7 +71,7 @@ func TestClean(t *testing.T) {
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(cleanid),
|
||||
)
|
||||
pool.ExpectExec("name: AddDocumentCleanEntry :exec").WithArgs(cleanid, int32(1)).
|
||||
pool.ExpectExec("name: AddDocumentCleanEntry :exec").WithArgs(cleanid, pgxmock.AnyArg()).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
@@ -175,9 +171,6 @@ func TestStoreClean(t *testing.T) {
|
||||
|
||||
svc := Service{
|
||||
cfg: cfg,
|
||||
svc: &Services{
|
||||
Version: cleanversion.New(cfg),
|
||||
},
|
||||
}
|
||||
|
||||
doc := document.Document{
|
||||
@@ -210,7 +203,7 @@ func TestStoreClean(t *testing.T) {
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(cleanid),
|
||||
)
|
||||
pool.ExpectExec("name: AddDocumentCleanEntry :exec").WithArgs(cleanid, int32(1)).
|
||||
pool.ExpectExec("name: AddDocumentCleanEntry :exec").WithArgs(cleanid, pgxmock.AnyArg()).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
@@ -233,7 +226,7 @@ func TestStoreClean(t *testing.T) {
|
||||
pool.ExpectQuery("name: GetMostRecentDocumentCleanEntry :one").WithArgs(dbid).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}).
|
||||
AddRow(database.MustToDBUUID(uuid.New()), dbid, nil, nil, int32(1), nil, repository.CleanfailtypeInvalidRead),
|
||||
AddRow(database.MustToDBUUID(uuid.New()), dbid, nil, nil, int64(1), nil, repository.CleanfailtypeInvalidRead),
|
||||
)
|
||||
cleanid := database.MustToDBUUID(uuid.New())
|
||||
pool.ExpectQuery("name: AddDocumentClean :one").WithArgs(dbid, &inloc.Bucket, &inloc.Key, dbmimetype, repository.NullCleanfailtype{}).
|
||||
@@ -241,7 +234,7 @@ func TestStoreClean(t *testing.T) {
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(cleanid),
|
||||
)
|
||||
pool.ExpectExec("name: AddDocumentCleanEntry :exec").WithArgs(cleanid, int32(1)).
|
||||
pool.ExpectExec("name: AddDocumentCleanEntry :exec").WithArgs(cleanid, pgxmock.AnyArg()).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
@@ -260,12 +253,12 @@ func TestStoreClean(t *testing.T) {
|
||||
pool.ExpectQuery("name: GetMostRecentDocumentCleanEntry :one").WithArgs(dbid).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}).
|
||||
AddRow(cleanid, dbid, nil, nil, int32(1), nil, repository.NullCleanfailtype{
|
||||
AddRow(cleanid, dbid, nil, nil, int64(1), nil, repository.NullCleanfailtype{
|
||||
Valid: true,
|
||||
Cleanfailtype: repository.CleanfailtypeInvalidMimetype,
|
||||
}),
|
||||
)
|
||||
pool.ExpectExec("name: AddDocumentCleanEntry :exec").WithArgs(cleanid, int32(1)).
|
||||
pool.ExpectExec("name: AddDocumentCleanEntry :exec").WithArgs(cleanid, pgxmock.AnyArg()).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/document"
|
||||
cleanversion "queryorchestration/internal/document/clean/version"
|
||||
objectstoremock "queryorchestration/mocks/objectstore"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
@@ -25,9 +24,6 @@ func TestGetContent(t *testing.T) {
|
||||
|
||||
svc := Service{
|
||||
cfg: cfg,
|
||||
svc: &Services{
|
||||
Version: cleanversion.New(cfg),
|
||||
},
|
||||
}
|
||||
|
||||
inloc := document.Location{
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
cleanversion "queryorchestration/internal/document/clean/version"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/serviceconfig/objectstore"
|
||||
"queryorchestration/internal/serviceconfig/queue/documenttext"
|
||||
@@ -49,9 +48,6 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
svc := Service{
|
||||
cfg: cfg,
|
||||
svc: &Services{
|
||||
Version: cleanversion.New(cfg),
|
||||
},
|
||||
}
|
||||
|
||||
doc := document.Document{
|
||||
@@ -94,7 +90,7 @@ func TestCreate(t *testing.T) {
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(cleanid),
|
||||
)
|
||||
pool.ExpectExec("name: AddDocumentCleanEntry :exec").WithArgs(cleanid, int32(1)).
|
||||
pool.ExpectExec("name: AddDocumentCleanEntry :exec").WithArgs(cleanid, pgxmock.AnyArg()).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package documentclean
|
||||
|
||||
import (
|
||||
cleanversion "queryorchestration/internal/document/clean/version"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/serviceconfig/objectstore"
|
||||
"queryorchestration/internal/serviceconfig/queue/documenttext"
|
||||
@@ -13,18 +12,12 @@ type ConfigProvider interface {
|
||||
objectstore.ConfigProvider
|
||||
}
|
||||
|
||||
type Services struct {
|
||||
Version *cleanversion.Service
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
cfg ConfigProvider
|
||||
svc *Services
|
||||
}
|
||||
|
||||
func New(cfg ConfigProvider, svc *Services) *Service {
|
||||
func New(cfg ConfigProvider) *Service {
|
||||
return &Service{
|
||||
cfg: cfg,
|
||||
svc: svc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,6 @@ type DocCleanConfig struct {
|
||||
|
||||
func TestService(t *testing.T) {
|
||||
cfg := &DocCleanConfig{}
|
||||
svc := documentclean.New(cfg, nil)
|
||||
svc := documentclean.New(cfg)
|
||||
assert.NotNil(t, svc)
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package cleanversion
|
||||
|
||||
import (
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
cfg serviceconfig.ConfigProvider
|
||||
}
|
||||
|
||||
func New(cfg serviceconfig.ConfigProvider) *Service {
|
||||
return &Service{
|
||||
cfg,
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package cleanversion_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
cleanversion "queryorchestration/internal/document/clean/version"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
svc := cleanversion.New(nil)
|
||||
assert.NotNil(t, svc)
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package cleanversion
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (s *Service) GetVersion() int32 {
|
||||
return 1
|
||||
}
|
||||
|
||||
func (s *Service) IsValidVersion(v int32) error {
|
||||
currentVersion := s.GetVersion()
|
||||
|
||||
if v < 1 || v > currentVersion {
|
||||
return fmt.Errorf("document clean code version must be in the range 0 < version <= %d", currentVersion)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package cleanversion_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
cleanversion "queryorchestration/internal/document/clean/version"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIsValidVersion(t *testing.T) {
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
svc := cleanversion.New(cfg)
|
||||
|
||||
assert.Nil(t, svc.IsValidVersion(1))
|
||||
assert.Error(t, svc.IsValidVersion(2))
|
||||
assert.Error(t, svc.IsValidVersion(0))
|
||||
assert.Error(t, svc.IsValidVersion(-1))
|
||||
}
|
||||
|
||||
func TestGetVersion(t *testing.T) {
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
svc := cleanversion.New(cfg)
|
||||
|
||||
assert.Equal(t, int32(1), svc.GetVersion())
|
||||
}
|
||||
Reference in New Issue
Block a user