@@ -6,72 +6,127 @@ import (
6
6
)
7
7
8
8
func TestParseGitRef (t * testing.T ) {
9
- cases := map [string ]* GitRef {
10
- "https://example.com/" : nil ,
11
- "https://example.com/foo" : nil ,
12
- "https://example.com/foo.git" : {
13
- Remote : "https://example.com/foo.git" ,
14
- ShortName : "foo" ,
15
- },
16
- "https://example.com/foo.git#deadbeef" : {
17
- Remote : "https://example.com/foo.git" ,
18
- ShortName : "foo" ,
19
- Commit : "deadbeef" ,
20
- },
21
- "https://example.com/foo.git#release/1.2" : {
22
- Remote : "https://example.com/foo.git" ,
23
- ShortName : "foo" ,
24
- Commit : "release/1.2" ,
25
- },
26
- "https://example.com/foo.git/" : nil ,
27
- "https://example.com/foo.git.bar" : nil ,
28
- "git://example.com/foo" : {
29
- Remote : "git://example.com/foo" ,
30
- ShortName : "foo" ,
31
- UnencryptedTCP : true ,
32
- },
33
- "github.com/moby/buildkit" : {
34
- Remote : "github.com/moby/buildkit" , ShortName : "buildkit" ,
35
- IndistinguishableFromLocal : true ,
36
- },
37
- "https://github.com/moby/buildkit" : nil ,
38
- "https://github.com/moby/buildkit.git" : {
39
- Remote : "https://github.com/moby/buildkit.git" ,
40
- ShortName : "buildkit" ,
41
- },
42
- "[email protected] :moby/buildkit" : {
43
- Remote :
"[email protected] :moby/buildkit" ,
44
- ShortName : "buildkit" ,
45
- },
46
- "[email protected] :moby/buildkit.git" : {
47
- Remote :
"[email protected] :moby/buildkit.git" ,
48
- ShortName : "buildkit" ,
49
- },
50
- "[email protected] :atlassianlabs/atlassian-docker.git" : {
51
- Remote :
"[email protected] :atlassianlabs/atlassian-docker.git" ,
52
- ShortName : "atlassian-docker" ,
53
- },
54
- "https://github.com/foo/bar.git#baz/qux:quux/quuz" : {
55
- Remote : "https://github.com/foo/bar.git" ,
56
- ShortName : "bar" ,
57
- Commit : "baz/qux" ,
58
- SubDir : "quux/quuz" ,
59
- },
60
- "http://github.com/docker/docker.git:#branch" : nil ,
9
+ cases := []struct {
10
+ ref string
11
+ expected * GitRef
12
+ }{
13
+ {
14
+ ref : "https://example.com/" ,
15
+ expected : nil ,
16
+ },
17
+ {
18
+ ref : "https://example.com/foo" ,
19
+ expected : nil ,
20
+ },
21
+ {
22
+ ref : "https://example.com/foo.git" ,
23
+ expected : & GitRef {
24
+ Remote : "https://example.com/foo.git" ,
25
+ ShortName : "foo" ,
26
+ },
27
+ },
28
+ {
29
+ ref : "https://example.com/foo.git#deadbeef" ,
30
+ expected : & GitRef {
31
+ Remote : "https://example.com/foo.git" ,
32
+ ShortName : "foo" ,
33
+ Commit : "deadbeef" ,
34
+ },
35
+ },
36
+ {
37
+ ref : "https://example.com/foo.git#release/1.2" ,
38
+ expected : & GitRef {
39
+ Remote : "https://example.com/foo.git" ,
40
+ ShortName : "foo" ,
41
+ Commit : "release/1.2" ,
42
+ },
43
+ },
44
+ {
45
+ ref : "https://example.com/foo.git/" ,
46
+ expected : nil ,
47
+ },
48
+ {
49
+ ref : "https://example.com/foo.git.bar" ,
50
+ expected : nil ,
51
+ },
52
+ {
53
+ ref : "git://example.com/foo" ,
54
+ expected : & GitRef {
55
+ Remote : "git://example.com/foo" ,
56
+ ShortName : "foo" ,
57
+ UnencryptedTCP : true ,
58
+ },
59
+ },
60
+ {
61
+ ref : "github.com/moby/buildkit" ,
62
+ expected : & GitRef {
63
+ Remote : "github.com/moby/buildkit" ,
64
+ ShortName : "buildkit" ,
65
+ IndistinguishableFromLocal : true ,
66
+ },
67
+ },
68
+ {
69
+ ref : "https://github.com/moby/buildkit" ,
70
+ expected : nil ,
71
+ },
72
+ {
73
+ ref : "https://github.com/moby/buildkit.git" ,
74
+ expected : & GitRef {
75
+ Remote : "https://github.com/moby/buildkit.git" ,
76
+ ShortName : "buildkit" ,
77
+ },
78
+ },
79
+ {
80
+ ref :
"[email protected] :moby/buildkit" ,
81
+ expected : & GitRef {
82
+ Remote :
"[email protected] :moby/buildkit" ,
83
+ ShortName : "buildkit" ,
84
+ },
85
+ },
86
+ {
87
+ ref :
"[email protected] :moby/buildkit.git" ,
88
+ expected : & GitRef {
89
+ Remote :
"[email protected] :moby/buildkit.git" ,
90
+ ShortName : "buildkit" ,
91
+ },
92
+ },
93
+ {
94
+ ref :
"[email protected] :atlassianlabs/atlassian-docker.git" ,
95
+ expected : & GitRef {
96
+ Remote :
"[email protected] :atlassianlabs/atlassian-docker.git" ,
97
+ ShortName : "atlassian-docker" ,
98
+ },
99
+ },
100
+ {
101
+ ref : "https://github.com/foo/bar.git#baz/qux:quux/quuz" ,
102
+ expected : & GitRef {
103
+ Remote : "https://github.com/foo/bar.git" ,
104
+ ShortName : "bar" ,
105
+ Commit : "baz/qux" ,
106
+ SubDir : "quux/quuz" ,
107
+ },
108
+ },
109
+ {
110
+ ref : "http://github.com/docker/docker.git:#branch" ,
111
+ expected : nil ,
112
+ },
61
113
}
62
- for ref , expected := range cases {
63
- got , err := ParseGitRef (ref )
64
- if expected == nil {
65
- if err == nil {
66
- t .Errorf ("expected an error for ParseGitRef(%q)" , ref )
67
- }
68
- } else {
69
- if err != nil {
70
- t .Errorf ("got an unexpected error: ParseGitRef(%q): %v" , ref , err )
71
- }
72
- if ! reflect .DeepEqual (got , expected ) {
73
- t .Errorf ("expected ParseGitRef(%q) to return %#v, got %#v" , ref , expected , got )
114
+ for _ , tt := range cases {
115
+ tt := tt
116
+ t .Run (tt .ref , func (t * testing.T ) {
117
+ got , err := ParseGitRef (tt .ref )
118
+ if tt .expected == nil {
119
+ if err == nil {
120
+ t .Errorf ("expected an error for ParseGitRef(%q)" , tt .ref )
121
+ }
122
+ } else {
123
+ if err != nil {
124
+ t .Errorf ("got an unexpected error: ParseGitRef(%q): %v" , tt .ref , err )
125
+ }
126
+ if ! reflect .DeepEqual (got , tt .expected ) {
127
+ t .Errorf ("expected ParseGitRef(%q) to return %#v, got %#v" , tt .ref , tt .expected , got )
128
+ }
74
129
}
75
- }
130
+ })
76
131
}
77
132
}
0 commit comments