Skip to content

Commit

Permalink
fix: fixing runCmd in 'operations/manager' to work in any nesting dir…
Browse files Browse the repository at this point in the history
…ectory level.

Signed-off-by: Nikolay Nedkov <[email protected]>
  • Loading branch information
Psykepro committed Dec 13, 2022
1 parent b323342 commit 46edc7f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/operations/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math/big"
"os"
"os/exec"
"path/filepath"
"strings"
"time"

Expand All @@ -30,6 +31,7 @@ const (
maticTokenAddress = "0x5FbDB2315678afecb367f032d93F642f64180aa3" //nolint:gosec
l1AccHexAddress = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
l1AccHexPrivateKey = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
cmdFolder = "test"
)

// Public constants
Expand Down Expand Up @@ -493,7 +495,23 @@ func stopNode() error {
}

func runCmd(c *exec.Cmd) error {
c.Dir = "../../test"
dir, err := os.Getwd()
if err != nil {
log.Fatalf("failed to get current work directory: %w", err)
}

if strings.Contains(dir, cmdFolder) {
// Making the change dir to work in any nesting directory level inside cmd folder
base := filepath.Base(dir)
for base != cmdFolder {
dir = filepath.Dir(dir)
base = filepath.Base(dir)
}
} else {
dir = fmt.Sprintf("../../%s", cmdFolder)
}
c.Dir = dir

c.Stdout = os.Stdout
c.Stderr = os.Stderr
return c.Run()
Expand Down

0 comments on commit 46edc7f

Please sign in to comment.