Introduce simple git cloner.

This commit is contained in:
jregan
2018-11-22 10:24:35 -08:00
parent c51646e3db
commit d9ba209543
4 changed files with 133 additions and 13 deletions

View File

@@ -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)
}
}
}
}
}