mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
TestParseRemoteURL: use subtests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
c36460c437
commit
5a74a736a8
1 changed files with 65 additions and 24 deletions
|
@ -19,33 +19,74 @@ import (
|
|||
)
|
||||
|
||||
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))
|
||||
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))
|
||||
|
||||
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))
|
||||
|
||||
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) {
|
||||
mux := http.NewServeMux()
|
||||
server := httptest.NewServer(mux)
|
||||
|
|
Loading…
Add table
Reference in a new issue