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