Skip to content

Commit a000563

Browse files
authored
Fix stagingArtifactRegistry support raw us.gcr.io artifact registry (#2243)
1 parent 42d06d2 commit a000563

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

plugins/templates-maven-plugin/src/main/java/com/google/cloud/teleport/plugin/maven/TemplatesStageMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ protected String stageFlexTemplate(
443443
String imagePath =
444444
stageImageBeforePromote
445445
? generateFlexTemplateImagePath(
446-
containerName, null, null, stagingArtifactRegistry, stagePrefix)
446+
containerName, projectId, null, stagingArtifactRegistry, stagePrefix)
447447
: imageSpec.getImage();
448448
String buildProjectId =
449449
stageImageBeforePromote
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (C) 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package com.google.cloud.teleport.plugin.maven;
17+
18+
import static org.junit.Assert.assertEquals;
19+
20+
import com.google.common.base.Strings;
21+
import com.google.common.collect.ImmutableMap;
22+
import org.junit.Test;
23+
import org.junit.runner.RunWith;
24+
import org.junit.runners.JUnit4;
25+
26+
@RunWith(JUnit4.class)
27+
public class TemplatesStageMojoTest {
28+
@Test
29+
public void testGenerateFlexTemplateImagePath() {
30+
String containerName = "name";
31+
String projectId = "some-project";
32+
String stagePrefix = "some-prefix";
33+
ImmutableMap<String, String> testCases =
34+
ImmutableMap.<String, String>builder()
35+
.put("", "gcr.io/some-project/some-prefix/name")
36+
.put("gcr.io", "gcr.io/some-project/some-prefix/name")
37+
.put("eu.gcr.io", "eu.gcr.io/some-project/some-prefix/name")
38+
.put(
39+
"us-docker.pkg.dev/other-project/other-repo",
40+
"us-docker.pkg.dev/other-project/other-repo/some-prefix/name")
41+
.build();
42+
testCases.forEach(
43+
(key, value) -> {
44+
// workaround for null key we intended to test
45+
if (Strings.isNullOrEmpty(key)) {
46+
key = null;
47+
}
48+
assertEquals(
49+
value,
50+
TemplatesStageMojo.generateFlexTemplateImagePath(
51+
containerName, projectId, null, key, stagePrefix));
52+
});
53+
}
54+
55+
@Test
56+
public void testGenerateFlexTemplateImagePathWithDomain() {
57+
String containerName = "name";
58+
String projectId = "google.com:project";
59+
String stagePrefix = "some-prefix";
60+
ImmutableMap<String, String> testCases =
61+
ImmutableMap.<String, String>builder()
62+
.put("", "gcr.io/google.com/project/some-prefix/name")
63+
.put("gcr.io", "gcr.io/google.com/project/some-prefix/name")
64+
.put("eu.gcr.io", "eu.gcr.io/google.com/project/some-prefix/name")
65+
.put(
66+
"us-docker.pkg.dev/other-project/other-repo",
67+
"us-docker.pkg.dev/other-project/other-repo/some-prefix/name")
68+
.build();
69+
testCases.forEach(
70+
(key, value) -> {
71+
// workaround for null key we intended to test
72+
if (Strings.isNullOrEmpty(key)) {
73+
key = null;
74+
}
75+
assertEquals(
76+
value,
77+
TemplatesStageMojo.generateFlexTemplateImagePath(
78+
containerName, projectId, null, key, stagePrefix));
79+
});
80+
}
81+
}

0 commit comments

Comments
 (0)