Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unit test which covers imagename creation with registries on non default ports. #782

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion schema/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ 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 {

colon_count := strings.Count(image, ":")
if colon_count > 0 {

slash_index := strings.Index(image, "/")
colon_index := strings.Index(image, ":")

if slash_index-colon_index > 0 && colon_count == 1 {
imageVal += ":latest"
}

} else {
imageVal += ":latest"
}

Expand Down
18 changes: 18 additions & 0 deletions schema/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,21 @@ func Test_BuildImageName_BranchAndSHAFormat(t *testing.T) {
t.Errorf("BuildImageName want: \"%s\", got: \"%s\"", want, got)
}
}

func Test_BuildImageName_RegistryWithPort(t *testing.T) {
want := "registry.domain:8080/image:latest"
got := BuildImageName(DefaultFormat, "registry.domain:8080/image", "ef384", "master")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is probably a good idea to also include one case with a port and a tag, e.g. registry.domain:8080/image:foo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a new version with that. Thank you for the hint.


if got != want {
t.Errorf("BuildImageName want: \"%s\", got: \"%s\"", want, got)
}
}

func Test_BuildImageName_RegistryWithPortAndTag(t *testing.T) {
want := "registry.domain:8080/image:foo"
got := BuildImageName(DefaultFormat, "registry.domain:8080/image:foo", "ef384", "master")

if got != want {
t.Errorf("BuildImageName want: \"%s\", got: \"%s\"", want, got)
}
}