use of org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe in project devspaces-images by redhat-developer.
the class KubernetesEnvironmentFactoryTest method exceptionOnObjectWithNoMetadataSpecified.
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "MyObject metadata must not be null")
public void exceptionOnObjectWithNoMetadataSpecified() throws Exception {
HasMetadata object = mock(HasMetadata.class);
when(object.getKind()).thenReturn("MyObject");
when(object.getMetadata()).thenReturn(null);
when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(singletonList(object));
k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
}
use of org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe in project devspaces-images by redhat-developer.
the class KubernetesEnvironmentFactoryTest method shouldMergeDeploymentAndPodIntoOneDeployment.
@Test
public void shouldMergeDeploymentAndPodIntoOneDeployment() throws Exception {
// given
PodTemplateSpec podTemplate = new PodTemplateSpecBuilder().withNewMetadata().withName("deployment-pod").endMetadata().withNewSpec().endSpec().build();
Deployment deployment = new DeploymentBuilder().withNewMetadata().withName("deployment-test").endMetadata().withNewSpec().withTemplate(podTemplate).endSpec().build();
Pod pod = new PodBuilder().withNewMetadata().withName("bare-pod").endMetadata().withNewSpec().endSpec().build();
when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(asList(deployment, pod));
Deployment merged = createEmptyDeployment("merged");
when(podMerger.merge(any())).thenReturn(merged);
// when
final KubernetesEnvironment k8sEnv = k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
// then
verify(podMerger).merge(asList(new PodData(pod), new PodData(deployment)));
assertEquals(k8sEnv.getPodsData().size(), 1);
assertTrue(k8sEnv.getPodsCopy().isEmpty());
assertEquals(k8sEnv.getDeploymentsCopy().size(), 1);
assertEquals(k8sEnv.getDeploymentsCopy().get("merged"), merged);
}
use of org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe in project che-server by eclipse-che.
the class KubernetesEnvironmentFactoryTest method addDeploymentsWhenRecipeContainsThem.
@Test
public void addDeploymentsWhenRecipeContainsThem() throws Exception {
// given
PodTemplateSpec podTemplate = new PodTemplateSpecBuilder().withNewMetadata().withName("deployment-pod").endMetadata().withNewSpec().endSpec().build();
Deployment deployment = new DeploymentBuilder().withNewMetadata().withName("deployment-test").endMetadata().withNewSpec().withTemplate(podTemplate).endSpec().build();
when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(singletonList(deployment));
// when
final KubernetesEnvironment k8sEnv = k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
// then
assertEquals(k8sEnv.getDeploymentsCopy().size(), 1);
assertEquals(k8sEnv.getDeploymentsCopy().get("deployment-test"), deployment);
assertEquals(k8sEnv.getPodsData().size(), 1);
assertEquals(k8sEnv.getPodsData().get("deployment-test").getMetadata(), podTemplate.getMetadata());
assertEquals(k8sEnv.getPodsData().get("deployment-test").getSpec(), podTemplate.getSpec());
}
use of org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe in project che-server by eclipse-che.
the class KubernetesEnvironmentFactoryTest method exceptionOnRecipeLoadError.
@Test(expectedExceptions = ValidationException.class)
public void exceptionOnRecipeLoadError() throws Exception {
when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenThrow(new ValidationException("Could not parse recipe"));
k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
}
use of org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe in project che-server by eclipse-che.
the class KubernetesEnvironmentFactoryTest method shouldCreateK8sEnvironmentWithPVCsFromRecipe.
@Test
public void shouldCreateK8sEnvironmentWithPVCsFromRecipe() throws Exception {
// given
PersistentVolumeClaim pvc1 = new PersistentVolumeClaimBuilder().withNewMetadata().withName("pvc1").endMetadata().build();
PersistentVolumeClaim pvc2 = new PersistentVolumeClaimBuilder().withNewMetadata().withName("pvc2").endMetadata().build();
when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(asList(pvc1, pvc2));
// when
KubernetesEnvironment k8sEnv = k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
// then
assertEquals(k8sEnv.getPersistentVolumeClaims().size(), 2);
assertEquals(k8sEnv.getPersistentVolumeClaims().get("pvc1"), pvc1);
assertEquals(k8sEnv.getPersistentVolumeClaims().get("pvc2"), pvc2);
}
Aggregations