diff options
author | Icarus Sparry <golang@icarus.freeuk.com> | 2010-01-26 13:16:03 -0800 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2010-01-26 13:16:03 -0800 |
commit | 090e71e7fd122a176f65a08189ac2324f073d826 (patch) | |
tree | 24794ceee2941dc966f70c307667729b7d44ee26 | |
parent | 7c1841fb2a5668ce560a8f0ff1253bfb2e70def7 (diff) | |
download | go-090e71e7fd122a176f65a08189ac2324f073d826.tar.gz go-090e71e7fd122a176f65a08189ac2324f073d826.zip |
os: in test, allow Hostname to return FQDN even if /bin/hostname does not
Hostname reads the file /proc/sys/kernel/hostname to determine
the value it returns. Some people set this to a Fully Qualified
Doamin Name. At least one implementation of /bin/hostname
truncates the name it gets (often from the "uname" system call)
at the first dot unless it is given a "-f" flag. This change makes
the unit test also truncate at the first dot and checks if the strings
then match. This seems more portable than adding an extra flag
to the called /bin/hostname program.
R=rsc
CC=golang-dev
https://golang.org/cl/181097
-rw-r--r-- | src/pkg/os/os_test.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/pkg/os/os_test.go b/src/pkg/os/os_test.go index 4523cad79d..4a84c4f18d 100644 --- a/src/pkg/os/os_test.go +++ b/src/pkg/os/os_test.go @@ -647,13 +647,18 @@ func run(t *testing.T, cmd []string) string { func TestHostname(t *testing.T) { // Check internal Hostname() against the output of /bin/hostname. + // Allow that the internal Hostname returns a Fully Qualified Domain Name + // and the /bin/hostname only returns the first component hostname, err := Hostname() if err != nil { t.Fatalf("%v", err) } want := run(t, []string{"/bin/hostname"}) if hostname != want { - t.Errorf("Hostname() = %q, want %q", hostname, want) + i := strings.Index(hostname, ".") + if i < 0 || hostname[0:i] != want { + t.Errorf("Hostname() = %q, want %q", hostname, want) + } } } |