MCPcopy Index your code
hub / github.com/coder/coder / TestExecer

Function TestExecer

agent/agentexec/exec_internal_test.go:11–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestExecer(t *testing.T) {
12 t.Parallel()
13
14 t.Run("Default", func(t *testing.T) {
15 t.Parallel()
16
17 cmd := DefaultExecer.CommandContext(context.Background(), "sh", "-c", "sleep")
18
19 path, err := exec.LookPath("sh")
20 require.NoError(t, err)
21 require.Equal(t, path, cmd.Path)
22 require.Equal(t, []string{"sh", "-c", "sleep"}, cmd.Args)
23 })
24
25 t.Run("Priority", func(t *testing.T) {
26 t.Parallel()
27
28 t.Run("OK", func(t *testing.T) {
29 t.Parallel()
30
31 e := priorityExecer{
32 binPath: "/foo/bar/baz",
33 oomScore: unset,
34 niceScore: unset,
35 }
36
37 cmd := e.CommandContext(context.Background(), "sh", "-c", "sleep")
38 require.Equal(t, e.binPath, cmd.Path)
39 require.Equal(t, []string{e.binPath, "agent-exec", "--", "sh", "-c", "sleep"}, cmd.Args)
40 })
41
42 t.Run("Nice", func(t *testing.T) {
43 t.Parallel()
44
45 e := priorityExecer{
46 binPath: "/foo/bar/baz",
47 oomScore: unset,
48 niceScore: 10,
49 }
50
51 cmd := e.CommandContext(context.Background(), "sh", "-c", "sleep")
52 require.Equal(t, e.binPath, cmd.Path)
53 require.Equal(t, []string{e.binPath, "agent-exec", "--coder-nice=10", "--", "sh", "-c", "sleep"}, cmd.Args)
54 })
55
56 t.Run("OOM", func(t *testing.T) {
57 t.Parallel()
58
59 e := priorityExecer{
60 binPath: "/foo/bar/baz",
61 oomScore: 123,
62 niceScore: unset,
63 }
64
65 cmd := e.CommandContext(context.Background(), "sh", "-c", "sleep")
66 require.Equal(t, e.binPath, cmd.Path)
67 require.Equal(t, []string{e.binPath, "agent-exec", "--coder-oom=123", "--", "sh", "-c", "sleep"}, cmd.Args)
68 })

Callers

nothing calls this directly

Calls 4

CommandContextMethod · 0.95
RunMethod · 0.65
CommandContextMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected