Merge branch '2.3.x'

This commit is contained in:
Phillip Webb
2020-06-22 22:37:25 -07:00
7 changed files with 228 additions and 330 deletions

View File

@@ -71,12 +71,42 @@ class ImageNameTests {
@Test
void ofWhenSimpleNameAndPortCreatesImageName() {
ImageName imageName = ImageName.of("repo:8080/ubuntu");
assertThat(imageName.toString()).isEqualTo("repo:8080/ubuntu");
assertThat(imageName.getDomain()).isEqualTo("repo:8080");
assertThat(imageName.getName()).isEqualTo("ubuntu");
}
@Test
void ofWhenSimplePathAndPortCreatesImageName() {
ImageName imageName = ImageName.of("repo:8080/canonical/ubuntu");
assertThat(imageName.toString()).isEqualTo("repo:8080/canonical/ubuntu");
assertThat(imageName.getDomain()).isEqualTo("repo:8080");
assertThat(imageName.getName()).isEqualTo("canonical/ubuntu");
}
@Test
void ofWhenNameWithLongPathCreatesImageName() {
ImageName imageName = ImageName.of("path1/path2/path3/ubuntu");
assertThat(imageName.toString()).isEqualTo("docker.io/path1/path2/path3/ubuntu");
assertThat(imageName.getDomain()).isEqualTo("docker.io");
assertThat(imageName.getName()).isEqualTo("path1/path2/path3/ubuntu");
}
@Test
void ofWhenLocalhostDomainCreatesImageName() {
ImageName imageName = ImageName.of("localhost/ubuntu");
assertThat(imageName.getDomain()).isEqualTo("localhost");
assertThat(imageName.getName()).isEqualTo("ubuntu");
}
@Test
void ofWhenLocalhostDomainAndPathCreatesImageName() {
ImageName imageName = ImageName.of("localhost/library/ubuntu");
assertThat(imageName.getDomain()).isEqualTo("localhost");
assertThat(imageName.getName()).isEqualTo("library/ubuntu");
}
@Test
void ofWhenLegacyDomainUsesNewDomain() {
ImageName imageName = ImageName.of("index.docker.io/ubuntu");
@@ -96,6 +126,25 @@ class ImageNameTests {
assertThatIllegalArgumentException().isThrownBy(() -> ImageName.of("")).withMessage("Value must not be empty");
}
@Test
void ofWhenContainsUppercaseThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> ImageName.of("Test"))
.withMessageContaining("Unable to parse name").withMessageContaining("Test");
}
@Test
void ofWhenNameIncludesTagThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> ImageName.of("ubuntu:latest"))
.withMessageContaining("Unable to parse name").withMessageContaining(":latest");
}
@Test
void ofWhenNameIncludeDigestThrowsException() {
assertThatIllegalArgumentException().isThrownBy(
() -> ImageName.of("ubuntu@sha256:47bfdb88c3ae13e488167607973b7688f69d9e8c142c2045af343ec199649c09"))
.withMessageContaining("Unable to parse name").withMessageContaining("@sha256:47b");
}
@Test
void hashCodeAndEquals() {
ImageName n1 = ImageName.of("ubuntu");

View File

@@ -1,158 +0,0 @@
/*
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.buildpack.platform.docker.type;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests for {@link ImageReferenceParser}.
*
* @author Scott Frederick
*/
class ImageReferenceParserTests {
@Test
void unableToParseWithUppercaseInName() {
assertThatIllegalArgumentException().isThrownBy(() -> ImageReferenceParser.of("Test"))
.withMessageContaining("Test");
}
@Test
void parsesName() {
ImageReferenceParser parser = ImageReferenceParser.of("ubuntu");
assertThat(parser.getDomain()).isNull();
assertThat(parser.getName()).isEqualTo("ubuntu");
assertThat(parser.getTag()).isNull();
assertThat(parser.getDigest()).isNull();
}
@Test
void parsesNameWithPath() {
ImageReferenceParser parser = ImageReferenceParser.of("library/ubuntu");
assertThat(parser.getDomain()).isNull();
assertThat(parser.getName()).isEqualTo("library/ubuntu");
assertThat(parser.getTag()).isNull();
assertThat(parser.getDigest()).isNull();
}
@Test
void parsesNameWithLongPath() {
ImageReferenceParser parser = ImageReferenceParser.of("path1/path2/path3/ubuntu");
assertThat(parser.getDomain()).isNull();
assertThat(parser.getName()).isEqualTo("path1/path2/path3/ubuntu");
assertThat(parser.getTag()).isNull();
assertThat(parser.getDigest()).isNull();
}
@Test
void parsesDomainAndNameWithPath() {
ImageReferenceParser parser = ImageReferenceParser.of("repo.example.com/library/ubuntu");
assertThat(parser.getDomain()).isEqualTo("repo.example.com");
assertThat(parser.getName()).isEqualTo("library/ubuntu");
assertThat(parser.getTag()).isNull();
assertThat(parser.getDigest()).isNull();
}
@Test
void parsesDomainWithPortAndNameWithPath() {
ImageReferenceParser parser = ImageReferenceParser.of("repo.example.com:8080/library/ubuntu");
assertThat(parser.getDomain()).isEqualTo("repo.example.com:8080");
assertThat(parser.getName()).isEqualTo("library/ubuntu");
assertThat(parser.getTag()).isNull();
assertThat(parser.getDigest()).isNull();
}
@Test
void parsesSimpleDomainWithPortAndName() {
ImageReferenceParser parser = ImageReferenceParser.of("repo:8080/ubuntu");
assertThat(parser.getDomain()).isEqualTo("repo:8080");
assertThat(parser.getName()).isEqualTo("ubuntu");
assertThat(parser.getTag()).isNull();
assertThat(parser.getDigest()).isNull();
}
@Test
void parsesSimpleDomainWithPortAndNameWithPath() {
ImageReferenceParser parser = ImageReferenceParser.of("repo:8080/library/ubuntu");
assertThat(parser.getDomain()).isEqualTo("repo:8080");
assertThat(parser.getName()).isEqualTo("library/ubuntu");
assertThat(parser.getTag()).isNull();
assertThat(parser.getDigest()).isNull();
}
@Test
void parsesLocalhostDomainAndName() {
ImageReferenceParser parser = ImageReferenceParser.of("localhost/ubuntu");
assertThat(parser.getDomain()).isEqualTo("localhost");
assertThat(parser.getName()).isEqualTo("ubuntu");
assertThat(parser.getTag()).isNull();
assertThat(parser.getDigest()).isNull();
}
@Test
void parsesLocalhostDomainAndNameWithPath() {
ImageReferenceParser parser = ImageReferenceParser.of("localhost/library/ubuntu");
assertThat(parser.getDomain()).isEqualTo("localhost");
assertThat(parser.getName()).isEqualTo("library/ubuntu");
assertThat(parser.getTag()).isNull();
assertThat(parser.getDigest()).isNull();
}
@Test
void parsesNameAndTag() {
ImageReferenceParser parser = ImageReferenceParser.of("ubuntu:v1");
assertThat(parser.getDomain()).isNull();
assertThat(parser.getName()).isEqualTo("ubuntu");
assertThat(parser.getTag()).isEqualTo("v1");
assertThat(parser.getDigest()).isNull();
}
@Test
void parsesNameAndDigest() {
ImageReferenceParser parser = ImageReferenceParser
.of("ubuntu@sha256:47bfdb88c3ae13e488167607973b7688f69d9e8c142c2045af343ec199649c09");
assertThat(parser.getDomain()).isNull();
assertThat(parser.getName()).isEqualTo("ubuntu");
assertThat(parser.getTag()).isNull();
assertThat(parser.getDigest())
.isEqualTo("sha256:47bfdb88c3ae13e488167607973b7688f69d9e8c142c2045af343ec199649c09");
}
@Test
void parsesReferenceWithTag() {
ImageReferenceParser parser = ImageReferenceParser.of("repo.example.com:8080/library/ubuntu:v1");
assertThat(parser.getDomain()).isEqualTo("repo.example.com:8080");
assertThat(parser.getName()).isEqualTo("library/ubuntu");
assertThat(parser.getTag()).isEqualTo("v1");
assertThat(parser.getDigest()).isNull();
}
@Test
void parsesReferenceWithDigest() {
ImageReferenceParser parser = ImageReferenceParser.of(
"repo.example.com:8080/library/ubuntu@sha256:47bfdb88c3ae13e488167607973b7688f69d9e8c142c2045af343ec199649c09");
assertThat(parser.getDomain()).isEqualTo("repo.example.com:8080");
assertThat(parser.getName()).isEqualTo("library/ubuntu");
assertThat(parser.getTag()).isNull();
assertThat(parser.getDigest())
.isEqualTo("sha256:47bfdb88c3ae13e488167607973b7688f69d9e8c142c2045af343ec199649c09");
}
}

View File

@@ -102,6 +102,16 @@ class ImageReferenceTests {
assertThat(reference.toString()).isEqualTo("docker.io/library/ubuntu:bionic");
}
@Test
void ofDomainPortAndTag() {
ImageReference reference = ImageReference.of("repo.example.com:8080/library/ubuntu:v1");
assertThat(reference.getDomain()).isEqualTo("repo.example.com:8080");
assertThat(reference.getName()).isEqualTo("library/ubuntu");
assertThat(reference.getTag()).isEqualTo("v1");
assertThat(reference.getDigest()).isNull();
assertThat(reference.toString()).isEqualTo("repo.example.com:8080/library/ubuntu:v1");
}
@Test
void ofNameAndDigest() {
ImageReference reference = ImageReference