forked from coder/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusershell_test.go
More file actions
46 lines (37 loc) · 968 Bytes
/
usershell_test.go
File metadata and controls
46 lines (37 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package usershell_test
import (
"os/user"
"runtime"
"testing"
"github.com/stretchr/testify/require"
"github.com/coder/coder/agent/usershell"
)
//nolint:paralleltest,tparallel // This test sets an environment variable.
func TestGet(t *testing.T) {
if runtime.GOOS == "windows" {
t.SkipNow()
}
t.Run("Fallback", func(t *testing.T) {
t.Setenv("SHELL", "/bin/sh")
t.Run("NonExistentUser", func(t *testing.T) {
shell, err := usershell.Get("notauser")
require.NoError(t, err)
require.Equal(t, "/bin/sh", shell)
})
})
t.Run("NoFallback", func(t *testing.T) {
// Disable env fallback for these tests.
t.Setenv("SHELL", "")
t.Run("NotFound", func(t *testing.T) {
_, err := usershell.Get("notauser")
require.Error(t, err)
})
t.Run("User", func(t *testing.T) {
u, err := user.Current()
require.NoError(t, err)
shell, err := usershell.Get(u.Username)
require.NoError(t, err)
require.NotEmpty(t, shell)
})
})
}