Skip to content

Commit

Permalink
Merge pull request #73 from ivanilves/the-split
Browse files Browse the repository at this point in the history
Refactor GeneratePathFromHostname
  • Loading branch information
ivanilves authored Oct 10, 2017
2 parents 8d6d14b + f158b1e commit 6eb70da
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
10 changes: 5 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"strings"
)

// GenerateRegistryPrefix generates destination Docker registry prefix path from the source registry name
func GenerateRegistryPrefix(registry string) string {
allParts := strings.Split(registry, ":")
hostname := allParts[0]
// GeneratePathFromHostname generates "/"-delimited path from a hostname[:port]
func GeneratePathFromHostname(hostname string) string {
allParts := strings.Split(hostname, ":")
hostPart := allParts[0]

return "/" + strings.Replace(hostname, ".", "/", -1)
return "/" + strings.Replace(hostPart, ".", "/", -1)
}
27 changes: 27 additions & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package app

import (
"testing"
)

func TestGeneratePathFromHostname(t *testing.T) {
examples := map[string]string{
"localhost": "/localhost",
"localhost:5000": "/localhost",
"registry.company.com": "/registry/company/com",
"dockerz.hipster.io:8443": "/dockerz/hipster/io",
}

for input, expected := range examples {
output := GeneratePathFromHostname(input)

if output != expected {
t.Fatalf(
"Unexpected path '%s' generated from hostname '%s' (expected: '%s')",
output,
input,
expected,
)
}
}
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func main() {
for _, tg := range tags {
prefix := o.PushPrefix
if prefix == "" {
prefix = app.GenerateRegistryPrefix(registry)
prefix = app.GeneratePathFromHostname(registry)
}

srcRef := repo + ":" + tg.GetName()
Expand Down

0 comments on commit 6eb70da

Please sign in to comment.