@@ -7,27 +7,43 @@ import (
7
7
)
8
8
9
9
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
+ }
33
49
}
0 commit comments