build: fix image name when having the case registry:8080/foo/bar

Signed-off-by: Carlos Panato <ctadeu@gmail.com>
This commit is contained in:
Carlos Panato
2021-03-26 13:30:28 +01:00
committed by Alex Ellis
parent 6f0be272d1
commit 1ef557f974
2 changed files with 38 additions and 1 deletions

View File

@@ -65,7 +65,8 @@ func (i *BuildFormat) Set(value string) error {
// BuildImageName builds a Docker image tag for build, push or deploy
func BuildImageName(format BuildFormat, image string, version string, branch string) string {
imageVal := image
if strings.Contains(image, ":") == false {
splitImage := strings.Split(image, "/")
if strings.Contains(splitImage[len(splitImage)-1], ":") == false {
imageVal += ":latest"
}

View File

@@ -11,6 +11,15 @@ func Test_BuildImageName_DefaultFormat(t *testing.T) {
}
}
func Test_BuildImageName_DefaultFormat_WithCustomServerPort(t *testing.T) {
want := "registry:8080/honk/img:latest"
got := BuildImageName(DefaultFormat, "registry:8080/honk/img", "ef384", "master")
if got != want {
t.Errorf("BuildImageName want: \"%s\", got: \"%s\"", want, got)
}
}
func Test_BuildImageName_SHAFormat(t *testing.T) {
want := "img:latest-ef384"
got := BuildImageName(SHAFormat, "img", "ef384", "master")
@@ -20,6 +29,15 @@ func Test_BuildImageName_SHAFormat(t *testing.T) {
}
}
func Test_BuildImageName_SHAFormat_WithCustomServerPort(t *testing.T) {
want := "registry:5000/honk/img:latest-ef384"
got := BuildImageName(SHAFormat, "registry:5000/honk/img", "ef384", "master")
if got != want {
t.Errorf("BuildImageName want: \"%s\", got: \"%s\"", want, got)
}
}
func Test_BuildImageName_SHAFormat_WithNumericVersion(t *testing.T) {
want := "img:0.2-ef384"
got := BuildImageName(SHAFormat, "img:0.2", "ef384", "master")
@@ -29,6 +47,15 @@ func Test_BuildImageName_SHAFormat_WithNumericVersion(t *testing.T) {
}
}
func Test_BuildImageName_SHAFormat_WithNumericVersion_WithCustomServerPort(t *testing.T) {
want := "registry:3000/honk/img:0.2-ef384"
got := BuildImageName(SHAFormat, "registry:3000/honk/img:0.2", "ef384", "master")
if got != want {
t.Errorf("BuildImageName want: \"%s\", got: \"%s\"", want, got)
}
}
func Test_BuildImageName_BranchAndSHAFormat(t *testing.T) {
want := "img:latest-master-ef384"
got := BuildImageName(BranchAndSHAFormat, "img", "ef384", "master")
@@ -37,3 +64,12 @@ func Test_BuildImageName_BranchAndSHAFormat(t *testing.T) {
t.Errorf("BuildImageName want: \"%s\", got: \"%s\"", want, got)
}
}
func Test_BuildImageName_BranchAndSHAFormat_WithCustomServerPort(t *testing.T) {
want := "registry:80/honk/img:latest-master-ef384"
got := BuildImageName(BranchAndSHAFormat, "registry:80/honk/img", "ef384", "master")
if got != want {
t.Errorf("BuildImageName want: \"%s\", got: \"%s\"", want, got)
}
}