Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/pkg/osutil/user_test.go
2606 views
1
// SPDX-FileCopyrightText: Copyright The Lima Authors
2
// SPDX-License-Identifier: Apache-2.0
3
4
package osutil
5
6
import (
7
"path"
8
"strconv"
9
"sync"
10
"testing"
11
12
"gotest.tools/v3/assert"
13
)
14
15
const limaVersion = "1.0.0"
16
17
// "admin" is a reserved username in 1.0.0
18
func TestLimaUserAdminNew(t *testing.T) {
19
currentUser.Username = "admin"
20
once = new(sync.Once)
21
user := LimaUser(t.Context(), limaVersion, false)
22
assert.Equal(t, user.Username, fallbackUser)
23
}
24
25
// "admin" is allowed in older instances
26
func TestLimaUserAdminOld(t *testing.T) {
27
currentUser.Username = "admin"
28
once = new(sync.Once)
29
user := LimaUser(t.Context(), "0.23.0", false)
30
assert.Equal(t, user.Username, "admin")
31
}
32
33
func TestLimaUserInvalid(t *testing.T) {
34
currentUser.Username = "[email protected]"
35
once = new(sync.Once)
36
user := LimaUser(t.Context(), limaVersion, false)
37
assert.Equal(t, user.Username, fallbackUser)
38
}
39
40
func TestLimaUserUid(t *testing.T) {
41
currentUser.Username = fallbackUser
42
once = new(sync.Once)
43
user := LimaUser(t.Context(), limaVersion, false)
44
_, err := strconv.Atoi(user.Uid)
45
assert.NilError(t, err)
46
}
47
48
func TestLimaUserGid(t *testing.T) {
49
currentUser.Username = fallbackUser
50
once = new(sync.Once)
51
user := LimaUser(t.Context(), limaVersion, false)
52
_, err := strconv.Atoi(user.Gid)
53
assert.NilError(t, err)
54
}
55
56
func TestLimaHomeDir(t *testing.T) {
57
currentUser.Username = fallbackUser
58
once = new(sync.Once)
59
user := LimaUser(t.Context(), limaVersion, false)
60
// check for absolute unix path (/home)
61
assert.Assert(t, path.IsAbs(user.HomeDir), user.HomeDir)
62
}
63
64