summaryrefslogtreecommitdiff
path: root/tests/e2e/test_helpers.go
blob: 34aae3f65b36db7f93098b676131b8cd470770db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package e2e

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

// GetBinaryPath resolves the path to the wg-wrap binary.
// It checks the current directory, then the project root, then the system PATH.
func GetBinaryPath() string {
	binaryName := "wg-wrap"
	if runtime.GOOS == "windows" {
		binaryName += ".exe"
	}

	// 1. Check current working directory
	if _, err := os.Stat(binaryName); err == nil {
		abs, _ := filepath.Abs(binaryName)
		return abs
	}

	// 2. Check common project root relative paths
	// Since go test can be run from root or package dir, we try both.
	candidates := []string{
		filepath.Join("..", "..", binaryName), // from tests/e2e
		filepath.Join("..", binaryName),       // from tests/
		binaryName,                           // from root
	}
	for _, c := range candidates {
		if _, err := os.Stat(c); err == nil {
			abs, _ := filepath.Abs(c)
			return abs
		}
	}

	// 3. Check system PATH
	path, err := exec.LookPath(binaryName)
	if err == nil {
		return path
	}

	return binaryName 
}