use of org.eclipse.che.plugin.docker.client.params.CreateExecParams in project che by eclipse.
the class DockerConnectorTest method shouldBeAbleToCreateExec.
@Test
public void shouldBeAbleToCreateExec() throws IOException, JsonParseException {
CreateExecParams createExecParams = CreateExecParams.create(CONTAINER, CMD_WITH_ARGS);
Exec exec = new Exec(CMD_WITH_ARGS, EXEC_ID);
ExecCreated execCreated = mock(ExecCreated.class);
doReturn(execCreated).when(dockerConnector).parseResponseStreamAndClose(inputStream, ExecCreated.class);
when(execCreated.getId()).thenReturn(EXEC_ID);
Exec returnedExec = dockerConnector.createExec(createExecParams);
verify(dockerConnectionFactory).openConnection(any(URI.class));
verify(dockerConnection).method(REQUEST_METHOD_POST);
verify(dockerConnection).path("/containers/" + createExecParams.getContainer() + "/exec");
verify(dockerConnection).header("Content-Type", MediaType.APPLICATION_JSON);
verify(dockerConnection).header(eq("Content-Length"), anyInt());
verify(dockerConnection).entity(any(byte[].class));
verify(dockerConnection).request();
verify(dockerResponse).getStatus();
verify(dockerResponse).getInputStream();
assertEquals(returnedExec, exec);
}
use of org.eclipse.che.plugin.docker.client.params.CreateExecParams in project che by eclipse.
the class KeysInjectorTest method shouldInjectSshKeysWhenThereIsNoPublicWorkspaceKeyButMachineKeys.
/**
* Validate the usecase: There is a workspace sshkeypair (without public key) but there is a machine keypair
* Expect that only the machine keypair is injected (as workspace keypair has no public key).
*/
@Test
public void shouldInjectSshKeysWhenThereIsNoPublicWorkspaceKeyButMachineKeys() throws Exception {
// no machine key pairs
when(sshManager.getPairs(anyString(), eq("machine"))).thenReturn(Arrays.asList(new SshPairImpl(OWNER, "machine", "myPair", "publicKey1", null)));
// workspace keypair without public key
when(sshManager.getPair(anyString(), eq("workspace"), anyString())).thenReturn(new SshPairImpl(OWNER, "workspace", WORKSPACE_ID, null, null));
subscriber.onEvent(newDto(MachineStatusEvent.class).withEventType(MachineStatusEvent.EventType.RUNNING).withMachineId(MACHINE_ID).withWorkspaceId(WORKSPACE_ID));
verify(environmentEngine).getMachine(eq(WORKSPACE_ID), eq(MACHINE_ID));
// check calls for machine and workspace ssh pairs
verify(sshManager).getPairs(eq(OWNER), eq("machine"));
verify(sshManager).getPair(eq(OWNER), eq("workspace"), eq(WORKSPACE_ID));
ArgumentCaptor<CreateExecParams> argumentCaptor = ArgumentCaptor.forClass(CreateExecParams.class);
verify(docker).createExec(argumentCaptor.capture());
assertEquals(argumentCaptor.getValue().getCmd(), new String[] { "/bin/bash", "-c", "mkdir ~/.ssh/ -p" + "&& echo 'publicKey1' >> ~/.ssh/authorized_keys" });
verify(docker).startExec(eq(StartExecParams.create(EXEC_ID)), anyObject());
verifyZeroInteractions(docker, environmentEngine, sshManager);
}
use of org.eclipse.che.plugin.docker.client.params.CreateExecParams in project che by eclipse.
the class KeysInjectorTest method shouldInjectSshKeysWhenThereIsOnlyWorkspaceKey.
/**
* Validate the usecase: There is a workspace sshkeypair but no machine keypair (empty list)
* Expect that the workspace public key is injected.
*/
@Test
public void shouldInjectSshKeysWhenThereIsOnlyWorkspaceKey() throws Exception {
// no machine key pairs
when(sshManager.getPairs(anyString(), eq("machine"))).thenReturn(Collections.emptyList());
// workspace keypair
when(sshManager.getPair(anyString(), eq("workspace"), anyString())).thenReturn(new SshPairImpl(OWNER, "workspace", WORKSPACE_ID, "publicKeyWorkspace", null));
subscriber.onEvent(newDto(MachineStatusEvent.class).withEventType(MachineStatusEvent.EventType.RUNNING).withMachineId(MACHINE_ID).withWorkspaceId(WORKSPACE_ID));
verify(environmentEngine).getMachine(eq(WORKSPACE_ID), eq(MACHINE_ID));
// check calls for machine and workspace ssh pairs
verify(sshManager).getPairs(eq(OWNER), eq("machine"));
verify(sshManager).getPair(eq(OWNER), eq("workspace"), eq(WORKSPACE_ID));
ArgumentCaptor<CreateExecParams> argumentCaptor = ArgumentCaptor.forClass(CreateExecParams.class);
verify(docker).createExec(argumentCaptor.capture());
assertEquals(argumentCaptor.getValue().getCmd(), new String[] { "/bin/bash", "-c", "mkdir ~/.ssh/ -p" + "&& echo 'publicKeyWorkspace' >> ~/.ssh/authorized_keys" });
verify(docker).startExec(eq(StartExecParams.create(EXEC_ID)), anyObject());
verifyZeroInteractions(docker, environmentEngine, sshManager);
}
use of org.eclipse.che.plugin.docker.client.params.CreateExecParams in project che by eclipse.
the class DockerConnectorTest method shouldThrowDockerExceptionWhileCreatingExecIfResponseCodeIsNotSuccess.
@Test(expectedExceptions = DockerException.class, expectedExceptionsMessageRegExp = EXCEPTION_ERROR_MESSAGE)
public void shouldThrowDockerExceptionWhileCreatingExecIfResponseCodeIsNotSuccess() throws IOException {
CreateExecParams inspectContainerParams = CreateExecParams.create(CONTAINER, CMD_WITH_ARGS);
when(dockerResponse.getStatus()).thenReturn(RESPONSE_ERROR_CODE);
dockerConnector.createExec(inspectContainerParams);
verify(dockerResponse).getStatus();
}
Aggregations