Skip to content

Commit

Permalink
Fix stagingArtifactRegistry support raw us.gcr.io artifact registry (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Abacn authored Mar 10, 2025
1 parent 42d06d2 commit a000563
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ protected String stageFlexTemplate(
String imagePath =
stageImageBeforePromote
? generateFlexTemplateImagePath(
containerName, null, null, stagingArtifactRegistry, stagePrefix)
containerName, projectId, null, stagingArtifactRegistry, stagePrefix)
: imageSpec.getImage();
String buildProjectId =
stageImageBeforePromote
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2025 Google LLC
*
* 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
*
* http://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 com.google.cloud.teleport.plugin.maven;

import static org.junit.Assert.assertEquals;

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class TemplatesStageMojoTest {
@Test
public void testGenerateFlexTemplateImagePath() {
String containerName = "name";
String projectId = "some-project";
String stagePrefix = "some-prefix";
ImmutableMap<String, String> testCases =
ImmutableMap.<String, String>builder()
.put("", "gcr.io/some-project/some-prefix/name")
.put("gcr.io", "gcr.io/some-project/some-prefix/name")
.put("eu.gcr.io", "eu.gcr.io/some-project/some-prefix/name")
.put(
"us-docker.pkg.dev/other-project/other-repo",
"us-docker.pkg.dev/other-project/other-repo/some-prefix/name")
.build();
testCases.forEach(
(key, value) -> {
// workaround for null key we intended to test
if (Strings.isNullOrEmpty(key)) {
key = null;
}
assertEquals(
value,
TemplatesStageMojo.generateFlexTemplateImagePath(
containerName, projectId, null, key, stagePrefix));
});
}

@Test
public void testGenerateFlexTemplateImagePathWithDomain() {
String containerName = "name";
String projectId = "google.com:project";
String stagePrefix = "some-prefix";
ImmutableMap<String, String> testCases =
ImmutableMap.<String, String>builder()
.put("", "gcr.io/google.com/project/some-prefix/name")
.put("gcr.io", "gcr.io/google.com/project/some-prefix/name")
.put("eu.gcr.io", "eu.gcr.io/google.com/project/some-prefix/name")
.put(
"us-docker.pkg.dev/other-project/other-repo",
"us-docker.pkg.dev/other-project/other-repo/some-prefix/name")
.build();
testCases.forEach(
(key, value) -> {
// workaround for null key we intended to test
if (Strings.isNullOrEmpty(key)) {
key = null;
}
assertEquals(
value,
TemplatesStageMojo.generateFlexTemplateImagePath(
containerName, projectId, null, key, stagePrefix));
});
}
}

0 comments on commit a000563

Please sign in to comment.