mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
fix(testrun): preflight resolves adb through the sdk, not just PATH
This commit is contained in:
1 parent
3af6791029
commit
f819dad7b6
2 files changed
+39
No files matched your search
@@ -4,6 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
|
"github.com/priyanshujain/sanderling/internal/android"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Preflight runs platform-specific host checks before sidecar/driver setup.
|
// Preflight runs platform-specific host checks before sidecar/driver setup.
|
||||||
@@ -18,7 +20,15 @@ func Preflight(ctx context.Context, platform string) error {
|
|||||||
|
|
||||||
type preflightFunc func(name string) error
|
type preflightFunc func(name string) error
|
||||||
|
|
||||||
|
// preflightCheck resolves adb through the same helper every adb call in a run
|
||||||
|
// uses, so a host whose SDK is only reachable through $ANDROID_HOME or a
|
||||||
|
// standard install location is not turned away here and then driven fine by
|
||||||
|
// the rest of the pipeline.
|
||||||
func preflightCheck(name string) error {
|
func preflightCheck(name string) error {
|
||||||
|
if name == "adb" {
|
||||||
|
_, err := android.AdbBinary()
|
||||||
|
return err
|
||||||
|
}
|
||||||
if _, err := exec.LookPath(name); err != nil {
|
if _, err := exec.LookPath(name); err != nil {
|
||||||
return fmt.Errorf("%s not found on PATH: %w", name, err)
|
return fmt.Errorf("%s not found on PATH: %w", name, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package testrun
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -49,6 +51,33 @@ func TestPreflight_AndroidNeedsAdbAndJava(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Every adb call in an android run resolves through $ANDROID_HOME and the
|
||||||
|
// standard SDK locations, so a preflight that only looks at PATH turns away a
|
||||||
|
// host the run itself would drive.
|
||||||
|
func TestPreflight_AndroidAcceptsAdbUnderAndroidHome(t *testing.T) {
|
||||||
|
sdk := t.TempDir()
|
||||||
|
writeExecutable(t, filepath.Join(sdk, "platform-tools", "adb"))
|
||||||
|
pathDirectory := t.TempDir()
|
||||||
|
writeExecutable(t, filepath.Join(pathDirectory, "java"))
|
||||||
|
t.Setenv("PATH", pathDirectory)
|
||||||
|
t.Setenv("ANDROID_HOME", sdk)
|
||||||
|
t.Setenv("ANDROID_SDK_ROOT", "")
|
||||||
|
|
||||||
|
if err := Preflight(context.Background(), "android"); err != nil {
|
||||||
|
t.Fatalf("Preflight with adb under $ANDROID_HOME: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeExecutable(t *testing.T, path string) {
|
||||||
|
t.Helper()
|
||||||
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||||
|
t.Fatalf("mkdir %s: %v", filepath.Dir(path), err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(path, nil, 0o755); err != nil {
|
||||||
|
t.Fatalf("write %s: %v", path, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPreflight_iOSNeedsXcrun(t *testing.T) {
|
func TestPreflight_iOSNeedsXcrun(t *testing.T) {
|
||||||
check := func(name string) error {
|
check := func(name string) error {
|
||||||
if name == "xcrun" {
|
if name == "xcrun" {
|
||||||
|
|||||||
Reference in new issue
Block a user