Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Use make and docker-compose from the root folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed Nov 20, 2023
1 parent 82ddc77 commit 899d593
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
13 changes: 9 additions & 4 deletions test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package test
import (
"context"
"math/big"
"os/exec"
"testing"
"time"

Expand All @@ -20,15 +19,21 @@ func TestEthTransfer(t *testing.T) {
if testing.Short() {
t.Skip()
}

cluster, err := newTestCluster("")
require.NoError(t, err)

ctx := context.Background()
defer func() {
msg, err := exec.Command("make", "stop").CombinedOutput()
msg, err := cluster.stop()
require.NoError(t, err, string(msg))
require.NoError(t, cluster.reset())
}()

log.Info("restarting docker containers for the test")
msg, err := exec.Command("make", "stop").CombinedOutput()
msg, err := cluster.stop()
require.NoError(t, err, string(msg))
msg, err = exec.Command("make", "run").CombinedOutput()
msg, err = cluster.start()
require.NoError(t, err, string(msg))
time.Sleep(5 * time.Second)

Expand Down
43 changes: 43 additions & 0 deletions test/test-cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package test

import (
"os"
"os/exec"
"path/filepath"
)

type testCluster struct {
path string
originalWorkDir string
}

func newTestCluster(path string) (*testCluster, error) {
workDir, err := os.Getwd()
if err != nil {
return nil, err
}

if path == "" {
parentDir := filepath.Dir(workDir)
if err := os.Chdir(parentDir); err != nil {
return nil, err
}
}

return &testCluster{
path: path,
originalWorkDir: workDir,
}, nil
}

func (t *testCluster) start() ([]byte, error) {
return exec.Command("make", "run-docker").CombinedOutput()
}

func (t *testCluster) stop() ([]byte, error) {
return exec.Command("make", "stop-docker").CombinedOutput()
}

func (t *testCluster) reset() error {
return os.Chdir(t.originalWorkDir)
}

0 comments on commit 899d593

Please sign in to comment.