|
@@ -19,33 +19,74 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
func TestParseRemoteURL(t *testing.T) {
|
|
func TestParseRemoteURL(t *testing.T) {
|
|
- dir, err := parseRemoteURL("git://github.com/user/repo.git")
|
|
|
|
- assert.NilError(t, err)
|
|
|
|
- assert.Check(t, is.DeepEqual(gitRepo{"git://github.com/user/repo.git", "master", ""}, dir, cmpGitRepoOpt))
|
|
|
|
-
|
|
|
|
- dir, err = parseRemoteURL("git://github.com/user/repo.git#mybranch:mydir/mysubdir/")
|
|
|
|
- assert.NilError(t, err)
|
|
|
|
- assert.Check(t, is.DeepEqual(gitRepo{"git://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt))
|
|
|
|
-
|
|
|
|
- dir, err = parseRemoteURL("https://github.com/user/repo.git")
|
|
|
|
- assert.NilError(t, err)
|
|
|
|
- assert.Check(t, is.DeepEqual(gitRepo{"https://github.com/user/repo.git", "master", ""}, dir, cmpGitRepoOpt))
|
|
|
|
-
|
|
|
|
- dir, err = parseRemoteURL("https://github.com/user/repo.git#mybranch:mydir/mysubdir/")
|
|
|
|
- assert.NilError(t, err)
|
|
|
|
- assert.Check(t, is.DeepEqual(gitRepo{"https://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt))
|
|
|
|
-
|
|
|
|
- dir, err = parseRemoteURL("git@github.com:user/repo.git")
|
|
|
|
- assert.NilError(t, err)
|
|
|
|
- assert.Check(t, is.DeepEqual(gitRepo{"git@github.com:user/repo.git", "master", ""}, dir, cmpGitRepoOpt))
|
|
|
|
|
|
+ tests := []struct {
|
|
|
|
+ doc string
|
|
|
|
+ url string
|
|
|
|
+ expected gitRepo
|
|
|
|
+ }{
|
|
|
|
+ {
|
|
|
|
+ doc: "git scheme, no url-fragment",
|
|
|
|
+ url: "git://github.com/user/repo.git",
|
|
|
|
+ expected: gitRepo{
|
|
|
|
+ remote: "git://github.com/user/repo.git",
|
|
|
|
+ ref: "master",
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ doc: "git scheme, with url-fragment",
|
|
|
|
+ url: "git://github.com/user/repo.git#mybranch:mydir/mysubdir/",
|
|
|
|
+ expected: gitRepo{
|
|
|
|
+ remote: "git://github.com/user/repo.git",
|
|
|
|
+ ref: "mybranch",
|
|
|
|
+ subdir: "mydir/mysubdir/",
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ doc: "https scheme, no url-fragment",
|
|
|
|
+ url: "https://github.com/user/repo.git",
|
|
|
|
+ expected: gitRepo{
|
|
|
|
+ remote: "https://github.com/user/repo.git",
|
|
|
|
+ ref: "master",
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ doc: "https scheme, with url-fragment",
|
|
|
|
+ url: "https://github.com/user/repo.git#mybranch:mydir/mysubdir/",
|
|
|
|
+ expected: gitRepo{
|
|
|
|
+ remote: "https://github.com/user/repo.git",
|
|
|
|
+ ref: "mybranch",
|
|
|
|
+ subdir: "mydir/mysubdir/",
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ doc: "git@, no url-fragment",
|
|
|
|
+ url: "git@github.com:user/repo.git",
|
|
|
|
+ expected: gitRepo{
|
|
|
|
+ remote: "git@github.com:user/repo.git",
|
|
|
|
+ ref: "master",
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ doc: "git@, with url-fragment",
|
|
|
|
+ url: "git@github.com:user/repo.git#mybranch:mydir/mysubdir/",
|
|
|
|
+ expected: gitRepo{
|
|
|
|
+ remote: "git@github.com:user/repo.git",
|
|
|
|
+ ref: "mybranch",
|
|
|
|
+ subdir: "mydir/mysubdir/",
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
|
|
- dir, err = parseRemoteURL("git@github.com:user/repo.git#mybranch:mydir/mysubdir/")
|
|
|
|
- assert.NilError(t, err)
|
|
|
|
- assert.Check(t, is.DeepEqual(gitRepo{"git@github.com:user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt))
|
|
|
|
|
|
+ for _, tc := range tests {
|
|
|
|
+ tc := tc
|
|
|
|
+ t.Run(tc.doc, func(t *testing.T) {
|
|
|
|
+ repo, err := parseRemoteURL(tc.url)
|
|
|
|
+ assert.NilError(t, err)
|
|
|
|
+ assert.Check(t, is.DeepEqual(tc.expected, repo, cmp.AllowUnexported(gitRepo{})))
|
|
|
|
+ })
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
-var cmpGitRepoOpt = cmp.AllowUnexported(gitRepo{})
|
|
|
|
-
|
|
|
|
func TestCloneArgsSmartHttp(t *testing.T) {
|
|
func TestCloneArgsSmartHttp(t *testing.T) {
|
|
mux := http.NewServeMux()
|
|
mux := http.NewServeMux()
|
|
server := httptest.NewServer(mux)
|
|
server := httptest.NewServer(mux)
|