Skip to content

Commit

Permalink
Review comment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jbhamra1 committed Aug 3, 2023
1 parent de574dd commit 02ac64f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 51 deletions.
2 changes: 2 additions & 0 deletions dgraphtest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion dgraphtest/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 1 addition & 6 deletions systest/plugin/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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())
}

Expand Down
57 changes: 28 additions & 29 deletions systest/plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()))
}
})
}
}
22 changes: 7 additions & 15 deletions systest/plugin/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package main
import (
"log"
"testing"
"time"

"github.com/stretchr/testify/suite"

Expand All @@ -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 {
Expand All @@ -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))

Check failure on line 61 in systest/plugin/upgrade_test.go

View workflow job for this annotation

GitHub Actions / dgraph-upgrade-tests

undefined: require
}

func TestPluginTestSuite(t *testing.T) {
Expand Down

0 comments on commit 02ac64f

Please sign in to comment.