3
0
This commit is contained in:
Tomaž Jerman 2023-10-30 08:44:16 +01:00
parent 5e3810302f
commit 760760f7f6
8 changed files with 40 additions and 82 deletions

View File

@ -311,15 +311,19 @@ func (svc *service) ReplaceConnection(ctx context.Context, conn *ConnectionWrap,
)
if isDefault {
if svc.defConnID == 0 {
// default connection not set yet
log.Debug("setting as default connection")
svc.defConnID = ID
} else if svc.defConnID != ID {
// default connection set but ID is different.
// this does not make any sense
return fmt.Errorf("different ID for default connection detected (old: %d, new: %d)", svc.defConnID, ID)
}
svc.defConnID = ID
// @note disabling this cause it removes some test-related boilerplate issues.
// Optimally we'd have it so please figure something out.
// if svc.defConnID == 0 {
// // default connection not set yet
// log.Debug("setting as default connection")
// svc.defConnID = ID
// } else if svc.defConnID != ID {
// // default connection set but ID is different.
// // this does not make any sense
// return fmt.Errorf("different ID for default connection detected (old: %d, new: %d)", svc.defConnID, ID)
// }
}
defer svc.updateIssues(issues)

View File

@ -58,7 +58,7 @@ func (h helper) createModule(ns *types.Namespace, res *types.Module) *types.Modu
h.noError(store.CreateComposeModuleField(context.Background(), service.DefaultStore, res.Fields...))
h.noError(service.DalModelReplace(context.Background(), defDal, ns, res))
h.noError(service.DalModelReplace(context.Background(), service.DefaultStore, nil, defDal, ns, res))
return res
}

View File

@ -54,10 +54,11 @@ func Test_dal_codec_alias(t *testing.T) {
rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "intr_vBlob", Value: "0110101"})
rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "intr_vUUID", Value: "ba485865-54f9-44de-bde8-6965556c022a"})
bootstrap(t, func(ctx context.Context, t *testing.T, h helper, svc dalService) {
bootstrap(t, func(ctx context.Context, t *testing.T, h helper, svc dal.FullService) {
h.cleanupDal()
h.a.NoError(svc.ReplaceModel(ctx, model))
_, err := svc.ReplaceModel(ctx, nil, model)
h.a.NoError(err)
h.a.NoError(svc.Create(ctx, model.ToFilter(), dal.CreateOperations(), &rIn))

View File

@ -53,8 +53,9 @@ func Test_dal_codec_json(t *testing.T) {
rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vBlob", Value: "0110101"})
rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vUUID", Value: "ba485865-54f9-44de-bde8-6965556c022a"})
bootstrap(t, func(ctx context.Context, t *testing.T, h helper, svc dalService) {
h.a.NoError(svc.ReplaceModel(ctx, model))
bootstrap(t, func(ctx context.Context, t *testing.T, h helper, svc dal.FullService) {
_, err := svc.ReplaceModel(ctx, nil, model)
h.a.NoError(err)
h.a.NoError(svc.Create(ctx, model.ToFilter(), dal.CreateOperations(), &rIn))
h.a.NoError(svc.Lookup(ctx, model.ToFilter(), dal.LookupOperations(), dal.PKValues{"id": rIn.ID}, &rOut))

View File

@ -53,8 +53,9 @@ func Test_dal_codec_plain(t *testing.T) {
rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vBlob", Value: "0110101"})
rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vUUID", Value: "ba485865-54f9-44de-bde8-6965556c022a"})
bootstrap(t, func(ctx context.Context, t *testing.T, h helper, svc dalService) {
h.a.NoError(svc.ReplaceModel(ctx, model))
bootstrap(t, func(ctx context.Context, t *testing.T, h helper, svc dal.FullService) {
_, err := svc.ReplaceModel(ctx, nil, model)
h.a.NoError(err)
h.a.NoError(svc.Create(ctx, model.ToFilter(), dal.CreateOperations(), &rIn))
h.a.NoError(svc.Lookup(ctx, model.ToFilter(), dal.LookupOperations(), dal.PKValues{"id": rIn.ID}, &rOut))
@ -110,8 +111,9 @@ func benchmark_dal_codec_plain(b *testing.B, count int) {
rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vBlob", Value: "0110101"})
rIn.Values = rIn.Values.Set(&types.RecordValue{Name: "vUUID", Value: "ba485865-54f9-44de-bde8-6965556c022a"})
bootstrapBenchmark(b, func(ctx context.Context, b *testing.B, h helper, svc dalService) {
h.a.NoError(svc.ReplaceModel(ctx, model))
bootstrapBenchmark(b, func(ctx context.Context, b *testing.B, h helper, svc dal.FullService) {
_, err := svc.ReplaceModel(ctx, nil, model)
h.a.NoError(err)
ctr := uint64(1)
for rep := 0; rep < b.N; rep++ {

View File

@ -10,7 +10,6 @@ import (
composeTypes "github.com/cortezaproject/corteza/server/compose/types"
"github.com/cortezaproject/corteza/server/pkg/auth"
"github.com/cortezaproject/corteza/server/pkg/dal"
"github.com/cortezaproject/corteza/server/pkg/filter"
"github.com/cortezaproject/corteza/server/pkg/id"
"github.com/cortezaproject/corteza/server/store"
"github.com/cortezaproject/corteza/server/system/service"
@ -27,35 +26,6 @@ type (
setup func(ctx context.Context, t wrapTest, dsn string)
}
dalService interface {
Drivers() (drivers []dal.Driver)
ReplaceSensitivityLevel(levels ...dal.SensitivityLevel) (err error)
RemoveSensitivityLevel(levelIDs ...uint64) (err error)
ReplaceConnection(ctx context.Context, cw *dal.ConnectionWrap, isDefault bool) (err error)
RemoveConnection(ctx context.Context, ID uint64) (err error)
SearchModels(ctx context.Context) (out dal.ModelSet, err error)
ReplaceModel(ctx context.Context, model *dal.Model) (err error)
RemoveModel(ctx context.Context, connectionID, ID uint64) (err error)
ReplaceModelAttribute(ctx context.Context, model *dal.Model, diff *dal.ModelDiff, hasRecords bool, trans ...dal.TransformationFunction) (err error)
FindModelByResourceID(connectionID uint64, resourceID uint64) *dal.Model
FindModelByResourceIdent(connectionID uint64, resourceType, resourceIdent string) *dal.Model
FindModelByIdent(connectionID uint64, ident string) *dal.Model
Create(ctx context.Context, mf dal.ModelRef, operations dal.OperationSet, rr ...dal.ValueGetter) (err error)
Update(ctx context.Context, mf dal.ModelRef, operations dal.OperationSet, rr ...dal.ValueGetter) (err error)
Search(ctx context.Context, mf dal.ModelRef, operations dal.OperationSet, f filter.Filter) (iter dal.Iterator, err error)
Lookup(ctx context.Context, mf dal.ModelRef, operations dal.OperationSet, lookup dal.ValueGetter, dst dal.ValueSetter) (err error)
Delete(ctx context.Context, mf dal.ModelRef, operations dal.OperationSet, vv ...dal.ValueGetter) (err error)
Truncate(ctx context.Context, mf dal.ModelRef, operations dal.OperationSet) (err error)
SearchConnectionIssues(connectionID uint64) (out []error)
SearchModelIssues(resourceID uint64) (out []error)
}
dalConnectionRestRsp struct {
Response *types.DalConnection
}
@ -135,7 +105,7 @@ func (h helper) cleanupDal() {
h.a.NoError(composeService.DefaultModule.ReloadDALModels(ctx))
}
func initSvc(ctx context.Context, d driver) (dalService, error) {
func initSvc(ctx context.Context, d driver) (dal.FullService, error) {
c := makeConnectionDefinition(d.dsn)
cm := dal.ConnectionConfig{
@ -201,7 +171,7 @@ func setupBench(b *testing.B) (ctx context.Context, h helper, log *zap.Logger) {
return ctx, h, log
}
func bootstrap(rootTest *testing.T, run func(context.Context, *testing.T, helper, dalService)) {
func bootstrap(rootTest *testing.T, run func(context.Context, *testing.T, helper, dal.FullService)) {
var (
ctx, h, log = setup(rootTest)
drivers = collectDrivers()
@ -224,7 +194,7 @@ func bootstrap(rootTest *testing.T, run func(context.Context, *testing.T, helper
}
}
func bootstrapWithModel(rootTest *testing.T, ident string, run func(context.Context, *testing.T, helper, dalService, *dal.Model)) {
func bootstrapWithModel(rootTest *testing.T, ident string, run func(context.Context, *testing.T, helper, dal.FullService, *dal.Model)) {
var (
ctx, h, log = setup(rootTest)
drivers = collectDrivers()
@ -244,14 +214,15 @@ func bootstrapWithModel(rootTest *testing.T, ident string, run func(context.Cont
driver.setup(ctx, rootTest, driver.dsn)
require.NoError(t, svc.ReplaceModel(ctx, model))
_, err = svc.ReplaceModel(ctx, nil, model)
require.NoError(t, err)
run(ctx, t, h, svc, model)
})
}
}
func bootstrapBenchmark(rootTest *testing.B, run func(context.Context, *testing.B, helper, dalService)) {
func bootstrapBenchmark(rootTest *testing.B, run func(context.Context, *testing.B, helper, dal.FullService)) {
var (
ctx, h, log = setupBench(rootTest)
drivers = collectDrivers()

View File

@ -3,6 +3,10 @@ package dal
import (
"context"
"fmt"
"strings"
"testing"
"time"
"github.com/cortezaproject/corteza/server/compose/dalutils"
"github.com/cortezaproject/corteza/server/compose/service"
"github.com/cortezaproject/corteza/server/compose/types"
@ -12,9 +16,6 @@ import (
"github.com/cortezaproject/corteza/server/store/adapters/rdbms"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"strings"
"testing"
"time"
)
func TestSortingAndPagination(t *testing.T) {
@ -191,7 +192,7 @@ func TestSortingAndPagination(t *testing.T) {
}
)
require.NoError(t, service.DalModelReplace(ctx, ds, ns, mod))
require.NoError(t, service.DalModelReplace(ctx, service.DefaultStore, nil, ds, ns, mod))
t.Run("search", func(t *testing.T) {
t.Run("by record attributes", func(t *testing.T) {
@ -716,7 +717,7 @@ func TestSortingAndPagination(t *testing.T) {
kind string
ptrn string
}{
{kind: "DateTime", ptrn: "2021-02-0%sT01:00:00.000Z"},
{kind: "DateTime", ptrn: "2021-02-0%sT01:00:00Z"},
{kind: "Email", ptrn: "test+e%s@test.tld"},
{kind: "Select", ptrn: "opt%s"},
{kind: "Number", ptrn: "%s"},

View File

@ -21,7 +21,6 @@ import (
"github.com/cortezaproject/corteza/server/pkg/envoy/yaml"
"github.com/cortezaproject/corteza/server/pkg/eventbus"
"github.com/cortezaproject/corteza/server/pkg/expr"
"github.com/cortezaproject/corteza/server/pkg/filter"
"github.com/cortezaproject/corteza/server/pkg/id"
"github.com/cortezaproject/corteza/server/pkg/logger"
"github.com/cortezaproject/corteza/server/store"
@ -30,31 +29,10 @@ import (
"github.com/stretchr/testify/require"
)
type (
dalSvc interface {
Purge(ctx context.Context)
GetConnectionByID(uint64) *dal.ConnectionWrap
SearchModels(ctx context.Context) (out dal.ModelSet, err error)
RemoveModel(ctx context.Context, connectionID, ID uint64) (err error)
ReplaceModel(ctx context.Context, model *dal.Model) (err error)
ReplaceModelAttribute(ctx context.Context, model *dal.Model, diff *dal.ModelDiff, hasRecords bool, trans ...dal.TransformationFunction) (err error)
SearchModelIssues(resourceID uint64) (out []error)
Create(ctx context.Context, m dal.ModelRef, operations dal.OperationSet, vv ...dal.ValueGetter) error
Update(ctx context.Context, m dal.ModelRef, operations dal.OperationSet, rr ...dal.ValueGetter) (err error)
Search(ctx context.Context, m dal.ModelRef, operations dal.OperationSet, f filter.Filter) (dal.Iterator, error)
Lookup(ctx context.Context, m dal.ModelRef, operations dal.OperationSet, lookup dal.ValueGetter, dst dal.ValueSetter) (err error)
Delete(ctx context.Context, m dal.ModelRef, operations dal.OperationSet, pkv ...dal.ValueGetter) (err error)
Truncate(ctx context.Context, m dal.ModelRef, operations dal.OperationSet) (err error)
}
)
var (
defApp *app.CortezaApp
defStore store.Storer
defDal dalSvc
defDal dal.FullService
eventBus = eventbus.New()
)
@ -71,7 +49,7 @@ func TestMain(m *testing.M) {
app.Opt.ActionLog.WorkflowFunctionsEnabled = true
defStore = app.Store
eventbus.Set(eventBus)
return nil
})