use of com.github.dockerjava.api.command.InspectExecCmd in project vespa by vespa-engine.
the class DockerImplTest method testExecuteCompletes.
@Test
public void testExecuteCompletes() throws Exception {
final String containerId = "container-id";
final String[] command = new String[] { "/bin/ls", "-l" };
final String execId = "exec-id";
final int exitCode = 3;
final DockerClient dockerClient = mock(DockerClient.class);
final ExecCreateCmdResponse response = mock(ExecCreateCmdResponse.class);
when(response.getId()).thenReturn(execId);
final ExecCreateCmd execCreateCmd = mock(ExecCreateCmd.class);
when(dockerClient.execCreateCmd(any(String.class))).thenReturn(execCreateCmd);
when(execCreateCmd.withCmd(Matchers.<String>anyVararg())).thenReturn(execCreateCmd);
when(execCreateCmd.withAttachStdout(any(Boolean.class))).thenReturn(execCreateCmd);
when(execCreateCmd.withAttachStderr(any(Boolean.class))).thenReturn(execCreateCmd);
when(execCreateCmd.withUser(any(String.class))).thenReturn(execCreateCmd);
when(execCreateCmd.exec()).thenReturn(response);
final ExecStartCmd execStartCmd = mock(ExecStartCmd.class);
when(dockerClient.execStartCmd(any(String.class))).thenReturn(execStartCmd);
when(execStartCmd.exec(any(ExecStartResultCallback.class))).thenReturn(mock(ExecStartResultCallback.class));
final InspectExecCmd inspectExecCmd = mock(InspectExecCmd.class);
final InspectExecResponse state = mock(InspectExecResponse.class);
when(dockerClient.inspectExecCmd(any(String.class))).thenReturn(inspectExecCmd);
when(inspectExecCmd.exec()).thenReturn(state);
when(state.isRunning()).thenReturn(false);
when(state.getExitCode()).thenReturn(exitCode);
final Docker docker = new DockerImpl(dockerClient);
final ProcessResult result = docker.executeInContainer(new ContainerName(containerId), command);
assertThat(result.getExitStatus(), is(exitCode));
}
Aggregations