ResolveDdevBinary returns the DDEV binary that tests should execute. If DDEV_BINARY_FULLPATH is set, it is used directly. Otherwise the binary is built from source via `make`.
()
| 15 | // If DDEV_BINARY_FULLPATH is set, it is used directly. Otherwise the binary |
| 16 | // is built from source via `make`. |
| 17 | func ResolveDdevBinary() (string, error) { |
| 18 | if bin := os.Getenv("DDEV_BINARY_FULLPATH"); bin != "" { |
| 19 | if !fileutil.FileExists(bin) { |
| 20 | return "", fmt.Errorf("DDEV_BINARY_FULLPATH=%s does not exist", bin) |
| 21 | } |
| 22 | return bin, nil |
| 23 | } |
| 24 | |
| 25 | repoRoot, err := findRepoRoot() |
| 26 | if err != nil { |
| 27 | return "", fmt.Errorf("failed to locate repository root: %w", err) |
| 28 | } |
| 29 | |
| 30 | binaryName := "ddev" |
| 31 | if runtime.GOOS == "windows" { |
| 32 | binaryName += ".exe" |
| 33 | } |
| 34 | binaryPath := filepath.Join(repoRoot, ".gotmp", "bin", runtime.GOOS+"_"+runtime.GOARCH, binaryName) |
| 35 | |
| 36 | cmd := osexec.Command("make") |
| 37 | cmd.Dir = repoRoot |
| 38 | cmd.Stdout = os.Stdout |
| 39 | cmd.Stderr = os.Stderr |
| 40 | if err := cmd.Run(); err != nil { |
| 41 | return "", fmt.Errorf("`make` failed: %w", err) |
| 42 | } |
| 43 | if !fileutil.FileExists(binaryPath) { |
| 44 | return "", fmt.Errorf("`make` succeeded but %s was not found", binaryPath) |
| 45 | } |
| 46 | return binaryPath, nil |
| 47 | } |
| 48 | |
| 49 | // MustResolveDdevBinary returns the test DDEV binary or aborts the current test process. |
| 50 | func MustResolveDdevBinary() string { |
no test coverage detected