From 441d3a4bcff4ac025f78f8fec9148d2915d24262 Mon Sep 17 00:00:00 2001 From: John Blum Date: Sat, 13 May 2023 12:35:11 -0700 Subject: [PATCH] Fix bug in VmwHarborProxyImageNameSubstitutor when resolving non-Spring Docker Images in VMware Harbor Proxy. --- .../VmwHarborProxyImageNameSubstitutor.java | 8 +-- ...borProxyImageNameSubstitutorUnitTests.java | 52 +++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 spring-geode-project/spring-geode/src/test/java/example/app/crm/config/testcontainers/VmwHarborProxyImageNameSubstitutorUnitTests.java diff --git a/spring-geode-project/spring-geode/src/test/java/example/app/crm/config/testcontainers/VmwHarborProxyImageNameSubstitutor.java b/spring-geode-project/spring-geode/src/test/java/example/app/crm/config/testcontainers/VmwHarborProxyImageNameSubstitutor.java index 91d389b9..7fda636c 100644 --- a/spring-geode-project/spring-geode/src/test/java/example/app/crm/config/testcontainers/VmwHarborProxyImageNameSubstitutor.java +++ b/spring-geode-project/spring-geode/src/test/java/example/app/crm/config/testcontainers/VmwHarborProxyImageNameSubstitutor.java @@ -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 diff --git a/spring-geode-project/spring-geode/src/test/java/example/app/crm/config/testcontainers/VmwHarborProxyImageNameSubstitutorUnitTests.java b/spring-geode-project/spring-geode/src/test/java/example/app/crm/config/testcontainers/VmwHarborProxyImageNameSubstitutorUnitTests.java new file mode 100644 index 00000000..3af539fb --- /dev/null +++ b/spring-geode-project/spring-geode/src/test/java/example/app/crm/config/testcontainers/VmwHarborProxyImageNameSubstitutorUnitTests.java @@ -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"); + } +}