mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-30 18:01:21 +00:00
Introduce simple git cloner.
This commit is contained in:
@@ -17,6 +17,8 @@ limitations under the License.
|
||||
package loader
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -38,6 +40,14 @@ func TestIsRepoURL(t *testing.T) {
|
||||
input: "github.com/org/repo",
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
input: "git@github.com:org/repo",
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
input: "gh:org/repo",
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
input: "git::https://gitlab.com/org/repo",
|
||||
expected: true,
|
||||
@@ -168,3 +178,52 @@ whatever
|
||||
coRoot+"/"+pathInRepo, l2.Root())
|
||||
}
|
||||
}
|
||||
|
||||
var repoNames = []string{"someOrg/someRepo", "kubernetes/website"}
|
||||
|
||||
var paths = []string{"", "README.md", "foo/index.md"}
|
||||
|
||||
var extractFmts = []string{
|
||||
"gh:%s",
|
||||
"GH:%s",
|
||||
"gitHub.com/%s",
|
||||
"https://github.com/%s",
|
||||
"hTTps://github.com/%s",
|
||||
"git::https://gitlab.com/%s",
|
||||
"git@gitHUB.com:%s.git",
|
||||
"github.com:%s",
|
||||
}
|
||||
|
||||
func TestExtractGithubRepoName(t *testing.T) {
|
||||
for _, repoName := range repoNames {
|
||||
for _, pathName := range paths {
|
||||
for _, extractFmt := range extractFmts {
|
||||
spec := repoName
|
||||
if len(pathName) > 0 {
|
||||
spec = filepath.Join(spec, pathName)
|
||||
}
|
||||
input := fmt.Sprintf(extractFmt, spec)
|
||||
if !isRepoUrl(input) {
|
||||
t.Errorf("Should smell like github arg: %s\n", input)
|
||||
continue
|
||||
}
|
||||
repo, path, err := extractGithubRepoName(input)
|
||||
if err != nil {
|
||||
t.Errorf("problem %v", err)
|
||||
}
|
||||
if repo != repoName {
|
||||
t.Errorf("\n"+
|
||||
" from %s\n"+
|
||||
" gotRepo %s\n"+
|
||||
"desiredRepo %s\n", input, repo, repoName)
|
||||
}
|
||||
if path != pathName {
|
||||
t.Errorf("\n"+
|
||||
" from %s\n"+
|
||||
" gotPath %s\n"+
|
||||
"desiredPath %s\n", input, path, pathName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user