Skip to content

Commit f613a7b

Browse files
committed
cmd/dist, os/user: test os/user in osusergo mode as well, fix plan9 & windows
Would've caught two regressions so far, and found two more. Updates #24841 Updates #24845 (package net remains) Change-Id: I57ad06eb54e04b8c99b5d2e7f24c77ad865224e8 Reviewed-on: https://go-review.googlesource.com/107300 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 04a27be commit f613a7b

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/cmd/dist/test.go

+12
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,18 @@ func (t *tester) registerTests() {
407407
}
408408
}
409409

410+
// Test the os/user package in the pure-Go mode too.
411+
if !t.compileOnly {
412+
t.tests = append(t.tests, distTest{
413+
name: "osusergo",
414+
heading: "os/user with tag osusergo",
415+
fn: func(dt *distTest) error {
416+
t.addCmd(dt, "src", t.goTest(), t.timeout(300), "-tags=osusergo", "os/user")
417+
return nil
418+
},
419+
})
420+
}
421+
410422
if t.race {
411423
return
412424
}

src/os/user/lookup_stubs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build !cgo,!windows,!plan9 android osusergo
5+
// +build !cgo,!windows,!plan9 android osusergo,!windows,!plan9
66

77
package user
88

src/os/user/user_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package user
66

77
import (
8+
"internal/testenv"
9+
"os"
810
"runtime"
911
"testing"
1012
)
@@ -16,6 +18,20 @@ func checkUser(t *testing.T) {
1618
}
1719

1820
func TestCurrent(t *testing.T) {
21+
// The Go builders (in particular the ones using containers)
22+
// often have minimal environments without $HOME or $USER set,
23+
// which breaks Current which relies on those working as a
24+
// fallback.
25+
// TODO: we should fix that (Issue 24884) and remove these
26+
// workarounds.
27+
if testenv.Builder() != "" && runtime.GOOS != "windows" && runtime.GOOS != "plan9" {
28+
if os.Getenv("HOME") == "" {
29+
os.Setenv("HOME", "/tmp")
30+
}
31+
if os.Getenv("USER") == "" {
32+
os.Setenv("USER", "gobuilder")
33+
}
34+
}
1935
u, err := Current()
2036
if err != nil {
2137
t.Fatalf("Current: %v (got %#v)", err, u)

0 commit comments

Comments
 (0)