Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from kenfdev/fix-repository-name-with-tag
Fix decision for repositories including ports
- Loading branch information
Showing
3 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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], ":") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
}) | ||
} | ||
|
||
} |