break out repo split and add unit test
This commit is contained in:
parent
69c4be48ec
commit
21c54aea3d
@ -55,7 +55,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if create {
|
if create {
|
||||||
err = ensureRepoExists(svc, strings.SplitN(repo, "/", 2)[1])
|
err = ensureRepoExists(svc, getRepoName(repo))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(fmt.Sprintf("error creating ECR repo: %v", err))
|
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) {
|
func ensureRepoExists(svc *ecr.ECR, name string) (err error) {
|
||||||
input := &ecr.CreateRepositoryInput{}
|
input := &ecr.CreateRepositoryInput{}
|
||||||
input.SetRepositoryName(name)
|
input.SetRepositoryName(name)
|
||||||
|
19
cmd/drone-docker-ecr/main_test.go
Normal file
19
cmd/drone-docker-ecr/main_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user