JobAssertions { public Map<String, String> validateImage(Image image) { if (image == null) { return Collections.emptyMap(); } Map<String, String> violations = new HashMap<>(); if (!IMAGE_NAME_PATTERN.matcher(image.getName()).matches()) { violations.put("name", "image name is not valid"); } boolean validDigest = !Strings.isNullOrEmpty(image.getDigest()) && IMAGE_DIGEST_PATTERN.matcher(image.getDigest()).matches(); boolean validTag = !Strings.isNullOrEmpty(image.getTag()) && IMAGE_TAG_PATTERN.matcher(image.getTag()).matches(); if (!validDigest && !validTag) { violations.put("noValidImageDigestOrTag", "must specify a valid digest or tag"); } return violations; } JobAssertions(JobConfiguration configuration,
                         Function<String, ResourceDimension> maxContainerSizeResolver); boolean isValidSyntax(List<String> securityGroups); boolean isValidIamRole(String iamRole); boolean isEntryPointNotTooLarge(List<String> entryPoint); Map<String, String> validateEnvironmentVariableNames(Map<String, String> environment); boolean areEnvironmentVariablesNotTooLarge(Map<String, String> environment); boolean isValidContainerHealthServiceName(String name); Map<String, String> validateImage(Image image); Map<String, String> notExceedsComputeResources(String capacityGroup, Container container); Map<String, String> notExceedsIpAllocations(Container container, JobDescriptor.JobDescriptorExt extension); static final int MAX_ENTRY_POINT_SIZE_SIZE_KB; static final int MAX_ENTRY_POINT_SIZE_SIZE_BYTES; }
@Test public void testImageDigestValidation() { Image image = Image.newBuilder() .withName("imageName") .withDigest("sha256:abcdef0123456789abcdef0123456789abcdef0123456789") .build(); Map<String, String> violations = jobAssertions.validateImage(image); assertThat(violations).isEmpty(); }
@Test public void testInvalidDigestValidation() { Image image = Image.newBuilder() .withName("imageName") .withDigest("sha256:XYZ") .build(); Map<String, String> violations = jobAssertions.validateImage(image); assertThat(violations).hasSize(1); }