VolumeUtils { public static String getValidVolumeName(String originalName) { if (originalName == null) { throw new RuntimeException("Volume name cannot be null"); } if (volumeNamePattern.matcher(originalName).matches()) { return originalName; } else { return makeValidVolumeName(originalName); } }  static Volume createConfigMapVolume(String name, String configMapName); static Volume createSecretVolume(String name, String secretName, Map<String, String> items, boolean isOpenshift); static Volume createSecretVolume(String name, String secretName, boolean isOpenshift); static Volume createEmptyDirVolume(String name, String sizeLimit); static PersistentVolumeClaim createPersistentVolumeClaimTemplate(String name, PersistentClaimStorage storage); static VolumeMount createVolumeMount(String name, String path); static List<Volume> getDataVolumes(Storage storage); static List<PersistentVolumeClaim> getDataPersistentVolumeClaims(Storage storage); static List<VolumeMount> getDataVolumeMountPaths(Storage storage, String mountPath); static String getVolumePrefix(Integer id); static String getValidVolumeName(String originalName);  }
@Test public void testValidVolumeNames() { assertThat(VolumeUtils.getValidVolumeName("my-user"), is("my-user")); assertThat(VolumeUtils.getValidVolumeName("my-0123456789012345678901234567890123456789012345678901234-user"), is("my-0123456789012345678901234567890123456789012345678901234-user")); }
@Test public void testInvalidVolumeNames() { assertThat(VolumeUtils.getValidVolumeName("my.user"), is("my-user-4dbf077e")); assertThat(VolumeUtils.getValidVolumeName("my_user"), is("my-user-e10dbc61")); assertThat(VolumeUtils.getValidVolumeName("my-very-long-012345678901234567890123456789012345678901234567890123456789-user"), is("my-very-long-01234567890123456789012345678901234567890-12a964dc")); assertThat(VolumeUtils.getValidVolumeName("my-very-long-0123456789012345678901234567890123456789-1234567890123456789-user"), is("my-very-long-0123456789012345678901234567890123456789-348f6fec")); assertThat(VolumeUtils.getValidVolumeName("my.bridge.012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"), is("my-bridge-01234567890123456789012345678901234567890123-30a4fce1")); assertThat(VolumeUtils.getValidVolumeName("a.a"), is("a-a-5bd24583")); assertThat(VolumeUtils.getValidVolumeName("a"), is("a-86f7e437")); }