Skip to content

Commit c8e589f

Browse files
committed
source: use subtests cases for git identifier
Signed-off-by: CrazyMax <[email protected]>
1 parent bc24cae commit c8e589f

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

source/gitidentifier_test.go

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,43 @@ import (
77
)
88

99
func TestNewGitIdentifier(t *testing.T) {
10-
gi, err := NewGitIdentifier("ssh://[email protected]:2222/root/my/really/weird/path/foo.git")
11-
require.Nil(t, err)
12-
require.Equal(t, "ssh://[email protected]:2222/root/my/really/weird/path/foo.git", gi.Remote)
13-
require.Equal(t, "", gi.Ref)
14-
require.Equal(t, "", gi.Subdir)
15-
16-
gi, err = NewGitIdentifier("ssh://[email protected]:2222/root/my/really/weird/path/foo.git#main")
17-
require.Nil(t, err)
18-
require.Equal(t, "ssh://[email protected]:2222/root/my/really/weird/path/foo.git", gi.Remote)
19-
require.Equal(t, "main", gi.Ref)
20-
require.Equal(t, "", gi.Subdir)
21-
22-
gi, err = NewGitIdentifier("[email protected]:moby/buildkit.git")
23-
require.Nil(t, err)
24-
require.Equal(t, "[email protected]:moby/buildkit.git", gi.Remote)
25-
require.Equal(t, "", gi.Ref)
26-
require.Equal(t, "", gi.Subdir)
27-
28-
gi, err = NewGitIdentifier("github.com/moby/buildkit.git#main")
29-
require.Nil(t, err)
30-
require.Equal(t, "https://github.com/moby/buildkit.git", gi.Remote)
31-
require.Equal(t, "main", gi.Ref)
32-
require.Equal(t, "", gi.Subdir)
10+
tests := []struct {
11+
url string
12+
expected GitIdentifier
13+
}{
14+
{
15+
url: "ssh://[email protected]:2222/root/my/really/weird/path/foo.git",
16+
expected: GitIdentifier{
17+
Remote: "ssh://[email protected]:2222/root/my/really/weird/path/foo.git",
18+
},
19+
},
20+
{
21+
url: "ssh://[email protected]:2222/root/my/really/weird/path/foo.git#main",
22+
expected: GitIdentifier{
23+
Remote: "ssh://[email protected]:2222/root/my/really/weird/path/foo.git",
24+
Ref: "main",
25+
},
26+
},
27+
{
28+
url: "[email protected]:moby/buildkit.git",
29+
expected: GitIdentifier{
30+
Remote: "[email protected]:moby/buildkit.git",
31+
},
32+
},
33+
{
34+
url: "github.com/moby/buildkit.git#main",
35+
expected: GitIdentifier{
36+
Remote: "https://github.com/moby/buildkit.git",
37+
Ref: "main",
38+
},
39+
},
40+
}
41+
for _, tt := range tests {
42+
tt := tt
43+
t.Run(tt.url, func(t *testing.T) {
44+
gi, err := NewGitIdentifier(tt.url)
45+
require.NoError(t, err)
46+
require.Equal(t, tt.expected, *gi)
47+
})
48+
}
3349
}

0 commit comments

Comments
 (0)