@@ -34,18 +34,9 @@ func newTestContext(h *test.Helper) *dep.Ctx {
34
34
35
35
func TestGlideConfig_Convert (t * testing.T ) {
36
36
testCases := map [string ]struct {
37
- yaml glideYaml
38
- lock * glideLock
39
- wantConvertErr bool
40
- matchPairedVersion bool
41
- projectRoot gps.ProjectRoot
42
- wantSourceRepo string
43
- wantConstraint string
44
- wantRevision gps.Revision
45
- wantVersion string
46
- wantLockCount int
47
- wantIgnoreCount int
48
- wantIgnoredPackages []string
37
+ * convertTestCase
38
+ yaml glideYaml
39
+ lock * glideLock
49
40
}{
50
41
"project" : {
51
42
yaml : glideYaml {
@@ -66,13 +57,14 @@ func TestGlideConfig_Convert(t *testing.T) {
66
57
},
67
58
},
68
59
},
69
- projectRoot : "github.com/sdboyer/deptest" ,
70
- wantSourceRepo : "https://github.com/sdboyer/deptest.git" ,
71
- matchPairedVersion : true ,
72
- wantConstraint : "^1.0.0" ,
73
- wantLockCount : 1 ,
74
- wantRevision : gps .Revision ("ff2948a2ac8f538c4ecd55962e919d1e13e74baf" ),
75
- wantVersion : "v1.0.0" ,
60
+ convertTestCase : & convertTestCase {
61
+ projectRoot : "github.com/sdboyer/deptest" ,
62
+ wantSourceRepo : "https://github.com/sdboyer/deptest.git" ,
63
+ wantConstraint : "^1.0.0" ,
64
+ wantLockCount : 1 ,
65
+ wantRevision : gps .Revision ("ff2948a2ac8f538c4ecd55962e919d1e13e74baf" ),
66
+ wantVersion : "v1.0.0" ,
67
+ },
76
68
},
77
69
"test project" : {
78
70
yaml : glideYaml {
@@ -91,42 +83,74 @@ func TestGlideConfig_Convert(t *testing.T) {
91
83
},
92
84
},
93
85
},
94
- projectRoot : "github.com/sdboyer/deptest" ,
95
- wantLockCount : 1 ,
96
- wantConstraint : "^1.0.0" ,
97
- wantVersion : "v1.0.0" ,
86
+ convertTestCase : & convertTestCase {
87
+ projectRoot : "github.com/sdboyer/deptest" ,
88
+ wantLockCount : 1 ,
89
+ wantConstraint : "^1.0.0" ,
90
+ wantVersion : "v1.0.0" ,
91
+ },
92
+ },
93
+ "revision only" : {
94
+ yaml : glideYaml {
95
+ Imports : []glidePackage {
96
+ {
97
+ Name : "github.com/sdboyer/deptest" ,
98
+ },
99
+ },
100
+ },
101
+ lock : & glideLock {
102
+ Imports : []glideLockedPackage {
103
+ {
104
+ Name : "github.com/sdboyer/deptest" ,
105
+ Reference : "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" ,
106
+ },
107
+ },
108
+ },
109
+ convertTestCase : & convertTestCase {
110
+ projectRoot : "github.com/sdboyer/deptest" ,
111
+ wantLockCount : 1 ,
112
+ wantRevision : gps .Revision ("ff2948a2ac8f538c4ecd55962e919d1e13e74baf" ),
113
+ },
98
114
},
99
115
"with ignored package" : {
100
116
yaml : glideYaml {
101
117
Ignores : []string {"github.com/sdboyer/deptest" },
102
118
},
103
- projectRoot : "github.com/sdboyer/deptest" ,
104
- wantIgnoreCount : 1 ,
105
- wantIgnoredPackages : []string {"github.com/sdboyer/deptest" },
119
+ convertTestCase : & convertTestCase {
120
+ projectRoot : "github.com/sdboyer/deptest" ,
121
+ wantIgnoreCount : 1 ,
122
+ wantIgnoredPackages : []string {"github.com/sdboyer/deptest" },
123
+ },
106
124
},
107
125
"with exclude dir" : {
108
126
yaml : glideYaml {
109
127
ExcludeDirs : []string {"samples" },
110
128
},
111
- projectRoot : testProjectRoot ,
112
- wantIgnoreCount : 1 ,
113
- wantIgnoredPackages : []string {"github.com/golang/notexist/samples" },
129
+ convertTestCase : & convertTestCase {
130
+ projectRoot : testProjectRoot ,
131
+ wantIgnoreCount : 1 ,
132
+ wantIgnoredPackages : []string {"github.com/golang/notexist/samples" },
133
+ },
114
134
},
115
135
"exclude dir ignores mismatched package name" : {
116
136
yaml : glideYaml {
117
137
Name : "github.com/golang/mismatched-package-name" ,
118
138
ExcludeDirs : []string {"samples" },
119
139
},
120
- projectRoot : testProjectRoot ,
121
- wantIgnoreCount : 1 ,
122
- wantIgnoredPackages : []string {"github.com/golang/notexist/samples" },
140
+ convertTestCase : & convertTestCase {
141
+ projectRoot : testProjectRoot ,
142
+ wantIgnoreCount : 1 ,
143
+ wantIgnoredPackages : []string {"github.com/golang/notexist/samples" },
144
+ },
123
145
},
124
146
"bad input, empty package name" : {
125
147
yaml : glideYaml {
126
148
Imports : []glidePackage {{Name : "" }},
127
149
},
128
- projectRoot : testProjectRoot ,
129
- wantConvertErr : true ,
150
+ convertTestCase : & convertTestCase {
151
+ projectRoot : testProjectRoot ,
152
+ wantConvertErr : true ,
153
+ },
130
154
},
131
155
}
132
156
@@ -147,86 +171,10 @@ func TestGlideConfig_Convert(t *testing.T) {
147
171
g .lock = testCase .lock
148
172
}
149
173
150
- manifest , lock , err := g .convert (testCase .projectRoot )
174
+ manifest , lock , convertErr := g .convert (testCase .projectRoot )
175
+ err := validateConvertTestCase (testCase .convertTestCase , manifest , lock , convertErr )
151
176
if err != nil {
152
- if testCase .wantConvertErr {
153
- return
154
- }
155
-
156
- t .Fatal (err )
157
- }
158
-
159
- // Lock checks.
160
- if lock != nil && len (lock .P ) != testCase .wantLockCount {
161
- t .Fatalf ("Expected lock to have %d project(s), got %d" ,
162
- testCase .wantLockCount ,
163
- len (lock .P ))
164
- }
165
-
166
- // Ignored projects checks.
167
- if len (manifest .Ignored ) != testCase .wantIgnoreCount {
168
- t .Fatalf ("Expected manifest to have %d ignored project(s), got %d" ,
169
- testCase .wantIgnoreCount ,
170
- len (manifest .Ignored ))
171
- }
172
-
173
- if ! equalSlice (manifest .Ignored , testCase .wantIgnoredPackages ) {
174
- t .Fatalf ("Expected manifest to have ignore %s, got %s" ,
175
- strings .Join (testCase .wantIgnoredPackages , ", " ),
176
- strings .Join (manifest .Ignored , ", " ))
177
- }
178
-
179
- // Constraints checks below. Skip if there is no want constraint.
180
- if testCase .wantConstraint == "" {
181
- return
182
- }
183
-
184
- d , ok := manifest .Constraints [testCase .projectRoot ]
185
- if ! ok {
186
- t .Fatalf ("Expected the manifest to have a dependency for '%s' but got none" ,
187
- testCase .projectRoot )
188
- }
189
-
190
- v := d .Constraint .String ()
191
- if v != testCase .wantConstraint {
192
- t .Fatalf ("Expected manifest constraint to be %s, got %s" , testCase .wantConstraint , v )
193
- }
194
-
195
- p := lock .P [0 ]
196
-
197
- if p .Ident ().ProjectRoot != testCase .projectRoot {
198
- t .Fatalf ("Expected the lock to have a project for '%s' but got '%s'" ,
199
- testCase .projectRoot ,
200
- p .Ident ().ProjectRoot )
201
- }
202
-
203
- if p .Ident ().Source != testCase .wantSourceRepo {
204
- t .Fatalf ("Expected locked source to be %s, got '%s'" , testCase .wantSourceRepo , p .Ident ().Source )
205
- }
206
-
207
- lv := p .Version ()
208
- lpv , ok := lv .(gps.PairedVersion )
209
-
210
- if ! ok {
211
- if testCase .matchPairedVersion {
212
- t .Fatalf ("Expected locked version to be PairedVersion but got %T" , lv )
213
- }
214
-
215
- return
216
- }
217
-
218
- ver := lpv .String ()
219
- if ver != testCase .wantVersion {
220
- t .Fatalf ("Expected locked version to be '%s', got %s" , testCase .wantVersion , ver )
221
- }
222
-
223
- if testCase .wantRevision != "" {
224
- rev := lpv .Revision ()
225
- if rev != testCase .wantRevision {
226
- t .Fatalf ("Expected locked revision to be '%s', got %s" ,
227
- testCase .wantRevision ,
228
- rev )
229
- }
177
+ t .Fatalf ("%+v" , err )
230
178
}
231
179
})
232
180
}
0 commit comments