0
0
mirror of https://github.com/thegeeklab/wp-docker-buildx.git synced 2024-11-26 05:30:39 +00:00

break out repo split and add unit test

This commit is contained in:
Colin Hoglund 2018-02-10 11:41:07 -05:00
parent 69c4be48ec
commit 21c54aea3d
2 changed files with 24 additions and 1 deletions

View File

@ -55,7 +55,7 @@ func main() {
}
if create {
err = ensureRepoExists(svc, strings.SplitN(repo, "/", 2)[1])
err = ensureRepoExists(svc, getRepoName(repo))
if err != nil {
log.Fatal(fmt.Sprintf("error creating ECR repo: %v", err))
}
@ -75,6 +75,10 @@ func main() {
}
}
func getRepoName(repo string) string {
return strings.SplitN(repo, "/", 2)[1]
}
func ensureRepoExists(svc *ecr.ECR, name string) (err error) {
input := &ecr.CreateRepositoryInput{}
input.SetRepositoryName(name)

View File

@ -0,0 +1,19 @@
package main
import "testing"
func TestGetRepoName(t *testing.T) {
// map full repo path to expected repo name
repos := map[string]string{
"000000000000.dkr.ecr.us-east-1.amazonaws.com/repo": "repo",
"000000000000.dkr.ecr.us-east-1.amazonaws.com/namespace/repo": "namespace/repo",
"000000000000.dkr.ecr.us-east-1.amazonaws.com/namespace/namespace/repo": "namespace/namespace/repo",
}
for repo, name := range repos {
splitName := getRepoName(repo)
if splitName != name {
t.Errorf("%s is not equal to %s.", splitName, name)
}
}
}