Skip to content

Commit 60d1c13

Browse files
authored
Rename z package to testutil. (#3730)
Ristretto will be using the z package from now on so the z package in dgrpah (containing utility functions used in tests) is being renamed to testutil.
1 parent 2d0f950 commit 60d1c13

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+240
-240
lines changed

contrib/integration/acctupsert/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
"github.com/dgraph-io/dgo/protos/api"
3232
"github.com/dgraph-io/dgo/x"
3333
"github.com/dgraph-io/dgo/y"
34-
"github.com/dgraph-io/dgraph/z"
34+
"github.com/dgraph-io/dgraph/testutil"
3535
)
3636

3737
var (
@@ -70,7 +70,7 @@ func init() {
7070

7171
func main() {
7272
flag.Parse()
73-
c := z.DgraphClientWithGroot(*alpha)
73+
c := testutil.DgraphClientWithGroot(*alpha)
7474
setup(c)
7575
fmt.Println("Doing upserts")
7676
doUpserts(c)

contrib/integration/swap/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
"github.com/dgraph-io/dgo"
3232
"github.com/dgraph-io/dgo/protos/api"
3333
"github.com/dgraph-io/dgo/x"
34-
"github.com/dgraph-io/dgraph/z"
34+
"github.com/dgraph-io/dgraph/testutil"
3535
)
3636

3737
var (
@@ -78,7 +78,7 @@ func main() {
7878
fmt.Printf("%15s: %3d\n", w.word, w.count)
7979
}
8080

81-
c := z.DgraphClientWithGroot(*alpha)
81+
c := testutil.DgraphClientWithGroot(*alpha)
8282
uids := setup(c, sents)
8383

8484
// Check invariants before doing any mutations as a sanity check.

contrib/integration/testtxn/main_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626

2727
"github.com/dgraph-io/dgo"
2828
"github.com/dgraph-io/dgo/protos/api"
29+
"github.com/dgraph-io/dgraph/testutil"
2930
"github.com/dgraph-io/dgraph/x"
30-
"github.com/dgraph-io/dgraph/z"
3131
"github.com/stretchr/testify/assert"
3232
"github.com/stretchr/testify/require"
3333
"google.golang.org/grpc"
@@ -38,12 +38,12 @@ type state struct {
3838
}
3939

4040
var s state
41-
var addr string = z.SockAddr
41+
var addr string = testutil.SockAddr
4242

4343
func TestMain(m *testing.M) {
4444
log.SetFlags(log.LstdFlags | log.Lshortfile)
45-
z.AssignUids(200)
46-
dg := z.DgraphClientWithGroot(z.SockAddr)
45+
testutil.AssignUids(200)
46+
dg := testutil.DgraphClientWithGroot(testutil.SockAddr)
4747
s.dg = dg
4848

4949
r := m.Run()
@@ -708,8 +708,8 @@ query countAnswers($num: int) {
708708
)
709709

710710
func TestCountIndexConcurrentTxns(t *testing.T) {
711-
dg := z.DgraphClientWithGroot(z.SockAddr)
712-
z.DropAll(t, dg)
711+
dg := testutil.DgraphClientWithGroot(testutil.SockAddr)
712+
testutil.DropAll(t, dg)
713713
alterSchema(dg, "answer: [uid] @count .")
714714

715715
// Expected edge count of 0x100: 1
@@ -764,8 +764,8 @@ func TestCountIndexConcurrentTxns(t *testing.T) {
764764
}
765765

766766
func TestCountIndexSerialTxns(t *testing.T) {
767-
dg := z.DgraphClientWithGroot(z.SockAddr)
768-
z.DropAll(t, dg)
767+
dg := testutil.DgraphClientWithGroot(testutil.SockAddr)
768+
testutil.DropAll(t, dg)
769769
alterSchema(dg, "answer: [uid] @count .")
770770

771771
// Expected Edge count of 0x100: 1
@@ -813,8 +813,8 @@ func TestCountIndexSerialTxns(t *testing.T) {
813813
}
814814

815815
func TestCountIndexSameTxn(t *testing.T) {
816-
dg := z.DgraphClientWithGroot(z.SockAddr)
817-
z.DropAll(t, dg)
816+
dg := testutil.DgraphClientWithGroot(testutil.SockAddr)
817+
testutil.DropAll(t, dg)
818818
alterSchema(dg, "answer: [uid] @count .")
819819

820820
// Expected Edge count of 0x100: 1

dgraph/cmd/alpha/http_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import (
3434
"github.com/stretchr/testify/require"
3535

3636
"github.com/dgraph-io/dgraph/query"
37+
"github.com/dgraph-io/dgraph/testutil"
3738
"github.com/dgraph-io/dgraph/x"
38-
"github.com/dgraph-io/dgraph/z"
3939
)
4040

4141
type respError struct {
@@ -212,7 +212,7 @@ func runWithRetries(method, contentType, url string, body string) (
212212

213213
qr, respBody, err := runRequest(req)
214214
if err != nil && strings.Contains(err.Error(), "Token is expired") {
215-
grootAccessJwt, grootRefreshJwt, err = z.HttpLogin(&z.LoginParams{
215+
grootAccessJwt, grootRefreshJwt, err = testutil.HttpLogin(&testutil.LoginParams{
216216
Endpoint: addr + "/login",
217217
RefreshJwt: grootRefreshJwt,
218218
})

dgraph/cmd/alpha/mutations_mode/mutations_mode_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
// Tests in this file require a cluster running with the --mutations=<mode> option.
3333

3434
// Since this requires three alphas they will likely always be run with docker-compose,
35-
// so no point in trying to use z.TestSockAddr here.
35+
// so no point in trying to use testutil.TestSockAddr here.
3636
const disallowModeAlpha = "localhost:9180"
3737
const strictModeAlphaGroup1 = "localhost:9182"
3838
const strictModeAlphaGroup2 = "localhost:9183"

dgraph/cmd/alpha/run_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import (
3535
"github.com/dgraph-io/dgraph/protos/pb"
3636
"github.com/dgraph-io/dgraph/query"
3737
"github.com/dgraph-io/dgraph/schema"
38+
"github.com/dgraph-io/dgraph/testutil"
3839
"github.com/dgraph-io/dgraph/x"
39-
"github.com/dgraph-io/dgraph/z"
4040
"github.com/pkg/errors"
4141
"github.com/stretchr/testify/assert"
4242
"github.com/stretchr/testify/require"
@@ -265,7 +265,7 @@ func TestDeletePredicate(t *testing.T) {
265265

266266
output, err = runGraphqlQuery(`schema{}`)
267267
require.NoError(t, err)
268-
z.CompareJSON(t, `{"data":{"schema":[`+
268+
testutil.CompareJSON(t, `{"data":{"schema":[`+
269269
`{"predicate":"age","type":"default"},`+
270270
`{"predicate":"name","type":"string","index":true, "tokenizer":["term"]},`+
271271
x.AclPredicates+","+
@@ -1218,7 +1218,7 @@ func TestListTypeSchemaChange(t *testing.T) {
12181218
q = `schema{}`
12191219
res, err = runGraphqlQuery(q)
12201220
require.NoError(t, err)
1221-
z.CompareJSON(t, `{"data":{"schema":[`+
1221+
testutil.CompareJSON(t, `{"data":{"schema":[`+
12221222
x.AclPredicates+","+
12231223
`{"predicate":"occupations","type":"string"},`+
12241224
`{"predicate":"dgraph.type", "type":"string", "index":true, "tokenizer": ["exact"],
@@ -1438,7 +1438,7 @@ func TestDropAll(t *testing.T) {
14381438
q3 := "schema{}"
14391439
output, err = runGraphqlQuery(q3)
14401440
require.NoError(t, err)
1441-
z.CompareJSON(t,
1441+
testutil.CompareJSON(t,
14421442
`{"data":{"schema":[`+
14431443
x.AclPredicates+","+
14441444
`{"predicate":"dgraph.type", "type":"string", "index":true, "tokenizer":["exact"],
@@ -1494,7 +1494,7 @@ func TestJsonUnicode(t *testing.T) {
14941494
}
14951495

14961496
func TestGrpcCompressionSupport(t *testing.T) {
1497-
conn, err := grpc.Dial(z.SockAddr,
1497+
conn, err := grpc.Dial(testutil.SockAddr,
14981498
grpc.WithInsecure(),
14991499
grpc.WithDefaultCallOptions(grpc.UseCompressor(gzip.Name)),
15001500
)
@@ -1677,15 +1677,15 @@ var grootRefreshJwt string
16771677

16781678
func TestMain(m *testing.M) {
16791679
// Increment lease, so that mutations work.
1680-
conn, err := grpc.Dial(z.SockAddrZero, grpc.WithInsecure())
1680+
conn, err := grpc.Dial(testutil.SockAddrZero, grpc.WithInsecure())
16811681
if err != nil {
16821682
log.Fatal(err)
16831683
}
16841684
zc := pb.NewZeroClient(conn)
16851685
if _, err := zc.AssignUids(context.Background(), &pb.Num{Val: 1e6}); err != nil {
16861686
log.Fatal(err)
16871687
}
1688-
grootAccessJwt, grootRefreshJwt = z.GrootHttpLogin(addr + "/login")
1688+
grootAccessJwt, grootRefreshJwt = testutil.GrootHttpLogin(addr + "/login")
16891689

16901690
r := m.Run()
16911691
os.Exit(r)

dgraph/cmd/alpha/upsert_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"sync"
2222
"testing"
2323

24-
"github.com/dgraph-io/dgraph/z"
24+
"github.com/dgraph-io/dgraph/testutil"
2525

2626
"github.com/dgraph-io/dgo/y"
2727
"github.com/stretchr/testify/require"
@@ -763,7 +763,7 @@ upsert {
763763
]
764764
}
765765
}`
766-
z.CompareJSON(t, expected, res)
766+
testutil.CompareJSON(t, expected, res)
767767
}
768768

769769
func TestUpsertDeleteNonExistent(t *testing.T) {

dgraph/cmd/counter/increment_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828

2929
"github.com/dgraph-io/dgo"
3030
"github.com/dgraph-io/dgo/protos/api"
31+
"github.com/dgraph-io/dgraph/testutil"
3132
"github.com/dgraph-io/dgraph/x"
32-
"github.com/dgraph-io/dgraph/z"
3333
"github.com/spf13/viper"
3434
"github.com/stretchr/testify/require"
3535
"google.golang.org/grpc/metadata"
@@ -134,7 +134,7 @@ func readBestEffort(t *testing.T, dg *dgo.Dgraph, pred string, M int) {
134134
}
135135

136136
func setup(t *testing.T) *dgo.Dgraph {
137-
dg := z.DgraphClientWithGroot(z.SockAddr)
137+
dg := testutil.DgraphClientWithGroot(testutil.SockAddr)
138138
ctx := context.Background()
139139
op := api.Operation{DropAll: true}
140140

dgraph/cmd/live/load-json/load_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ import (
2828
"github.com/dgraph-io/dgo"
2929
"github.com/stretchr/testify/require"
3030

31+
"github.com/dgraph-io/dgraph/testutil"
3132
"github.com/dgraph-io/dgraph/x"
32-
"github.com/dgraph-io/dgraph/z"
3333
)
3434

35-
var alphaService = z.SockAddr
36-
var zeroService = z.SockAddrZero
35+
var alphaService = testutil.SockAddr
36+
var zeroService = testutil.SockAddrZero
3737

3838
var (
3939
testDataDir string
@@ -54,7 +54,7 @@ func checkLoadedData(t *testing.T) {
5454
}
5555
`)
5656
require.NoError(t, err)
57-
z.CompareJSON(t, `
57+
testutil.CompareJSON(t, `
5858
{
5959
"q": [
6060
{
@@ -79,7 +79,7 @@ func checkLoadedData(t *testing.T) {
7979
}
8080
`)
8181
require.NoError(t, err)
82-
z.CompareJSON(t, `
82+
testutil.CompareJSON(t, `
8383
{
8484
"q": [
8585
{
@@ -96,49 +96,49 @@ func checkLoadedData(t *testing.T) {
9696
}
9797

9898
func TestLiveLoadJSONFileEmpty(t *testing.T) {
99-
z.DropAll(t, dg)
99+
testutil.DropAll(t, dg)
100100

101101
pipeline := [][]string{
102102
{"echo", "[]"},
103103
{os.ExpandEnv("$GOPATH/bin/dgraph"), "live",
104104
"--schema", testDataDir + "/family.schema", "--files", "/dev/stdin",
105105
"--alpha", alphaService, "--zero", zeroService},
106106
}
107-
err := z.Pipeline(pipeline)
107+
err := testutil.Pipeline(pipeline)
108108
require.NoError(t, err, "live loading JSON file ran successfully")
109109
}
110110

111111
func TestLiveLoadJSONFile(t *testing.T) {
112-
z.DropAll(t, dg)
112+
testutil.DropAll(t, dg)
113113

114114
pipeline := [][]string{
115115
{os.ExpandEnv("$GOPATH/bin/dgraph"), "live",
116116
"--schema", testDataDir + "/family.schema", "--files", testDataDir + "/family.json",
117117
"--alpha", alphaService, "--zero", zeroService},
118118
}
119-
err := z.Pipeline(pipeline)
119+
err := testutil.Pipeline(pipeline)
120120
require.NoError(t, err, "live loading JSON file exited with error")
121121

122122
checkLoadedData(t)
123123
}
124124

125125
func TestLiveLoadJSONCompressedStream(t *testing.T) {
126-
z.DropAll(t, dg)
126+
testutil.DropAll(t, dg)
127127

128128
pipeline := [][]string{
129129
{"gzip", "-c", testDataDir + "/family.json"},
130130
{os.ExpandEnv("$GOPATH/bin/dgraph"), "live",
131131
"--schema", testDataDir + "/family.schema", "--files", "/dev/stdin",
132132
"--alpha", alphaService, "--zero", zeroService},
133133
}
134-
err := z.Pipeline(pipeline)
134+
err := testutil.Pipeline(pipeline)
135135
require.NoError(t, err, "live loading JSON stream exited with error")
136136

137137
checkLoadedData(t)
138138
}
139139

140140
func TestLiveLoadJSONMultipleFiles(t *testing.T) {
141-
z.DropAll(t, dg)
141+
testutil.DropAll(t, dg)
142142

143143
files := []string{
144144
testDataDir + "/family1.json",
@@ -152,7 +152,7 @@ func TestLiveLoadJSONMultipleFiles(t *testing.T) {
152152
"--schema", testDataDir + "/family.schema", "--files", fileList,
153153
"--alpha", alphaService, "--zero", zeroService},
154154
}
155-
err := z.Pipeline(pipeline)
155+
err := testutil.Pipeline(pipeline)
156156
require.NoError(t, err, "live loading multiple JSON files exited with error")
157157

158158
checkLoadedData(t)
@@ -162,7 +162,7 @@ func TestMain(m *testing.M) {
162162
_, thisFile, _, _ := runtime.Caller(0)
163163
testDataDir = path.Dir(thisFile)
164164

165-
dg = z.DgraphClientWithGroot(z.SockAddr)
165+
dg = testutil.DgraphClientWithGroot(testutil.SockAddr)
166166

167167
// Try to create any files in a dedicated temp directory that gets cleaned up
168168
// instead of all over /tmp or the working directory.

0 commit comments

Comments
 (0)