Skip to content

Commit 702e740

Browse files
ShivaShivaji Kharse
authored andcommitted
resolve dgraph binary selection for macOS in dgraphtest and testutil
1 parent da18664 commit 702e740

16 files changed

Lines changed: 55 additions & 106 deletions

File tree

check_upgrade/check_upgrade_test.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ package checkupgrade
1010
import (
1111
"context"
1212
"fmt"
13-
"os"
1413
"os/exec"
15-
"path/filepath"
1614
"regexp"
17-
"runtime"
1815
"testing"
1916
"time"
2017

@@ -28,11 +25,6 @@ import (
2825
)
2926

3027
func TestCheckUpgrade(t *testing.T) {
31-
if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" {
32-
fmt.Println("Skipping live load-uids tests on non-Linux platforms due to dgraph binary dependency")
33-
fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests")
34-
os.Exit(0)
35-
}
3628
conf := dgraphtest.NewClusterConfig().WithNumAlphas(1).WithNumZeros(1).WithReplicas(1).
3729
WithACL(time.Hour).WithVersion("57aa5c4ac")
3830
c, err := dgraphtest.NewLocalCluster(conf)
@@ -88,7 +80,7 @@ func TestCheckUpgrade(t *testing.T) {
8880
"--namespace", "1",
8981
}
9082

91-
cmd := exec.Command(filepath.Join(c1.GetTempDir(), "dgraph"), args...)
83+
cmd := exec.Command(c1.HostDgraphBinaryPath(), args...)
9284
out, err := cmd.CombinedOutput()
9385
require.NoError(t, err)
9486
actualOutput := string(out)
@@ -108,7 +100,7 @@ func TestQueryDuplicateNodes(t *testing.T) {
108100
WithACL(time.Hour).WithVersion("57aa5c4ac").WithAclAlg(jwt.GetSigningMethod("HS256"))
109101
c, err := dgraphtest.NewLocalCluster(conf)
110102
require.NoError(t, err)
111-
// defer func() { c.Cleanup(t.Failed()) }()
103+
defer func() { c.Cleanup(t.Failed()) }()
112104
require.NoError(t, c.Start())
113105
gc, cleanup, err := c.Client()
114106
require.NoError(t, err)

dgraph/cmd/dgraphimport/import_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import (
1010
"context"
1111
"encoding/json"
1212
"fmt"
13-
"os"
1413
"path/filepath"
15-
"runtime"
1614
"strconv"
1715
"strings"
1816
"testing"
@@ -326,11 +324,6 @@ func runImportTest(t *testing.T, tt testcase) {
326324

327325
// setupBulkCluster creates and configures a cluster for bulk loading data
328326
func setupBulkCluster(t *testing.T, numAlphas int, encrypted bool) (*dgraphtest.LocalCluster, string) {
329-
if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" {
330-
fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests")
331-
t.Skip("Skipping test on non-Linux platforms due to dgraph binary dependency")
332-
}
333-
334327
baseDir := t.TempDir()
335328
bulkConf := dgraphtest.NewClusterConfig().
336329
WithNumAlphas(numAlphas).

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package live
99

1010
import (
1111
"context"
12-
"fmt"
1312
"os"
1413
"path/filepath"
1514
"runtime"
@@ -162,12 +161,6 @@ func TestLiveLoadJSONMultipleFiles(t *testing.T) {
162161
}
163162

164163
func TestMain(m *testing.M) {
165-
if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" {
166-
fmt.Println("Skipping live load-json tests on non-Linux platforms due to dgraph binary dependency")
167-
fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests")
168-
os.Exit(0)
169-
}
170-
171164
_, thisFile, _, _ := runtime.Caller(0)
172165
testDataDir = filepath.Dir(thisFile)
173166

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,6 @@ func TestLiveLoadFileNameMultipleCorrect(t *testing.T) {
351351
}
352352

353353
func TestMain(m *testing.M) {
354-
if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" {
355-
fmt.Println("Skipping live load-uids tests on non-Linux platforms due to dgraph binary dependency")
356-
fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests")
357-
os.Exit(0)
358-
}
359-
360354
alphaService = testutil.GetSockAddr()
361355
alphaName = testutil.Instance
362356

dgraph/cmd/version/version_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
package version
77

88
import (
9-
"fmt"
109
"os"
1110
"path/filepath"
12-
"runtime"
1311
"testing"
1412

1513
"github.com/stretchr/testify/require"
@@ -19,11 +17,6 @@ import (
1917

2018
// Test `dgraph version` with an empty config file.
2119
func TestMain(m *testing.M) {
22-
if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" {
23-
fmt.Println("Skipping version tests on non-Linux platforms due to dgraph binary dependency")
24-
fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests")
25-
os.Exit(0)
26-
}
2720
m.Run()
2821
}
2922

dgraphtest/image.go

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"os"
1313
"os/exec"
1414
"path/filepath"
15+
"runtime"
1516
"strings"
1617
"sync"
1718

@@ -28,9 +29,18 @@ func (c *LocalCluster) dgraphImage() string {
2829
return "dgraph/dgraph:local"
2930
}
3031

31-
// setupBinary sets up the dgraph binary. The binary is expected to be a version
32-
// compiled that is compatible with the host OS and architecture. Search this repo
33-
// for DGRAPH_BINARY to learn its use.
32+
// setupBinary sets up dgraph binaries in tempBinDir.
33+
//
34+
// On Linux a single "dgraph" binary from $GOPATH/bin serves both Docker
35+
// containers and local commands (bulk/live loader).
36+
//
37+
// On non-Linux (macOS) two binaries are placed in tempBinDir:
38+
// - "dgraph" – a Linux binary for Docker containers, from
39+
// $GOPATH/linux_<arch> (or LINUX_GOBIN if set).
40+
// - "dgraph_host" – the host-native binary for local commands,
41+
// from $GOPATH/bin.
42+
//
43+
// Both are produced by "make install".
3444
func (c *LocalCluster) setupBinary() error {
3545
if err := ensureDgraphClone(); err != nil {
3646
panic(err)
@@ -43,11 +53,34 @@ func (c *LocalCluster) setupBinary() error {
4353
}
4454
}
4555
if c.conf.version == localVersion {
46-
if os.Getenv("GOPATH") == "" {
56+
gopath := os.Getenv("GOPATH")
57+
if gopath == "" {
4758
return errors.New("GOPATH is not set")
4859
}
49-
fromDir := filepath.Join(os.Getenv("GOPATH"), "bin")
50-
return copyBinary(fromDir, c.tempBinDir, c.conf.version)
60+
61+
if runtime.GOOS == "linux" {
62+
// On Linux $GOPATH/bin/dgraph is both the native and Docker binary.
63+
return copyBinary(filepath.Join(gopath, "bin"), c.tempBinDir, c.conf.version)
64+
}
65+
66+
// Non-Linux (macOS): need separate Linux and host-native binaries.
67+
// 1. Copy the Linux binary (for Docker containers) as "dgraph".
68+
linuxDir := os.Getenv("LINUX_GOBIN")
69+
if linuxDir == "" {
70+
linuxDir = filepath.Join(gopath, "linux_"+runtime.GOARCH)
71+
}
72+
if err := copyBinary(linuxDir, c.tempBinDir, c.conf.version); err != nil {
73+
return err
74+
}
75+
76+
// 2. Copy the host-native binary (for local bulk/live commands) as "dgraph_host".
77+
hostSrc := filepath.Join(gopath, "bin", "dgraph")
78+
79+
hostDst := filepath.Join(c.tempBinDir, "dgraph_host")
80+
if err := copy(hostSrc, hostDst); err != nil {
81+
return errors.Wrapf(err, "error copying host-native binary from [%v] to [%v]", hostSrc, hostDst)
82+
}
83+
return nil
5184
}
5285

5386
binaryPath := filepath.Join(binariesPath, fmt.Sprintf(binaryNameFmt, c.conf.version))

dgraphtest/load.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"os"
1818
"os/exec"
1919
"path/filepath"
20+
"runtime"
2021
"strconv"
2122
"strings"
2223

@@ -28,6 +29,17 @@ import (
2829
"github.com/dgraph-io/dgraph/v25/x"
2930
)
3031

32+
// HostDgraphBinaryPath returns the path to the host-OS-native dgraph binary
33+
// in tempBinDir. On Linux this is simply "dgraph" (the same binary used by
34+
// Docker containers). On non-Linux (macOS) it is "dgraph_host", a separate
35+
// native binary copied by setupBinary().
36+
func (c *LocalCluster) HostDgraphBinaryPath() string {
37+
if runtime.GOOS == "linux" {
38+
return filepath.Join(c.tempBinDir, "dgraph")
39+
}
40+
return filepath.Join(c.tempBinDir, "dgraph_host")
41+
}
42+
3143
var datafiles = map[string]string{
3244
"1million.schema": "https://github.com/dgraph-io/dgraph-benchmarks/blob/main/data/1million.schema?raw=true",
3345
"1million.rdf.gz": "https://github.com/dgraph-io/dgraph-benchmarks/blob/main/data/1million.rdf.gz?raw=true",
@@ -245,7 +257,7 @@ func (c *LocalCluster) LiveLoad(opts LiveOpts) error {
245257
}
246258

247259
log.Printf("[INFO] running live loader with args: [%v]", strings.Join(args, " "))
248-
cmd := exec.Command(filepath.Join(c.tempBinDir, "dgraph"), args...)
260+
cmd := exec.Command(c.HostDgraphBinaryPath(), args...)
249261
if out, err := cmd.CombinedOutput(); err != nil {
250262
return errors.Wrapf(err, "error running live loader: %v", string(out))
251263
} else {
@@ -505,17 +517,8 @@ func (c *LocalCluster) BulkLoad(opts BulkOpts) error {
505517
args = append(args, "-g", strings.Join(opts.GQLSchemaFiles, ","))
506518
}
507519

508-
// dgraphCmdPath := os.Getenv("DGRAPH_CMD_PATH")
509-
// if dgraphCmdPath == "" {
510-
// dgraphCmdPath = filepath.Join(c.tempBinDir, "dgraph")
511-
// }
512-
513520
log.Printf("[INFO] running bulk loader with args: [%v]", strings.Join(args, " "))
514-
binaryName := "dgraph"
515-
if os.Getenv("DGRAPH_BINARY") != "" {
516-
binaryName = filepath.Base(os.Getenv("DGRAPH_BINARY"))
517-
}
518-
cmd := exec.Command(filepath.Join(c.tempBinDir, binaryName), args...)
521+
cmd := exec.Command(c.HostDgraphBinaryPath(), args...)
519522
if out, err := cmd.CombinedOutput(); err != nil {
520523
return errors.Wrapf(err, "error running bulk loader: %v", string(out))
521524
} else {

systest/1million/1million_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"fmt"
1313
"os"
1414
"path/filepath"
15-
"runtime"
1615
"testing"
1716
"time"
1817

@@ -44,11 +43,6 @@ func Test1Million(t *testing.T) {
4443
}
4544

4645
func TestMain(m *testing.M) {
47-
if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" {
48-
fmt.Println("Skipping 1million tests on non-Linux platforms due to dgraph binary dependency")
49-
fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests")
50-
os.Exit(0)
51-
}
5246
noschemaFile := filepath.Join(testutil.TestDataDirectory, "1million-noindex.schema")
5347
rdfFile := filepath.Join(testutil.TestDataDirectory, "1million.rdf.gz")
5448
if err := testutil.MakeDirEmpty([]string{"out/0", "out/1", "out/2"}); err != nil {

systest/21million/bulk/run_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ func BenchmarkQueries(b *testing.B) {
6969
}
7070

7171
func TestMain(m *testing.M) {
72-
if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" {
73-
fmt.Println("Skipping 21million bulk tests on non-Linux platforms due to dgraph binary dependency")
74-
fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests")
75-
os.Exit(0)
76-
}
7772
schemaFile := filepath.Join(testutil.TestDataDirectory, "21million.schema")
7873
rdfFile := filepath.Join(testutil.TestDataDirectory, "21million.rdf.gz")
7974
if err := testutil.MakeDirEmpty([]string{"out/0", "out/1", "out/2"}); err != nil {

systest/audit_encrypted/audit_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"fmt"
1212
"os"
1313
"os/exec"
14-
"runtime"
1514
"testing"
1615

1716
"github.com/stretchr/testify/require"
@@ -21,11 +20,6 @@ import (
2120
)
2221

2322
func TestMain(m *testing.M) {
24-
if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" {
25-
fmt.Println("Skipping audit_encrypted tests on non-Linux platforms due to dgraph binary dependency")
26-
fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests")
27-
os.Exit(0)
28-
}
2923
m.Run()
3024
}
3125

0 commit comments

Comments
 (0)