Skip to content

Commit

Permalink
Merge pull request #25 from kenfdev/fix-repository-name-with-tag
Browse files Browse the repository at this point in the history
Fix decision for repositories including ports
  • Loading branch information
garethr committed Jul 5, 2019
2 parents 9b222d5 + e505812 commit 473cb4b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conftest.go
Expand Up @@ -320,7 +320,7 @@ func downloadPolicy(ctx context.Context, policies []Policy) {

for _, policy := range policies {
var ref string
if strings.Contains(policy.Repository, ":") {
if util.RepositoryNameContainsTag(policy.Repository) {
ref = policy.Repository
} else if policy.Tag == "" {
ref = policy.Repository + ":latest"
Expand Down
9 changes: 9 additions & 0 deletions util/repository.go
@@ -0,0 +1,9 @@
package util

import "strings"

// RepositoryNameContainsTag checks if the repository name includes a tag
func RepositoryNameContainsTag(name string) bool {
split := strings.Split(name, "/")
return strings.Contains(split[len(split)-1], ":")
}
42 changes: 42 additions & 0 deletions util/repository_test.go
@@ -0,0 +1,42 @@
package util

import "testing"

func TestRepositoryNameContainsTag(t *testing.T) {
tests := []struct {
note string
name string
expectedResult bool
}{
{
note: "no port, no tag",
name: "instrumenta.azurecr.io/test",
expectedResult: false,
},
{
note: "no port, contains tag",
name: "instrumenta.azurecr.io/test:master",
expectedResult: true,
},
{
note: "contains port, no tag",
name: "localhost:5000/test",
expectedResult: false,
},
{
note: "contains port, contains tag",
name: "localhost:5000/test:master",
expectedResult: true,
},
}

for _, tc := range tests {
t.Run(tc.note, func(t *testing.T) {
result := RepositoryNameContainsTag(tc.name)
if result != tc.expectedResult {
t.Errorf("Expected %v, got %v", tc.expectedResult, result)
}
})
}

}

0 comments on commit 473cb4b

Please sign in to comment.