aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/testsuite/testsuite.go28
-rw-r--r--internal/testsuite/users.go36
-rw-r--r--internal/testsuite/users_stub.go15
3 files changed, 51 insertions, 28 deletions
diff --git a/internal/testsuite/testsuite.go b/internal/testsuite/testsuite.go
index 395bf8f2..fc9c3dfb 100644
--- a/internal/testsuite/testsuite.go
+++ b/internal/testsuite/testsuite.go
@@ -17,7 +17,6 @@ import (
"os"
"os/exec"
"os/signal"
- "os/user"
"path/filepath"
"reflect"
"runtime"
@@ -48,33 +47,6 @@ func ReceiveSignals() {
log.Fatalf("terminating on signal %s", <-s)
}
-var (
- // users caches [user.LookupId] calls.
- users = make(map[string]*user.User)
- // usersMu synchronises access to users.
- usersMu sync.RWMutex
-)
-
-// mustLookupId is like [user.LookupId], but the first result is cached.
-func mustLookupId(uid string) *user.User {
- usersMu.RLock()
- v, ok := users[uid]
- usersMu.RUnlock()
- if ok {
- return v
- }
-
- u, err := user.LookupId(uid)
- if err != nil {
- log.Fatal(err)
- }
-
- usersMu.Lock()
- users[uid] = u
- usersMu.Unlock()
- return u
-}
-
// MustAppendEnv adds extra environment variables to cmd.
func MustAppendEnv(cmd *exec.Cmd, env ...string) {
if len(cmd.Env) == 0 {
diff --git a/internal/testsuite/users.go b/internal/testsuite/users.go
new file mode 100644
index 00000000..373582f4
--- /dev/null
+++ b/internal/testsuite/users.go
@@ -0,0 +1,36 @@
+//go:build !rosa
+
+package testsuite
+
+import (
+ "log"
+ "os/user"
+ "sync"
+)
+
+var (
+ // users caches [user.LookupId] calls.
+ users = make(map[string]*user.User)
+ // usersMu synchronises access to users.
+ usersMu sync.RWMutex
+)
+
+// mustLookupId is like [user.LookupId], but the first result is cached.
+func mustLookupId(uid string) *user.User {
+ usersMu.RLock()
+ v, ok := users[uid]
+ usersMu.RUnlock()
+ if ok {
+ return v
+ }
+
+ u, err := user.LookupId(uid)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ usersMu.Lock()
+ users[uid] = u
+ usersMu.Unlock()
+ return u
+}
diff --git a/internal/testsuite/users_stub.go b/internal/testsuite/users_stub.go
new file mode 100644
index 00000000..c9088646
--- /dev/null
+++ b/internal/testsuite/users_stub.go
@@ -0,0 +1,15 @@
+//go:build rosa
+
+package testsuite
+
+import "os/user"
+
+// mustLookupId always returns the address of a populated [user.User].
+func mustLookupId(uid string) *user.User {
+ return &user.User{
+ Uid: uid,
+ Gid: "100",
+ Username: "_" + uid,
+ HomeDir: "/proc/nonexistent",
+ }
+}