-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test (jkube-kit) : Add ImageName upstream compatibility tests
Add tests for ImageName for ORAS reference and Docker Distribution reference. Signed-off-by: Rohan Kumar <rohaan@redhat.com>
- Loading branch information
1 parent
58d6617
commit 0898414
Showing
2 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
.../src/test/java/org/eclipse/jkube/kit/config/image/ImageNameDistributionReferenceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.config.image; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; | ||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
/** | ||
* This test has been added to ensure ImageName's upstream compatibility with Docker Distribution Reference. | ||
* Tests ported from <a href="https://github.com/distribution/reference/blob/8507c7fcf0da9f570540c958ea7b972c30eeaeca/reference_test.go">Distribution Reference</a> | ||
*/ | ||
class ImageNameDistributionReferenceTest { | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { | ||
"test.com/foo", | ||
"test:8080/foo", | ||
"docker.io/library/foo", | ||
"test_com", | ||
"test.com:tag", | ||
"test.com:5000", | ||
"test.com/repo:tag", | ||
"test:5000/repo", | ||
"test:5000/repo:tag", | ||
"lowercase:Uppercase", | ||
"test:5000/repo@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", | ||
"test:5000/repo:tag@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", | ||
"sub-dom1.foo.com/bar/baz/quux", | ||
"sub-dom1.foo.com/bar/baz/quux:some-long-tag", | ||
"b.gcr.io/test.example.com/my-app:test.example.com", | ||
"xn--n3h.com/myimage:xn--n3h.com", | ||
//"xn--7o8h.com/myimage:xn--7o8h.com@sha512:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", // https://github.com/eclipse/jkube/issues/2540 | ||
"foo_bar.com:8080", | ||
"foo/foo_bar.com:8080", | ||
"192.168.1.1", | ||
"192.168.1.1:tag", | ||
"192.168.1.1:5000", | ||
"192.168.1.1/repo", | ||
"192.168.1.1:5000/repo", | ||
"192.168.1.1:5000/repo:5050", | ||
"a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a:tag-puts-this-over-max", | ||
"docker/docker", | ||
"library/debian", | ||
"debian", | ||
"localhost/library/debian", | ||
"localhost/debian", | ||
"docker.io/docker/docker", | ||
"docker.io/library/debian", | ||
"docker.io/debian", | ||
"index.docker.io/docker/docker", | ||
"index.docker.io/library/debian", | ||
"index.docker.io/debian", | ||
"127.0.0.1:5000/docker/docker", | ||
"127.0.0.1:5000/library/debian", | ||
"127.0.0.1:5000/debian", | ||
"192.168.0.1", | ||
"192.168.0.1:80", | ||
"192.168.0.1:8/debian", | ||
"192.168.0.2:25000/debian", | ||
"docker.io/1a3f5e7d9c1b3a5f7e9d1c3b5a7f9e1d3c5b7a9f1e3d5d7c9b1a3f5e7d9c1b3a", | ||
//"[2001:db8::1]/repo", // https://github.com/eclipse/jkube/issues/2541 | ||
//"[2001:db8:1:2:3:4:5:6]/repo:tag", // https://github.com/eclipse/jkube/issues/2541 | ||
//"[2001:db8::1]:5000/repo", // https://github.com/eclipse/jkube/issues/2541 | ||
//"[2001:db8::1]:5000/repo:tag", // https://github.com/eclipse/jkube/issues/2541 | ||
//"[2001:db8::1]:5000/repo@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", // https://github.com/eclipse/jkube/issues/2541 | ||
//"[2001:db8::1]:5000/repo:tag@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", // https://github.com/eclipse/jkube/issues/2541 | ||
//"[2001:db8::]:5000/repo", // https://github.com/eclipse/jkube/issues/2541 | ||
//"[::1]:5000/repo", // https://github.com/eclipse/jkube/issues/2541 | ||
}) | ||
void validNames(String name) { | ||
// Given | ||
ImageName imageName = new ImageName(name); | ||
|
||
// When + Then | ||
assertThat(imageName).isNotNull(); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { | ||
"", | ||
":justtag", | ||
"@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", | ||
//"a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a:tag", // https://github.com/eclipse/jkube/issues/2542 | ||
//"repo@sha256:ffffffffffffffffffffffffffffffffff", // https://github.com/eclipse/jkube/issues/2543 | ||
"validname@invaliddigest:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", | ||
"Uppercase:tag", | ||
"test:5000/Uppercase/lowercase:tag", | ||
"aa/asdf$$^/aa", | ||
//"[fe80::1%eth0]:5000/repo", // https://github.com/eclipse/jkube/issues/2541 | ||
//"[fe80::1%@invalidzone]:5000/repo", // https://github.com/eclipse/jkube/issues/2541 | ||
}) | ||
void invalidNames(String name) { | ||
assertThatIllegalArgumentException().isThrownBy(() -> new ImageName(name)); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...ig/image/src/test/java/org/eclipse/jkube/kit/config/image/ImageNameORASReferenceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.config.image; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; | ||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
/** | ||
* This test has been added to ensure ImageName's upstream compatibility with OCI Registry Reference. | ||
* Tests ported from <a href="https://github.com/oras-project/oras-go/blob/3b1dd0e9700082fe7bc690a745263c06361417dd/registry/reference_test.go">ORAS Reference</a> | ||
*/ | ||
class ImageNameORASReferenceTest { | ||
@ParameterizedTest | ||
@ValueSource(strings = { | ||
"localhost/hello-world@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
"localhost/hello-world:v1", | ||
"localhost/hello-world", | ||
"registry.example.com/hello-world@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
"registry.example.com/hello-world:v1", | ||
"registry.example.com/hello-world", | ||
"localhost:5000/hello-world@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
"localhost:5000/hello-world:v1", | ||
"localhost:5000/hello-world", | ||
"127.0.0.1:5000/hello-world@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
"127.0.0.1:5000/hello-world:v1", | ||
"127.0.0.1:5000/hello-world", | ||
"localhost/hello-world:v2@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
"registry.example.com/hello-world:v2@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
"localhost:5000/hello-world:v2@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
"127.0.0.1:5000/hello-world:v2@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
//"[::1]:5000/hello-world:v1", // https://github.com/eclipse/jkube/issues/2541 | ||
//"registry.example.com/hello-world:@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", // https://github.com/eclipse/jkube/issues/2545 | ||
}) | ||
void validImageNamesCompatibleWithAll(String name) { | ||
// Given + When | ||
ImageName imageName = new ImageName(name); | ||
|
||
// Then | ||
assertThat(imageName).isNotNull(); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { | ||
"localhost/UPPERCASE/test", // Invalid repo name | ||
"localhost:v1/hello-world", // Invalid port | ||
"registry.example.com/hello-world:foobar:sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", // Invalid Digest prefix: colon instead of the at sign | ||
"registry.example.com/hello-world@@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", // Invalid Digest prefix: double at sign | ||
"registry.example.com/hello-world @sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", // Invalid Digest prefix: space | ||
//"registry.example.com/foobar@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde" // https://github.com/eclipse/jkube/issues/2543 | ||
}) | ||
void invalidImageNames(String name) { | ||
assertThatIllegalArgumentException().isThrownBy(() -> new ImageName(name)); | ||
} | ||
} |