@@ -7,17 +7,12 @@ package gps
7
7
import (
8
8
"bytes"
9
9
"fmt"
10
- "io/ioutil"
11
10
"log"
12
- "math/rand"
13
11
"reflect"
14
12
"sort"
15
- "strconv"
16
13
"strings"
17
14
"testing"
18
15
"unicode"
19
-
20
- "github.com/golang/dep/internal/gps/pkgtree"
21
16
)
22
17
23
18
// overrideMkBridge overrides the base bridge with the depspecBridge that skips
@@ -274,150 +269,3 @@ func TestRootLockNoVersionPairMatching(t *testing.T) {
274
269
275
270
fixtureSolveSimpleChecks (fix , res , err , t )
276
271
}
277
-
278
- // TestBadSolveOpts exercises the different possible inputs to a solver that can
279
- // be determined as invalid in Prepare(), without any further work
280
- func TestBadSolveOpts (t * testing.T ) {
281
- pn := strconv .FormatInt (rand .Int63 (), 36 )
282
- fix := basicFixtures ["no dependencies" ]
283
- fix .ds [0 ].n = ProjectRoot (pn )
284
-
285
- sm := newdepspecSM (fix .ds , nil )
286
- params := SolveParameters {
287
- mkBridgeFn : overrideMkBridge ,
288
- }
289
-
290
- _ , err := Prepare (params , nil )
291
- if err == nil {
292
- t .Errorf ("Prepare should have errored on nil SourceManager" )
293
- } else if ! strings .Contains (err .Error (), "non-nil SourceManager" ) {
294
- t .Error ("Prepare should have given error on nil SourceManager, but gave:" , err )
295
- }
296
-
297
- _ , err = Prepare (params , sm )
298
- if err == nil {
299
- t .Errorf ("Prepare should have errored without ProjectAnalyzer" )
300
- } else if ! strings .Contains (err .Error (), "must provide a ProjectAnalyzer" ) {
301
- t .Error ("Prepare should have given error without ProjectAnalyzer, but gave:" , err )
302
- }
303
-
304
- params .ProjectAnalyzer = naiveAnalyzer {}
305
- _ , err = Prepare (params , sm )
306
- if err == nil {
307
- t .Errorf ("Prepare should have errored on empty root" )
308
- } else if ! strings .Contains (err .Error (), "non-empty root directory" ) {
309
- t .Error ("Prepare should have given error on empty root, but gave:" , err )
310
- }
311
-
312
- params .RootDir = pn
313
- _ , err = Prepare (params , sm )
314
- if err == nil {
315
- t .Errorf ("Prepare should have errored on empty name" )
316
- } else if ! strings .Contains (err .Error (), "non-empty import root" ) {
317
- t .Error ("Prepare should have given error on empty import root, but gave:" , err )
318
- }
319
-
320
- params .RootPackageTree = pkgtree.PackageTree {
321
- ImportRoot : pn ,
322
- }
323
- _ , err = Prepare (params , sm )
324
- if err == nil {
325
- t .Errorf ("Prepare should have errored on empty name" )
326
- } else if ! strings .Contains (err .Error (), "at least one package" ) {
327
- t .Error ("Prepare should have given error on empty import root, but gave:" , err )
328
- }
329
-
330
- params .RootPackageTree = pkgtree.PackageTree {
331
- ImportRoot : pn ,
332
- Packages : map [string ]pkgtree.PackageOrErr {
333
- pn : {
334
- P : pkgtree.Package {
335
- ImportPath : pn ,
336
- Name : pn ,
337
- },
338
- },
339
- },
340
- }
341
- params .TraceLogger = log .New (ioutil .Discard , "" , 0 )
342
-
343
- params .Manifest = simpleRootManifest {
344
- ovr : ProjectConstraints {
345
- ProjectRoot ("foo" ): ProjectProperties {},
346
- },
347
- }
348
- _ , err = Prepare (params , sm )
349
- if err == nil {
350
- t .Errorf ("Should have errored on override with empty ProjectProperties" )
351
- } else if ! strings .Contains (err .Error (), "foo, but without any non-zero properties" ) {
352
- t .Error ("Prepare should have given error override with empty ProjectProperties, but gave:" , err )
353
- }
354
-
355
- params .Manifest = simpleRootManifest {
356
- ig : map [string ]bool {"foo" : true },
357
- req : map [string ]bool {"foo" : true },
358
- }
359
- _ , err = Prepare (params , sm )
360
- if err == nil {
361
- t .Errorf ("Should have errored on pkg both ignored and required" )
362
- } else if ! strings .Contains (err .Error (), "was given as both a required and ignored package" ) {
363
- t .Error ("Prepare should have given error with single ignore/require conflict error, but gave:" , err )
364
- }
365
-
366
- params .Manifest = simpleRootManifest {
367
- ig : map [string ]bool {"foo" : true , "bar" : true },
368
- req : map [string ]bool {"foo" : true , "bar" : true },
369
- }
370
- _ , err = Prepare (params , sm )
371
- if err == nil {
372
- t .Errorf ("Should have errored on pkg both ignored and required" )
373
- } else if ! strings .Contains (err .Error (), "multiple packages given as both required and ignored:" ) {
374
- t .Error ("Prepare should have given error with multiple ignore/require conflict error, but gave:" , err )
375
- }
376
- params .Manifest = nil
377
-
378
- params .ToChange = []ProjectRoot {"foo" }
379
- _ , err = Prepare (params , sm )
380
- if err == nil {
381
- t .Errorf ("Should have errored on non-empty ToChange without a lock provided" )
382
- } else if ! strings .Contains (err .Error (), "update specifically requested for" ) {
383
- t .Error ("Prepare should have given error on ToChange without Lock, but gave:" , err )
384
- }
385
-
386
- params .Lock = safeLock {
387
- p : []LockedProject {
388
- NewLockedProject (mkPI ("bar" ), Revision ("makebelieve" ), nil ),
389
- },
390
- }
391
- _ , err = Prepare (params , sm )
392
- if err == nil {
393
- t .Errorf ("Should have errored on ToChange containing project not in lock" )
394
- } else if ! strings .Contains (err .Error (), "cannot update foo as it is not in the lock" ) {
395
- t .Error ("Prepare should have given error on ToChange with item not present in Lock, but gave:" , err )
396
- }
397
-
398
- params .Lock , params .ToChange = nil , nil
399
- _ , err = Prepare (params , sm )
400
- if err != nil {
401
- t .Error ("Basic conditions satisfied, prepare should have completed successfully, err as:" , err )
402
- }
403
-
404
- // swap out the test mkBridge override temporarily, just to make sure we get
405
- // the right error
406
- params .mkBridgeFn = nil
407
-
408
- _ , err = Prepare (params , sm )
409
- if err == nil {
410
- t .Errorf ("Should have errored on nonexistent root" )
411
- } else if ! strings .Contains (err .Error (), "could not read project root" ) {
412
- t .Error ("Prepare should have given error nonexistent project root dir, but gave:" , err )
413
- }
414
-
415
- // Pointing it at a file should also be an err
416
- params .RootDir = "solve_test.go"
417
- _ , err = Prepare (params , sm )
418
- if err == nil {
419
- t .Errorf ("Should have errored on file for RootDir" )
420
- } else if ! strings .Contains (err .Error (), "is a file, not a directory" ) {
421
- t .Error ("Prepare should have given error on file as RootDir, but gave:" , err )
422
- }
423
- }
0 commit comments