From ad77c84237700c1fe47aa1fe3901cb3eac84284e Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Fri, 2 May 2014 10:32:20 -0600 Subject: [PATCH] Handle private registries w/ port Fixes #2 --- docker_client.go | 9 ++++---- docker-gen_test.go => docker_client_test.go | 25 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) rename docker-gen_test.go => docker_client_test.go (72%) diff --git a/docker_client.go b/docker_client.go index 95cec441..29e4ee97 100644 --- a/docker_client.go +++ b/docker_client.go @@ -29,11 +29,10 @@ func splitDockerImage(img string) (string, string, string) { repository = img[index:] } - if strings.Contains(img, ":") { - separator := strings.Index(img, ":") - repository = img[index:separator] - index = separator + 1 - tag = img[index:] + if strings.Contains(repository, ":") { + separator := strings.Index(repository, ":") + tag = repository[separator+1:] + repository = repository[0:separator] } return registry, repository, tag diff --git a/docker-gen_test.go b/docker_client_test.go similarity index 72% rename from docker-gen_test.go rename to docker_client_test.go index 7cace8ff..fad34579 100644 --- a/docker-gen_test.go +++ b/docker_client_test.go @@ -97,3 +97,28 @@ func TestSplitDockerImageWithRepositoryAndTag(t *testing.T) { } } + +func TestSplitDockerImageWithLocalRepositoryAndTag(t *testing.T) { + registry, repository, tag := splitDockerImage("localhost:8888/ubuntu:12.04") + + if registry != "localhost:8888" { + t.Fatalf("registry does not match: expected %s got %s", "localhost:8888", registry) + } + + if repository != "ubuntu" { + t.Fatalf("repository does not match: expected %s got %s", "ubuntu", repository) + } + + if tag != "12.04" { + t.Fatalf("tag does not match: expected %s got %s", "12.04", tag) + } + dockerImage := DockerImage{ + Registry: registry, + Repository: repository, + Tag: tag, + } + if "localhost:8888/ubuntu:12.04" != dockerImage.String() { + t.Fail() + } + +}