Skip to content

Commit

Permalink
cmd/dist, os/user: test os/user in osusergo mode as well, fix plan9 &…
Browse files Browse the repository at this point in the history
… windows

Would've caught two regressions so far, and found two more.

Updates golang#24841
Updates golang#24845 (package net remains)

Change-Id: I57ad06eb54e04b8c99b5d2e7f24c77ad865224e8
Reviewed-on: https://go-review.googlesource.com/107300
Reviewed-by: Ian Lance Taylor <iant@golang.org>
  • Loading branch information
bradfitz committed Apr 16, 2018
1 parent 04a27be commit f613a7b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/cmd/dist/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,18 @@ func (t *tester) registerTests() {
}
}

// Test the os/user package in the pure-Go mode too.
if !t.compileOnly {
t.tests = append(t.tests, distTest{
name: "osusergo",
heading: "os/user with tag osusergo",
fn: func(dt *distTest) error {
t.addCmd(dt, "src", t.goTest(), t.timeout(300), "-tags=osusergo", "os/user")
return nil
},
})
}

if t.race {
return
}
Expand Down
2 changes: 1 addition & 1 deletion src/os/user/lookup_stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build !cgo,!windows,!plan9 android osusergo
// +build !cgo,!windows,!plan9 android osusergo,!windows,!plan9

package user

Expand Down
16 changes: 16 additions & 0 deletions src/os/user/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package user

import (
"internal/testenv"
"os"
"runtime"
"testing"
)
Expand All @@ -16,6 +18,20 @@ func checkUser(t *testing.T) {
}

func TestCurrent(t *testing.T) {
// The Go builders (in particular the ones using containers)
// often have minimal environments without $HOME or $USER set,
// which breaks Current which relies on those working as a
// fallback.
// TODO: we should fix that (Issue 24884) and remove these
// workarounds.
if testenv.Builder() != "" && runtime.GOOS != "windows" && runtime.GOOS != "plan9" {
if os.Getenv("HOME") == "" {
os.Setenv("HOME", "/tmp")
}
if os.Getenv("USER") == "" {
os.Setenv("USER", "gobuilder")
}
}
u, err := Current()
if err != nil {
t.Fatalf("Current: %v (got %#v)", err, u)
Expand Down

0 comments on commit f613a7b

Please sign in to comment.