Browse code

TestParseRemoteURL: use subtests

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2019/11/05 10:36:49
Showing 1 changed files
... ...
@@ -19,33 +19,74 @@ import (
19 19
 )
20 20
 
21 21
 func TestParseRemoteURL(t *testing.T) {
22
-	dir, err := parseRemoteURL("git://github.com/user/repo.git")
23
-	assert.NilError(t, err)
24
-	assert.Check(t, is.DeepEqual(gitRepo{"git://github.com/user/repo.git", "master", ""}, dir, cmpGitRepoOpt))
25
-
26
-	dir, err = parseRemoteURL("git://github.com/user/repo.git#mybranch:mydir/mysubdir/")
27
-	assert.NilError(t, err)
28
-	assert.Check(t, is.DeepEqual(gitRepo{"git://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt))
29
-
30
-	dir, err = parseRemoteURL("https://github.com/user/repo.git")
31
-	assert.NilError(t, err)
32
-	assert.Check(t, is.DeepEqual(gitRepo{"https://github.com/user/repo.git", "master", ""}, dir, cmpGitRepoOpt))
33
-
34
-	dir, err = parseRemoteURL("https://github.com/user/repo.git#mybranch:mydir/mysubdir/")
35
-	assert.NilError(t, err)
36
-	assert.Check(t, is.DeepEqual(gitRepo{"https://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt))
37
-
38
-	dir, err = parseRemoteURL("git@github.com:user/repo.git")
39
-	assert.NilError(t, err)
40
-	assert.Check(t, is.DeepEqual(gitRepo{"git@github.com:user/repo.git", "master", ""}, dir, cmpGitRepoOpt))
22
+	tests := []struct {
23
+		doc      string
24
+		url      string
25
+		expected gitRepo
26
+	}{
27
+		{
28
+			doc: "git scheme, no url-fragment",
29
+			url: "git://github.com/user/repo.git",
30
+			expected: gitRepo{
31
+				remote: "git://github.com/user/repo.git",
32
+				ref:    "master",
33
+			},
34
+		},
35
+		{
36
+			doc: "git scheme, with url-fragment",
37
+			url: "git://github.com/user/repo.git#mybranch:mydir/mysubdir/",
38
+			expected: gitRepo{
39
+				remote: "git://github.com/user/repo.git",
40
+				ref:    "mybranch",
41
+				subdir: "mydir/mysubdir/",
42
+			},
43
+		},
44
+		{
45
+			doc: "https scheme, no url-fragment",
46
+			url: "https://github.com/user/repo.git",
47
+			expected: gitRepo{
48
+				remote: "https://github.com/user/repo.git",
49
+				ref:    "master",
50
+			},
51
+		},
52
+		{
53
+			doc: "https scheme, with url-fragment",
54
+			url: "https://github.com/user/repo.git#mybranch:mydir/mysubdir/",
55
+			expected: gitRepo{
56
+				remote: "https://github.com/user/repo.git",
57
+				ref:    "mybranch",
58
+				subdir: "mydir/mysubdir/",
59
+			},
60
+		},
61
+		{
62
+			doc: "git@, no url-fragment",
63
+			url: "git@github.com:user/repo.git",
64
+			expected: gitRepo{
65
+				remote: "git@github.com:user/repo.git",
66
+				ref:    "master",
67
+			},
68
+		},
69
+		{
70
+			doc: "git@, with url-fragment",
71
+			url: "git@github.com:user/repo.git#mybranch:mydir/mysubdir/",
72
+			expected: gitRepo{
73
+				remote: "git@github.com:user/repo.git",
74
+				ref:    "mybranch",
75
+				subdir: "mydir/mysubdir/",
76
+			},
77
+		},
78
+	}
41 79
 
42
-	dir, err = parseRemoteURL("git@github.com:user/repo.git#mybranch:mydir/mysubdir/")
43
-	assert.NilError(t, err)
44
-	assert.Check(t, is.DeepEqual(gitRepo{"git@github.com:user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt))
80
+	for _, tc := range tests {
81
+		tc := tc
82
+		t.Run(tc.doc, func(t *testing.T) {
83
+			repo, err := parseRemoteURL(tc.url)
84
+			assert.NilError(t, err)
85
+			assert.Check(t, is.DeepEqual(tc.expected, repo, cmp.AllowUnexported(gitRepo{})))
86
+		})
87
+	}
45 88
 }
46 89
 
47
-var cmpGitRepoOpt = cmp.AllowUnexported(gitRepo{})
48
-
49 90
 func TestCloneArgsSmartHttp(t *testing.T) {
50 91
 	mux := http.NewServeMux()
51 92
 	server := httptest.NewServer(mux)