runContainer runs the container with the specific config and arguments buffers are returned containing the STDOUT and STDERR output for the run along with the exit code and any go error
(t testing.TB, config *configs.Config, args ...string)
| 174 | // buffers are returned containing the STDOUT and STDERR output for the run |
| 175 | // along with the exit code and any go error |
| 176 | func runContainer(t testing.TB, config *configs.Config, args ...string) (buffers *stdBuffers, exitCode int, err error) { |
| 177 | container, err := newContainer(t, config) |
| 178 | if err != nil { |
| 179 | return nil, -1, err |
| 180 | } |
| 181 | defer destroyContainer(container) |
| 182 | buffers = newStdBuffers() |
| 183 | process := &libcontainer.Process{ |
| 184 | Cwd: "/", |
| 185 | Args: args, |
| 186 | Env: standardEnvironment, |
| 187 | Stdout: buffers.Stdout, |
| 188 | Stderr: buffers.Stderr, |
| 189 | Init: true, |
| 190 | } |
| 191 | |
| 192 | err = container.Run(process) |
| 193 | if err != nil { |
| 194 | return buffers, -1, err |
| 195 | } |
| 196 | ps, err := process.Wait() |
| 197 | if err != nil { |
| 198 | return buffers, -1, err |
| 199 | } |
| 200 | status := ps.Sys().(syscall.WaitStatus) |
| 201 | if status.Exited() { |
| 202 | exitCode = status.ExitStatus() |
| 203 | } else if status.Signaled() { |
| 204 | exitCode = -int(status.Signal()) |
| 205 | } else { |
| 206 | return buffers, -1, err |
| 207 | } |
| 208 | return buffers, exitCode, err |
| 209 | } |
| 210 | |
| 211 | // runContainerOk is a wrapper for runContainer, simplifying its use for cases |
| 212 | // when the run is expected to succeed and return exit code of 0. |
no test coverage detected
searching dependent graphs…