Skip to content

Commit

Permalink
Fix formatting of images for a private registry, closes #13
Browse files Browse the repository at this point in the history
  • Loading branch information
moncho committed May 18, 2016
1 parent 256f196 commit fa2531c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
6 changes: 4 additions & 2 deletions docker/image_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func (formatter *ImageFormatter) ID() string {
func (formatter *ImageFormatter) Repository() string {
formatter.addHeader(repository)
if len(formatter.image.RepoTags) > 0 {
return strings.Split(formatter.image.RepoTags[0], ":")[0]
tagPos := strings.LastIndex(formatter.image.RepoTags[0], ":")
return formatter.image.RepoTags[0][:tagPos]
}
return ""
}
Expand All @@ -52,7 +53,8 @@ func (formatter *ImageFormatter) Repository() string {
func (formatter *ImageFormatter) Tag() string {
formatter.addHeader(tag)
if len(formatter.image.RepoTags) > 0 {
return strings.Split(formatter.image.RepoTags[0], ":")[1]
tagPos := strings.LastIndex(formatter.image.RepoTags[0], ":")
return formatter.image.RepoTags[0][tagPos+1:]
}
return ""

Expand Down
40 changes: 40 additions & 0 deletions docker/image_formatter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package docker

import (
"testing"

"github.com/docker/engine-api/types"
)

func TestImageNameFormatting(t *testing.T) {
formatter := ImageFormatter{
trunc: false,
image: types.Image{
RepoTags: []string{"nginx:1.10.0-alpine"},
},
}

repo := formatter.Repository()
tag := formatter.Tag()
if repo != "nginx" {
t.Errorf("Repo value not what expected after formatting: %s", repo)
} else if tag != "1.10.0-alpine" {
t.Errorf("Tag value not what expected after formatting: %s", tag)
}
}
func TestImageNameFormattingPrivateRegistry(t *testing.T) {
formatter := ImageFormatter{
trunc: false,
image: types.Image{
RepoTags: []string{"localhost:5000/nginx:1.10.0-alpine"},
},
}

repo := formatter.Repository()
tag := formatter.Tag()
if repo != "localhost:5000/nginx" {
t.Errorf("Repo value not what expected after formatting: %s", repo)
} else if tag != "1.10.0-alpine" {
t.Errorf("Tag value not what expected after formatting: %s", tag)
}
}

0 comments on commit fa2531c

Please sign in to comment.