Fix bug in VmwHarborProxyImageNameSubstitutor when resolving non-Spring Docker Images in VMware Harbor Proxy.

This commit is contained in:
John Blum
2023-05-13 12:35:11 -07:00
parent c41796e940
commit 441d3a4bcf
2 changed files with 56 additions and 4 deletions

View File

@@ -41,13 +41,13 @@ public class VmwHarborProxyImageNameSubstitutor extends ImageNameSubstitutor {
private static final String TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX =
VMWARE_HARBOR_PROXY_URL.concat("/dockerhub-proxy-cache/");
private static final String TESTCONTAINERS_HUB_IMAGE_NAME_TEMPLATE =
protected static final String TESTCONTAINERS_HUB_IMAGE_NAME_TEMPLATE =
TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX.concat("%s");
private static final String TESTCONTAINERS_SPRINGCI_HUB_IMAGE_NAME_PREFIX =
TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX.concat("springci/");
private static final String TESTCONTAINERS_SPRINGCI_HUB_IMAGE_NAME_TEMPLATE =
protected static final String TESTCONTAINERS_SPRINGCI_HUB_IMAGE_NAME_TEMPLATE =
TESTCONTAINERS_SPRINGCI_HUB_IMAGE_NAME_PREFIX.concat("%s");
private static final String SPRING_JAVA_VERSION =
@@ -115,8 +115,8 @@ public class VmwHarborProxyImageNameSubstitutor extends ImageNameSubstitutor {
: originalDockerImageName;
}
private String toUnqualifiedDockerImageName(String dockerImageName) {
return dockerImageName.substring(dockerImageName.lastIndexOf("/") + 1);
String toUnqualifiedDockerImageName(String dockerImageName) {
return dockerImageName.replace(TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX, "");
}
@Override

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2017-present 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 example.app.crm.config.testcontainers;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
/**
* Unit Tests for {@link VmwHarborProxyImageNameSubstitutor}.
*
* @author John Blum
* @see org.junit.Test
* @see example.app.crm.config.testcontainers.VmwHarborProxyImageNameSubstitutor
* @since 1.7.6
*/
public class VmwHarborProxyImageNameSubstitutorUnitTests {
@Test
public void toUnqualifiedDockerImageNameFromQualifiedName() {
VmwHarborProxyImageNameSubstitutor imageNameSubstitutor = new VmwHarborProxyImageNameSubstitutor();
String qualifiedDockerImageName = String.format(VmwHarborProxyImageNameSubstitutor
.TESTCONTAINERS_HUB_IMAGE_NAME_TEMPLATE, "testcontainers/ryuk:0.4.0");
assertThat(imageNameSubstitutor.toUnqualifiedDockerImageName(qualifiedDockerImageName))
.isEqualTo("testcontainers/ryuk:0.4.0");
}
@Test
public void toUnqualifiedDockerImageNameFromUnqualifiedName() {
VmwHarborProxyImageNameSubstitutor imageNameSubstitutor = new VmwHarborProxyImageNameSubstitutor();
assertThat(imageNameSubstitutor.toUnqualifiedDockerImageName("testcontainers/ryuk:0.4.0"))
.isEqualTo("testcontainers/ryuk:0.4.0");
}
}