]> Cypherpunks repositories - gostls13.git/commitdiff
os: add windows test for Hostname
authorAlex Brainman <alex.brainman@gmail.com>
Thu, 26 Feb 2015 03:19:19 +0000 (14:19 +1100)
committerAlex Brainman <alex.brainman@gmail.com>
Mon, 2 Mar 2015 01:23:27 +0000 (01:23 +0000)
Change-Id: I9b38b3a384722cf000eab18b62f73f90bcb56c5c
Reviewed-on: https://go-review.googlesource.com/6070
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/os/os_test.go

index 09177496e2fbc88315a17d820e5265afae695863..380e2b8ffe7f12198a2c1e6d484ac78c3bc88b8a 100644 (file)
@@ -1139,16 +1139,35 @@ func run(t *testing.T, cmd []string) string {
        return output
 }
 
+func testWindowsHostname(t *testing.T) {
+       hostname, err := Hostname()
+       if err != nil {
+               t.Fatal(err)
+       }
+       cmd := osexec.Command("hostname")
+       out, err := cmd.CombinedOutput()
+       if err != nil {
+               t.Fatalf("Failed to execute hostname command: %v %s", err, out)
+       }
+       want := strings.Trim(string(out), "\r\n")
+       if hostname != want {
+               t.Fatalf("Hostname() = %q, want %q", hostname, want)
+       }
+}
+
 func TestHostname(t *testing.T) {
        // There is no other way to fetch hostname on windows, but via winapi.
        // On Plan 9 it can be taken from #c/sysname as Hostname() does.
        switch runtime.GOOS {
-       case "android", "nacl", "plan9", "windows":
+       case "android", "nacl", "plan9":
                t.Skipf("skipping on %s", runtime.GOOS)
        case "darwin":
                if runtime.GOARCH == "arm" {
                        t.Skipf("skipping on %s/%s", runtime.GOOS, runtime.GOARCH)
                }
+       case "windows":
+               testWindowsHostname(t)
+               return
        }
 
        // Check internal Hostname() against the output of /bin/hostname.