From 02ac64ffb65f31a7feb47d7ddf363b6e5720489e Mon Sep 17 00:00:00 2001 From: JASWINDER BHAMRA Date: Wed, 26 Jul 2023 17:22:01 +0530 Subject: [PATCH] Review comment changes --- dgraphtest/config.go | 2 ++ dgraphtest/image.go | 3 +- systest/plugin/integration_test.go | 7 +--- systest/plugin/plugin_test.go | 57 +++++++++++++++--------------- systest/plugin/upgrade_test.go | 22 ++++-------- 5 files changed, 40 insertions(+), 51 deletions(-) diff --git a/dgraphtest/config.go b/dgraphtest/config.go index 1bc889cc1dd..7ac6ceb2fe9 100644 --- a/dgraphtest/config.go +++ b/dgraphtest/config.go @@ -188,6 +188,8 @@ func (cc ClusterConfig) WithGraphqlLambdaURL(url string) ClusterConfig { cc.lambdaURL = url return cc } + +// Enables generation of the custom_plugins in testutil/custom_plugins func (cc ClusterConfig) WithCustomPlugins() ClusterConfig { cc.customPlugins = true return cc diff --git a/dgraphtest/image.go b/dgraphtest/image.go index 8ca9e00b771..972911bcab9 100644 --- a/dgraphtest/image.go +++ b/dgraphtest/image.go @@ -25,8 +25,9 @@ import ( "path/filepath" "strings" - "github.com/dgraph-io/dgraph/testutil" "github.com/pkg/errors" + + "github.com/dgraph-io/dgraph/testutil" ) func (c *LocalCluster) dgraphImage() string { diff --git a/systest/plugin/integration_test.go b/systest/plugin/integration_test.go index 843dea293f9..267ac4c00bc 100644 --- a/systest/plugin/integration_test.go +++ b/systest/plugin/integration_test.go @@ -19,20 +19,17 @@ package main import ( - "context" "testing" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "github.com/dgraph-io/dgraph/dgraphtest" - "github.com/dgraph-io/dgraph/x" ) type PluginTestSuite struct { suite.Suite - dc dgraphtest.Cluster - dataSetNdx int + dc dgraphtest.Cluster } func (psuite *PluginTestSuite) SetupTest() { @@ -44,8 +41,6 @@ func (psuite *PluginTestSuite) TearDownTest() { gcli, cleanup, err := psuite.dc.Client() require.NoError(t, err) defer cleanup() - require.NoError(t, gcli.LoginIntoNamespace(context.Background(), - dgraphtest.DefaultUser, dgraphtest.DefaultPassword, x.GalaxyNamespace)) require.NoError(t, gcli.DropAll()) } diff --git a/systest/plugin/plugin_test.go b/systest/plugin/plugin_test.go index 48c6d4a24f3..8b207d33893 100644 --- a/systest/plugin/plugin_test.go +++ b/systest/plugin/plugin_test.go @@ -28,7 +28,6 @@ import ( "github.com/dgraph-io/dgo/v230/protos/api" "github.com/dgraph-io/dgraph/dgraphtest" - "github.com/dgraph-io/dgraph/x" ) type testCase struct { @@ -316,36 +315,36 @@ func (psuite *PluginTestSuite) TestPlugins() { } for i := 0; i < len(testInp); i++ { - psuite.dataSetNdx = i - psuite.Run(fmt.Sprintf("test case %d", i+1), psuite.pluginFn) - } -} + psuite.Run(fmt.Sprintf("test case %d", i+1), func() { + t := psuite.T() + gcli, cleanup, err := psuite.dc.Client() + require.NoError(t, err) + defer cleanup() + require.NoError(t, gcli.DropAll()) + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + require.NoError(t, gcli.Alter(ctx, &api.Operation{ + Schema: testInp[i].initialSchema, + })) -func (psuite *PluginTestSuite) pluginFn() { - t := psuite.T() - gcli, cleanup, err := psuite.dc.Client() - require.NoError(t, err) - defer cleanup() - require.NoError(t, gcli.LoginIntoNamespace(context.Background(), - dgraphtest.DefaultUser, dgraphtest.DefaultPassword, x.GalaxyNamespace)) - require.NoError(t, gcli.DropAll()) - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() - fmt.Printf("\ndataSetNdx = %d\n", psuite.dataSetNdx) - fmt.Printf("\ntestInp[psuite.dataSetNdx].initialSchema = [%s]\n", testInp[psuite.dataSetNdx].initialSchema) - require.NoError(t, gcli.Alter(ctx, &api.Operation{ - Schema: testInp[psuite.dataSetNdx].initialSchema, - })) + txn := gcli.NewTxn() + _, err = txn.Mutate(ctx, &api.Mutation{SetJson: []byte(testInp[i].setJSON)}) + require.NoError(t, err) + require.NoError(t, txn.Commit(ctx)) + + // Upgrade + psuite.Upgrade() - txn := gcli.NewTxn() - _, err = txn.Mutate(ctx, &api.Mutation{SetJson: []byte(testInp[psuite.dataSetNdx].setJSON)}) - require.NoError(t, err) - require.NoError(t, txn.Commit(ctx)) + gcli, cleanup, err = psuite.dc.Client() + require.NoError(t, err) + defer cleanup() - for _, test := range testInp[psuite.dataSetNdx].cases { - txn := gcli.NewTxn() - reply, err := txn.Query(ctx, test.query) - require.NoError(t, err) - dgraphtest.CompareJSON(test.wantResult, string(reply.GetJson())) + for _, test := range testInp[i].cases { + txn := gcli.NewTxn() + reply, err := txn.Query(ctx, test.query) + require.NoError(t, err) + dgraphtest.CompareJSON(test.wantResult, string(reply.GetJson())) + } + }) } } diff --git a/systest/plugin/upgrade_test.go b/systest/plugin/upgrade_test.go index 281ce78e68c..a98429b682d 100644 --- a/systest/plugin/upgrade_test.go +++ b/systest/plugin/upgrade_test.go @@ -21,7 +21,6 @@ package main import ( "log" "testing" - "time" "github.com/stretchr/testify/suite" @@ -31,21 +30,18 @@ import ( type PluginTestSuite struct { suite.Suite - dc dgraphtest.Cluster - lc *dgraphtest.LocalCluster - uc dgraphtest.UpgradeCombo - dataSetNdx int -} - -func (psuite *PluginTestSuite) SetupTest() { + dc dgraphtest.Cluster + lc *dgraphtest.LocalCluster + uc dgraphtest.UpgradeCombo } func (psuite *PluginTestSuite) SetupSubTest() { + // The TestPlugins() invokes subtest function, hence using + // SetupSubTest() instead of SetupTest(). psuite.lc.Cleanup(psuite.T().Failed()) conf := dgraphtest.NewClusterConfig().WithNumAlphas(1).WithNumZeros(1).WithReplicas(1). - WithACL(20 * time.Second).WithEncryption().WithVersion(psuite.uc.Before). - WithCustomPlugins() + WithVersion(psuite.uc.Before).WithCustomPlugins() c, err := dgraphtest.NewLocalCluster(conf) x.Panic(err) if err := c.Start(); err != nil { @@ -62,11 +58,7 @@ func (psuite *PluginTestSuite) TearDownTest() { } func (psuite *PluginTestSuite) Upgrade() { - t := psuite.T() - - if err := psuite.lc.Upgrade(psuite.uc.After, psuite.uc.Strategy); err != nil { - t.Fatal(err) - } + require.NoError(psuite.T(), psuite.lc.Upgrade(psuite.uc.After, psuite.uc.Strategy)) } func TestPluginTestSuite(t *testing.T) {