From 83ad91416d972e671d61da55d77a8a33ba269ff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Mon, 30 Nov 2020 18:45:03 +0100 Subject: [PATCH] Add base tests for envoy merge algs --- tests/envoy/main.go | 6 +- tests/envoy/provision_overwrite_test.go | 87 +++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 tests/envoy/provision_overwrite_test.go diff --git a/tests/envoy/main.go b/tests/envoy/main.go index 033826d90..139750708 100644 --- a/tests/envoy/main.go +++ b/tests/envoy/main.go @@ -72,7 +72,11 @@ func dd(ctx context.Context, suite string) ([]resource.Interface, error) { } func encode(ctx context.Context, s store.Storer, nn []resource.Interface) error { - se := es.NewStoreEncoder(s, nil) + return encodeC(ctx, s, nn, nil) +} + +func encodeC(ctx context.Context, s store.Storer, nn []resource.Interface, cfg *es.EncoderConfig) error { + se := es.NewStoreEncoder(s, cfg) bld := envoy.NewBuilder(se) g, err := bld.Build(ctx, nn...) if err != nil { diff --git a/tests/envoy/provision_overwrite_test.go b/tests/envoy/provision_overwrite_test.go new file mode 100644 index 000000000..12448f71a --- /dev/null +++ b/tests/envoy/provision_overwrite_test.go @@ -0,0 +1,87 @@ +package envoy + +import ( + "context" + "testing" + + su "github.com/cortezaproject/corteza-server/pkg/envoy/store" + "github.com/cortezaproject/corteza-server/store" + "github.com/stretchr/testify/require" +) + +func TestProvision_overwriting(t *testing.T) { + var ( + ctx = context.Background() + s, err = initStore(ctx) + ) + + if err != nil { + t.Fatalf("failed to init sqlite in-memory db: %v", err) + } + + ni := uint64(0) + su.NextID = func() uint64 { + ni++ + return ni + } + + prepare := func(ctx context.Context, s store.Storer, t *testing.T, suite string, cfg *su.EncoderConfig) (*require.Assertions, error) { + req := require.New(t) + + nn, err := dd(ctx, suite) + req.NoError(err) + + return req, encodeC(ctx, s, nn, cfg) + } + + // Prepare + s, err = initStore(ctx) + err = ce( + err, + + s.TruncateUsers(ctx), + s.TruncateRoles(ctx), + s.TruncateRbacRules(ctx), + s.TruncateActionlogs(ctx), + s.TruncateApplications(ctx), + s.TruncateAttachments(ctx), + s.TruncateComposeAttachments(ctx), + s.TruncateComposeCharts(ctx), + s.TruncateComposeNamespaces(ctx), + s.TruncateComposeModules(ctx), + s.TruncateComposeModuleFields(ctx), + s.TruncateComposePages(ctx), + s.TruncateComposeRecords(ctx, nil), + + storeRole(ctx, s, 1, "everyone"), + storeRole(ctx, s, 2, "admins"), + ) + if err != nil { + t.Fatal(err.Error()) + } + + // Prepare + req, err := prepare(ctx, s, t, "provision_batch/app_1", nil) + req.NoError(err) + store.TruncateComposeRecords(ctx, s, nil) + + req, err = prepare(ctx, s, t, "provision_batch/app_1", &su.EncoderConfig{OnExisting: su.Replace}) + req.NoError(err) + checkBatchProvision(ctx, t, req, s, "ns1") + store.TruncateComposeRecords(ctx, s, nil) + + req, err = prepare(ctx, s, t, "provision_batch/app_1", &su.EncoderConfig{OnExisting: su.Skip}) + req.NoError(err) + checkBatchProvision(ctx, t, req, s, "ns1") + store.TruncateComposeRecords(ctx, s, nil) + + req, err = prepare(ctx, s, t, "provision_batch/app_1", &su.EncoderConfig{OnExisting: su.MergeLeft}) + req.NoError(err) + checkBatchProvision(ctx, t, req, s, "ns1") + store.TruncateComposeRecords(ctx, s, nil) + + req, err = prepare(ctx, s, t, "provision_batch/app_1", &su.EncoderConfig{OnExisting: su.MergeRight}) + req.NoError(err) + checkBatchProvision(ctx, t, req, s, "ns1") + store.TruncateComposeRecords(ctx, s, nil) +}