use of io.kubernetes.client.openapi.models.V1ContainerBuilder in project heron by twitter.
the class V1ControllerTest method testMountVolumeIfPresent.
@Test
public void testMountVolumeIfPresent() {
final String pathDefault = "config-host-volume-path";
final String pathNameDefault = "config-host-volume-name";
final Config configWithVolumes = Config.newBuilder().put(KubernetesContext.KUBERNETES_CONTAINER_VOLUME_MOUNT_NAME, pathNameDefault).put(KubernetesContext.KUBERNETES_CONTAINER_VOLUME_MOUNT_PATH, pathDefault).build();
final V1Controller controllerWithMounts = new V1Controller(configWithVolumes, RUNTIME);
final V1VolumeMount volumeDefault = new V1VolumeMountBuilder().withName(pathNameDefault).withMountPath(pathDefault).build();
final V1VolumeMount volumeCustom = new V1VolumeMountBuilder().withName("custom-volume-mount").withMountPath("should-be-kept").build();
final List<V1VolumeMount> expectedMountsDefault = Collections.singletonList(volumeDefault);
final List<V1VolumeMount> expectedMountsCustom = Arrays.asList(volumeCustom, volumeDefault);
final List<V1VolumeMount> volumeMountsCustomList = Arrays.asList(new V1VolumeMountBuilder().withName(pathNameDefault).withMountPath("should-be-replaced").build(), volumeCustom);
// No Volume Mounts set.
V1Controller controllerDoNotSetMounts = new V1Controller(Config.newBuilder().build(), RUNTIME);
V1Container containerNoSetMounts = new V1Container();
controllerDoNotSetMounts.mountVolumeIfPresent(containerNoSetMounts);
Assert.assertNull(containerNoSetMounts.getVolumeMounts());
// Default. Null Volume Mounts.
V1Container containerNull = new V1ContainerBuilder().build();
controllerWithMounts.mountVolumeIfPresent(containerNull);
Assert.assertTrue("Default VOLUME MOUNTS should be set in container with null VOLUME MOUNTS", CollectionUtils.containsAll(expectedMountsDefault, containerNull.getVolumeMounts()));
// Empty Volume Mounts.
V1Container containerEmpty = new V1ContainerBuilder().withVolumeMounts(new LinkedList<>()).build();
controllerWithMounts.mountVolumeIfPresent(containerEmpty);
Assert.assertTrue("Default VOLUME MOUNTS should be set in container with empty VOLUME MOUNTS", CollectionUtils.containsAll(expectedMountsDefault, containerEmpty.getVolumeMounts()));
// Custom Volume Mounts.
V1Container containerCustom = new V1ContainerBuilder().withVolumeMounts(volumeMountsCustomList).build();
controllerWithMounts.mountVolumeIfPresent(containerCustom);
Assert.assertTrue("Default VOLUME MOUNTS should be set in container with custom VOLUME MOUNTS", CollectionUtils.containsAll(expectedMountsCustom, containerCustom.getVolumeMounts()));
}
Aggregations