use of org.eclipse.che.plugin.docker.client.params.CreateContainerParams in project che by eclipse.
the class MachineProviderImplTest method shouldAddEnvVarsFromMachineConfigToContainerOnNonDevInstanceCreationFromSnapshot.
@Test
public void shouldAddEnvVarsFromMachineConfigToContainerOnNonDevInstanceCreationFromSnapshot() throws Exception {
// given
Map<String, String> envVarsFromConfig = new HashMap<>();
envVarsFromConfig.put("ENV_VAR1", "123");
envVarsFromConfig.put("ENV_VAR2", "234");
final boolean isDev = false;
CheServiceImpl machine = createService();
machine.setEnvironment(envVarsFromConfig);
// when
createInstanceFromSnapshot(machine, isDev);
// then
ArgumentCaptor<CreateContainerParams> argumentCaptor = ArgumentCaptor.forClass(CreateContainerParams.class);
verify(dockerConnector).createContainer(argumentCaptor.capture());
assertTrue(asList(argumentCaptor.getValue().getContainerConfig().getEnv()).containsAll(envVarsFromConfig.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.toList())));
}
use of org.eclipse.che.plugin.docker.client.params.CreateContainerParams in project che by eclipse.
the class MachineProviderImplTest method shouldAddWorkspaceIdEnvVariableOnDevInstanceCreationFromSnapshot.
@Test
public void shouldAddWorkspaceIdEnvVariableOnDevInstanceCreationFromSnapshot() throws Exception {
String wsId = "myWs";
createInstanceFromSnapshot(true, wsId);
ArgumentCaptor<CreateContainerParams> argumentCaptor = ArgumentCaptor.forClass(CreateContainerParams.class);
verify(dockerConnector).createContainer(argumentCaptor.capture());
assertTrue(asList(argumentCaptor.getValue().getContainerConfig().getEnv()).contains(DockerInstanceRuntimeInfo.CHE_WORKSPACE_ID + "=" + wsId), "Workspace Id variable is missing. Required " + DockerInstanceRuntimeInfo.CHE_WORKSPACE_ID + "=" + wsId + ". Found " + Arrays.toString(argumentCaptor.getValue().getContainerConfig().getEnv()));
}
use of org.eclipse.che.plugin.docker.client.params.CreateContainerParams in project che by eclipse.
the class MachineProviderImplTest method shouldNotAddWorkspaceIdEnvVariableOnNonDevInstanceCreationFromRecipe.
@Test
public void shouldNotAddWorkspaceIdEnvVariableOnNonDevInstanceCreationFromRecipe() throws Exception {
String wsId = "myWs";
createInstanceFromRecipe(false, wsId);
ArgumentCaptor<CreateContainerParams> argumentCaptor = ArgumentCaptor.forClass(CreateContainerParams.class);
verify(dockerConnector).createContainer(argumentCaptor.capture());
assertFalse(asList(argumentCaptor.getValue().getContainerConfig().getEnv()).contains(DockerInstanceRuntimeInfo.CHE_WORKSPACE_ID + "=" + wsId), "Non dev machine should not contains " + DockerInstanceRuntimeInfo.CHE_WORKSPACE_ID);
}
use of org.eclipse.che.plugin.docker.client.params.CreateContainerParams in project che by eclipse.
the class MachineProviderImplTest method shouldAddLinksToContainerOnCreation.
@Test
public void shouldAddLinksToContainerOnCreation() throws Exception {
// given
String[] links = new String[] { "container1", "container2:alias" };
CheServiceImpl service = createService();
service.setLinks(asList(links));
// when
createInstanceFromRecipe(service, true);
// then
ArgumentCaptor<CreateContainerParams> argumentCaptor = ArgumentCaptor.forClass(CreateContainerParams.class);
verify(dockerConnector).createContainer(argumentCaptor.capture());
ContainerConfig containerConfig = argumentCaptor.getValue().getContainerConfig();
assertEquals(containerConfig.getHostConfig().getLinks(), links);
assertEquals(containerConfig.getNetworkingConfig().getEndpointsConfig().get(NETWORK_NAME).getLinks(), links);
}
use of org.eclipse.che.plugin.docker.client.params.CreateContainerParams in project che by eclipse.
the class MachineProviderImplTest method shouldAddServersConfsPortsFromMachineConfigToExposedPortsOnNonDevInstanceCreationFromRecipe.
@Test
public void shouldAddServersConfsPortsFromMachineConfigToExposedPortsOnNonDevInstanceCreationFromRecipe() throws Exception {
// given
final boolean isDev = false;
CheServiceImpl machine = createService();
machine.setExpose(asList("9090", "8080"));
List<String> expectedExposedPorts = asList("9090", "8080");
// when
createInstanceFromRecipe(machine, isDev);
// then
ArgumentCaptor<CreateContainerParams> argumentCaptor = ArgumentCaptor.forClass(CreateContainerParams.class);
verify(dockerConnector).createContainer(argumentCaptor.capture());
assertTrue(new ArrayList<>(argumentCaptor.getValue().getContainerConfig().getExposedPorts().keySet()).containsAll(expectedExposedPorts));
}
Aggregations