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

Function binCmd

agent/agentexec/cli_linux_test.go:152–183  ·  view source on GitHub ↗
(ctx context.Context, t *testing.T, bin string, oom, nice int)

Source from the content-addressed store, hash-verified

150}
151
152func binCmd(ctx context.Context, t *testing.T, bin string, oom, nice int) (*exec.Cmd, string) {
153 var (
154 args = execArgs(oom, nice)
155 dir = t.TempDir()
156 file = filepath.Join(dir, "sentinel")
157 )
158
159 args = append(args, "sh", "-c", fmt.Sprintf("touch %s && sleep 10m", file))
160 //nolint:gosec
161 cmd := exec.CommandContext(ctx, bin, args...)
162
163 // We set this so we can also easily kill the sleep process the shell spawns.
164 cmd.SysProcAttr = &syscall.SysProcAttr{
165 Setpgid: true,
166 }
167
168 cmd.Env = os.Environ()
169 var buf bytes.Buffer
170 cmd.Stdout = &buf
171 cmd.Stderr = &buf
172 t.Cleanup(func() {
173 // Print output of a command if the test fails.
174 if t.Failed() {
175 t.Logf("cmd %q output: %s", cmd.Args, buf.String())
176 }
177 if cmd.Process != nil {
178 // We use -cmd.Process.Pid to kill the whole process group.
179 _ = syscall.Kill(-cmd.Process.Pid, syscall.SIGINT)
180 }
181 })
182 return cmd, file
183}
184
185func cmd(ctx context.Context, t *testing.T, oom, nice int) (*exec.Cmd, string) {
186 return binCmd(ctx, t, TestBin, oom, nice)

Callers 2

TestCLIFunction · 0.85
cmdFunction · 0.85

Calls 9

execArgsFunction · 0.70
TempDirMethod · 0.65
CommandContextMethod · 0.65
EnvironMethod · 0.65
CleanupMethod · 0.65
LogfMethod · 0.65
KillMethod · 0.65
FailedMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected