@@ -10,6 +10,7 @@ import (
10
10
"path/filepath"
11
11
"testing"
12
12
13
+ "github.com/golang/dep"
13
14
"github.com/golang/dep/internal/gps"
14
15
"github.com/golang/dep/internal/test"
15
16
"github.com/pkg/errors"
@@ -69,7 +70,6 @@ func TestGodepConfig_Import(t *testing.T) {
69
70
func TestGodepConfig_JsonLoad (t * testing.T ) {
70
71
// This is same as cmd/dep/testdata/Godeps.json
71
72
wantJSON := godepJSON {
72
- Name : "github.com/golang/notexist" ,
73
73
Imports : []godepPackage {
74
74
{
75
75
ImportPath : "github.com/sdboyer/deptest" ,
@@ -98,10 +98,6 @@ func TestGodepConfig_JsonLoad(t *testing.T) {
98
98
t .Fatalf ("Error while loading... %v" , err )
99
99
}
100
100
101
- if g .json .Name != wantJSON .Name {
102
- t .Fatalf ("Expected project name to be %v, but got %v" , wantJSON .Name , g .json .Name )
103
- }
104
-
105
101
if ! equalImports (g .json .Imports , wantJSON .Imports ) {
106
102
t .Fatalf ("Expected imports to be equal. \n \t (GOT): %v\n \t (WNT): %v" , g .json .Imports , wantJSON .Imports )
107
103
}
@@ -118,7 +114,6 @@ func TestGodepConfig_ConvertProject(t *testing.T) {
118
114
119
115
g := newGodepImporter (discardLogger , true , sm )
120
116
g .json = godepJSON {
121
- Name : "github.com/foo/bar" ,
122
117
Imports : []godepPackage {
123
118
{
124
119
ImportPath : "github.com/sdboyer/deptest" ,
@@ -178,7 +173,6 @@ func TestGodepConfig_ConvertProject_EmptyComment(t *testing.T) {
178
173
179
174
g := newGodepImporter (discardLogger , true , sm )
180
175
g .json = godepJSON {
181
- Name : "github.com/foo/bar" ,
182
176
Imports : []godepPackage {
183
177
{
184
178
ImportPath : "github.com/sdboyer/deptest" ,
@@ -237,6 +231,106 @@ func TestGodepConfig_Convert_BadInput_EmptyPackageName(t *testing.T) {
237
231
}
238
232
}
239
233
234
+ func TestGodepConfig_Convert_BadInput_EmptyRev (t * testing.T ) {
235
+ h := test .NewHelper (t )
236
+ defer h .Cleanup ()
237
+ h .TempDir ("src" )
238
+
239
+ ctx := newTestContext (h )
240
+ sm , err := ctx .SourceManager ()
241
+ h .Must (err )
242
+ defer sm .Release ()
243
+
244
+ g := newGodepImporter (discardLogger , true , sm )
245
+ g .json = godepJSON {
246
+ Imports : []godepPackage {
247
+ {
248
+ ImportPath : "github.com/sdboyer/deptest" ,
249
+ },
250
+ },
251
+ }
252
+
253
+ _ , _ , err = g .convert ("" )
254
+ if err == nil {
255
+ t .Fatal ("Expected conversion to fail because the Rev is empty" )
256
+ }
257
+ }
258
+
259
+ func TestGodepConfig_Convert_SubPackages (t * testing.T ) {
260
+ h := test .NewHelper (t )
261
+ defer h .Cleanup ()
262
+ h .TempDir ("src" )
263
+
264
+ ctx := newTestContext (h )
265
+ sm , err := ctx .SourceManager ()
266
+ h .Must (err )
267
+ defer sm .Release ()
268
+
269
+ g := newGodepImporter (discardLogger , true , sm )
270
+ g .json = godepJSON {
271
+ Imports : []godepPackage {
272
+ {
273
+ ImportPath : "github.com/sdboyer/deptest" ,
274
+ Rev : "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" ,
275
+ },
276
+ {
277
+ ImportPath : "github.com/sdboyer/deptest/foo" ,
278
+ Rev : "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" ,
279
+ },
280
+ },
281
+ }
282
+
283
+ manifest , lock , err := g .convert ("" )
284
+ if err != nil {
285
+ t .Fatal (err )
286
+ }
287
+
288
+ if _ , present := manifest .Constraints ["github.com/sdboyer/deptest" ]; ! present {
289
+ t .Fatal ("Expected the manifest to have a dependency for 'github.com/sdboyer/deptest'" )
290
+ }
291
+
292
+ if _ , present := manifest .Constraints ["github.com/sdboyer/deptest/foo" ]; present {
293
+ t .Fatal ("Expected the manifest to not have a dependency for 'github.com/sdboyer/deptest/foo'" )
294
+ }
295
+
296
+ if len (lock .P ) != 1 {
297
+ t .Fatalf ("Expected lock to have 1 project, got %v" , len (lock .P ))
298
+ }
299
+
300
+ if string (lock .P [0 ].Ident ().ProjectRoot ) != "github.com/sdboyer/deptest" {
301
+ t .Fatal ("Expected lock to have 'github.com/sdboyer/deptest'" )
302
+ }
303
+ }
304
+
305
+ func TestGodepConfig_ProjectExistsInLock (t * testing.T ) {
306
+ lock := & dep.Lock {}
307
+ pi := gps.ProjectIdentifier {ProjectRoot : gps .ProjectRoot ("github.com/sdboyer/deptest" )}
308
+ ver := gps .NewVersion ("v1.0.0" )
309
+ lock .P = append (lock .P , gps .NewLockedProject (pi , ver , nil ))
310
+
311
+ cases := []struct {
312
+ importPath string
313
+ want bool
314
+ }{
315
+ {
316
+ importPath : "github.com/sdboyer/deptest" ,
317
+ want : true ,
318
+ },
319
+ {
320
+ importPath : "github.com/golang/notexist" ,
321
+ want : false ,
322
+ },
323
+ }
324
+
325
+ for _ , c := range cases {
326
+ result := projectExistsInLock (lock , c .importPath )
327
+
328
+ if result != c .want {
329
+ t .Fatalf ("projectExistsInLock result is not as expected: \n \t (GOT) %v \n \t (WNT) %v" , result , c .want )
330
+ }
331
+ }
332
+ }
333
+
240
334
// Compares two slices of godepPackage and checks if they are equal.
241
335
func equalImports (a , b []godepPackage ) bool {
242
336
0 commit comments