mirror of
https://github.com/golang/go
synced 2024-11-17 05:35:00 -07:00
os: look up hostname from PATH in test
When running TestHostname, the location of the hostname binary is hardcoded as /bin/hostname. However, on some systems the actual location is /usr/bin/hostname. Change this behaviour to perform a lookup for hostname in PATH, and skip the test when it cannot be found there.
This commit is contained in:
parent
cbc9e58905
commit
750f36fcf9
@ -1699,16 +1699,21 @@ func runBinHostname(t *testing.T) string {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer r.Close()
|
||||
const path = "/bin/hostname"
|
||||
|
||||
path, err := osexec.LookPath("hostname")
|
||||
if err != nil {
|
||||
if errors.Is(err, osexec.ErrNotFound) {
|
||||
t.Skip("skipping test; test requires hostname but it does not exist")
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
argv := []string{"hostname"}
|
||||
if runtime.GOOS == "aix" {
|
||||
argv = []string{"hostname", "-s"}
|
||||
}
|
||||
p, err := StartProcess(path, argv, &ProcAttr{Files: []*File{nil, w, Stderr}})
|
||||
if err != nil {
|
||||
if _, err := Stat(path); IsNotExist(err) {
|
||||
t.Skipf("skipping test; test requires %s but it does not exist", path)
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
w.Close()
|
||||
|
Loading…
Reference in New Issue
Block a user