Search in sources :

Example 16 with CreateContainerParams

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())));
}
Also used : RemoveContainerParams(org.eclipse.che.plugin.docker.client.params.RemoveContainerParams) Arrays(java.util.Arrays) Listeners(org.testng.annotations.Listeners) InspectContainerParams(org.eclipse.che.plugin.docker.client.params.InspectContainerParams) DockerConnectorProvider(org.eclipse.che.plugin.docker.client.DockerConnectorProvider) Volume(org.eclipse.che.plugin.docker.client.json.Volume) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) DOCKER_FILE_TYPE(org.eclipse.che.plugin.docker.machine.DockerInstanceProvider.DOCKER_FILE_TYPE) Mockito.doThrow(org.mockito.Mockito.doThrow) Collections.singleton(java.util.Collections.singleton) Collectors.toMap(java.util.stream.Collectors.toMap) Arrays.asList(java.util.Arrays.asList) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) Assert.assertFalse(org.testng.Assert.assertFalse) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) MachineConfig(org.eclipse.che.api.core.model.machine.MachineConfig) BeforeMethod(org.testng.annotations.BeforeMethod) RecipeRetriever(org.eclipse.che.api.machine.server.util.RecipeRetriever) Set(java.util.Set) Collectors(java.util.stream.Collectors) WindowsPathEscaper(org.eclipse.che.commons.lang.os.WindowsPathEscaper) MACHINE_SNAPSHOT_PREFIX(org.eclipse.che.plugin.docker.machine.DockerInstanceProvider.MACHINE_SNAPSHOT_PREFIX) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Stream(java.util.stream.Stream) ContainerConfig(org.eclipse.che.plugin.docker.client.json.ContainerConfig) TagParams(org.eclipse.che.plugin.docker.client.params.TagParams) ServerConfImpl(org.eclipse.che.api.machine.server.model.impl.ServerConfImpl) CreateContainerParams(org.eclipse.che.plugin.docker.client.params.CreateContainerParams) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) UserSpecificDockerRegistryCredentialsProvider(org.eclipse.che.plugin.docker.client.UserSpecificDockerRegistryCredentialsProvider) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) PullParams(org.eclipse.che.plugin.docker.client.params.PullParams) DockerConnectorConfiguration(org.eclipse.che.plugin.docker.client.DockerConnectorConfiguration) DataProvider(org.testng.annotations.DataProvider) Mock(org.mockito.Mock) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) RecipeImpl(org.eclipse.che.api.machine.server.recipe.RecipeImpl) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) ContainerCreated(org.eclipse.che.plugin.docker.client.json.ContainerCreated) Mockito.spy(org.mockito.Mockito.spy) Function(java.util.function.Function) StartContainerParams(org.eclipse.che.plugin.docker.client.params.StartContainerParams) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) RemoveImageParams(org.eclipse.che.plugin.docker.client.params.RemoveImageParams) HashSet(java.util.HashSet) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) ProgressMonitor(org.eclipse.che.plugin.docker.client.ProgressMonitor) ArgumentCaptor(org.mockito.ArgumentCaptor) ContainerState(org.eclipse.che.plugin.docker.client.json.ContainerState) Collections.singletonMap(java.util.Collections.singletonMap) ContainerInfo(org.eclipse.che.plugin.docker.client.json.ContainerInfo) Collections.emptySet(java.util.Collections.emptySet) DockerNode(org.eclipse.che.plugin.docker.machine.node.DockerNode) ServerConf(org.eclipse.che.api.core.model.machine.ServerConf) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Machine(org.eclipse.che.api.core.model.machine.Machine) Mockito.never(org.mockito.Mockito.never) ServerException(org.eclipse.che.api.core.ServerException) DockerConnector(org.eclipse.che.plugin.docker.client.DockerConnector) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) Assert.assertEqualsNoOrder(org.testng.Assert.assertEqualsNoOrder) HashMap(java.util.HashMap) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CreateContainerParams(org.eclipse.che.plugin.docker.client.params.CreateContainerParams) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 17 with CreateContainerParams

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()));
}
Also used : CreateContainerParams(org.eclipse.che.plugin.docker.client.params.CreateContainerParams) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 18 with CreateContainerParams

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);
}
Also used : CreateContainerParams(org.eclipse.che.plugin.docker.client.params.CreateContainerParams) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 19 with CreateContainerParams

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);
}
Also used : ContainerConfig(org.eclipse.che.plugin.docker.client.json.ContainerConfig) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CreateContainerParams(org.eclipse.che.plugin.docker.client.params.CreateContainerParams) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 20 with CreateContainerParams

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));
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CreateContainerParams(org.eclipse.che.plugin.docker.client.params.CreateContainerParams) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Aggregations

CreateContainerParams (org.eclipse.che.plugin.docker.client.params.CreateContainerParams)21 Test (org.testng.annotations.Test)21 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)15 Matchers.anyString (org.mockito.Matchers.anyString)15 ContainerConfig (org.eclipse.che.plugin.docker.client.json.ContainerConfig)14 ArrayList (java.util.ArrayList)12 ContainerCreated (org.eclipse.che.plugin.docker.client.json.ContainerCreated)11 IOException (java.io.IOException)10 Arrays (java.util.Arrays)10 Arrays.asList (java.util.Arrays.asList)10 Collections (java.util.Collections)10 Collections.emptySet (java.util.Collections.emptySet)10 Collections.singleton (java.util.Collections.singleton)10 Collections.singletonMap (java.util.Collections.singletonMap)10 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)10 List (java.util.List)10 Map (java.util.Map)10 Set (java.util.Set)10 Function (java.util.function.Function)10