Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 1f42a17

Browse files
committed
gps: move TestBadSolveOpts to solver_inputs_test.go
Signed-off-by: Ibrahim AshShohail <[email protected]>
1 parent 4a2215b commit 1f42a17

File tree

2 files changed

+152
-152
lines changed

2 files changed

+152
-152
lines changed

internal/gps/solve_test.go

Lines changed: 0 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@ import (
88
"bytes"
99
"flag"
1010
"fmt"
11-
"io/ioutil"
1211
"log"
13-
"math/rand"
1412
"reflect"
1513
"sort"
16-
"strconv"
1714
"strings"
1815
"testing"
1916
"unicode"
20-
21-
"github.com/golang/dep/internal/gps/pkgtree"
2217
)
2318

2419
var fixtorun string
@@ -292,150 +287,3 @@ func TestRootLockNoVersionPairMatching(t *testing.T) {
292287

293288
fixtureSolveSimpleChecks(fix, res, err, t)
294289
}
295-
296-
// TestBadSolveOpts exercises the different possible inputs to a solver that can
297-
// be determined as invalid in Prepare(), without any further work
298-
func TestBadSolveOpts(t *testing.T) {
299-
pn := strconv.FormatInt(rand.Int63(), 36)
300-
fix := basicFixtures["no dependencies"]
301-
fix.ds[0].n = ProjectRoot(pn)
302-
303-
sm := newdepspecSM(fix.ds, nil)
304-
params := SolveParameters{
305-
mkBridgeFn: overrideMkBridge,
306-
}
307-
308-
_, err := Prepare(params, nil)
309-
if err == nil {
310-
t.Errorf("Prepare should have errored on nil SourceManager")
311-
} else if !strings.Contains(err.Error(), "non-nil SourceManager") {
312-
t.Error("Prepare should have given error on nil SourceManager, but gave:", err)
313-
}
314-
315-
_, err = Prepare(params, sm)
316-
if err == nil {
317-
t.Errorf("Prepare should have errored without ProjectAnalyzer")
318-
} else if !strings.Contains(err.Error(), "must provide a ProjectAnalyzer") {
319-
t.Error("Prepare should have given error without ProjectAnalyzer, but gave:", err)
320-
}
321-
322-
params.ProjectAnalyzer = naiveAnalyzer{}
323-
_, err = Prepare(params, sm)
324-
if err == nil {
325-
t.Errorf("Prepare should have errored on empty root")
326-
} else if !strings.Contains(err.Error(), "non-empty root directory") {
327-
t.Error("Prepare should have given error on empty root, but gave:", err)
328-
}
329-
330-
params.RootDir = pn
331-
_, err = Prepare(params, sm)
332-
if err == nil {
333-
t.Errorf("Prepare should have errored on empty name")
334-
} else if !strings.Contains(err.Error(), "non-empty import root") {
335-
t.Error("Prepare should have given error on empty import root, but gave:", err)
336-
}
337-
338-
params.RootPackageTree = pkgtree.PackageTree{
339-
ImportRoot: pn,
340-
}
341-
_, err = Prepare(params, sm)
342-
if err == nil {
343-
t.Errorf("Prepare should have errored on empty name")
344-
} else if !strings.Contains(err.Error(), "at least one package") {
345-
t.Error("Prepare should have given error on empty import root, but gave:", err)
346-
}
347-
348-
params.RootPackageTree = pkgtree.PackageTree{
349-
ImportRoot: pn,
350-
Packages: map[string]pkgtree.PackageOrErr{
351-
pn: {
352-
P: pkgtree.Package{
353-
ImportPath: pn,
354-
Name: pn,
355-
},
356-
},
357-
},
358-
}
359-
params.TraceLogger = log.New(ioutil.Discard, "", 0)
360-
361-
params.Manifest = simpleRootManifest{
362-
ovr: ProjectConstraints{
363-
ProjectRoot("foo"): ProjectProperties{},
364-
},
365-
}
366-
_, err = Prepare(params, sm)
367-
if err == nil {
368-
t.Errorf("Should have errored on override with empty ProjectProperties")
369-
} else if !strings.Contains(err.Error(), "foo, but without any non-zero properties") {
370-
t.Error("Prepare should have given error override with empty ProjectProperties, but gave:", err)
371-
}
372-
373-
params.Manifest = simpleRootManifest{
374-
ig: map[string]bool{"foo": true},
375-
req: map[string]bool{"foo": true},
376-
}
377-
_, err = Prepare(params, sm)
378-
if err == nil {
379-
t.Errorf("Should have errored on pkg both ignored and required")
380-
} else if !strings.Contains(err.Error(), "was given as both a required and ignored package") {
381-
t.Error("Prepare should have given error with single ignore/require conflict error, but gave:", err)
382-
}
383-
384-
params.Manifest = simpleRootManifest{
385-
ig: map[string]bool{"foo": true, "bar": true},
386-
req: map[string]bool{"foo": true, "bar": true},
387-
}
388-
_, err = Prepare(params, sm)
389-
if err == nil {
390-
t.Errorf("Should have errored on pkg both ignored and required")
391-
} else if !strings.Contains(err.Error(), "multiple packages given as both required and ignored:") {
392-
t.Error("Prepare should have given error with multiple ignore/require conflict error, but gave:", err)
393-
}
394-
params.Manifest = nil
395-
396-
params.ToChange = []ProjectRoot{"foo"}
397-
_, err = Prepare(params, sm)
398-
if err == nil {
399-
t.Errorf("Should have errored on non-empty ToChange without a lock provided")
400-
} else if !strings.Contains(err.Error(), "update specifically requested for") {
401-
t.Error("Prepare should have given error on ToChange without Lock, but gave:", err)
402-
}
403-
404-
params.Lock = safeLock{
405-
p: []LockedProject{
406-
NewLockedProject(mkPI("bar"), Revision("makebelieve"), nil),
407-
},
408-
}
409-
_, err = Prepare(params, sm)
410-
if err == nil {
411-
t.Errorf("Should have errored on ToChange containing project not in lock")
412-
} else if !strings.Contains(err.Error(), "cannot update foo as it is not in the lock") {
413-
t.Error("Prepare should have given error on ToChange with item not present in Lock, but gave:", err)
414-
}
415-
416-
params.Lock, params.ToChange = nil, nil
417-
_, err = Prepare(params, sm)
418-
if err != nil {
419-
t.Error("Basic conditions satisfied, prepare should have completed successfully, err as:", err)
420-
}
421-
422-
// swap out the test mkBridge override temporarily, just to make sure we get
423-
// the right error
424-
params.mkBridgeFn = nil
425-
426-
_, err = Prepare(params, sm)
427-
if err == nil {
428-
t.Errorf("Should have errored on nonexistent root")
429-
} else if !strings.Contains(err.Error(), "could not read project root") {
430-
t.Error("Prepare should have given error nonexistent project root dir, but gave:", err)
431-
}
432-
433-
// Pointing it at a file should also be an err
434-
params.RootDir = "solve_test.go"
435-
_, err = Prepare(params, sm)
436-
if err == nil {
437-
t.Errorf("Should have errored on file for RootDir")
438-
} else if !strings.Contains(err.Error(), "is a file, not a directory") {
439-
t.Error("Prepare should have given error on file as RootDir, but gave:", err)
440-
}
441-
}

internal/gps/solver_inputs_test.go

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,164 @@
55
package gps
66

77
import (
8+
"io/ioutil"
9+
"log"
10+
"math/rand"
11+
"strconv"
12+
"strings"
813
"testing"
914

1015
"github.com/golang/dep/internal/gps/pkgtree"
1116
"github.com/golang/dep/internal/test"
1217
)
1318

19+
// TestBadSolveOpts exercises the different possible inputs to a solver that can
20+
// be determined as invalid in Prepare(), without any further work
21+
func TestBadSolveOpts(t *testing.T) {
22+
pn := strconv.FormatInt(rand.Int63(), 36)
23+
fix := basicFixtures["no dependencies"]
24+
fix.ds[0].n = ProjectRoot(pn)
25+
26+
sm := newdepspecSM(fix.ds, nil)
27+
params := SolveParameters{
28+
mkBridgeFn: overrideMkBridge,
29+
}
30+
31+
_, err := Prepare(params, nil)
32+
if err == nil {
33+
t.Errorf("Prepare should have errored on nil SourceManager")
34+
} else if !strings.Contains(err.Error(), "non-nil SourceManager") {
35+
t.Error("Prepare should have given error on nil SourceManager, but gave:", err)
36+
}
37+
38+
_, err = Prepare(params, sm)
39+
if err == nil {
40+
t.Errorf("Prepare should have errored without ProjectAnalyzer")
41+
} else if !strings.Contains(err.Error(), "must provide a ProjectAnalyzer") {
42+
t.Error("Prepare should have given error without ProjectAnalyzer, but gave:", err)
43+
}
44+
45+
params.ProjectAnalyzer = naiveAnalyzer{}
46+
_, err = Prepare(params, sm)
47+
if err == nil {
48+
t.Errorf("Prepare should have errored on empty root")
49+
} else if !strings.Contains(err.Error(), "non-empty root directory") {
50+
t.Error("Prepare should have given error on empty root, but gave:", err)
51+
}
52+
53+
params.RootDir = pn
54+
_, err = Prepare(params, sm)
55+
if err == nil {
56+
t.Errorf("Prepare should have errored on empty name")
57+
} else if !strings.Contains(err.Error(), "non-empty import root") {
58+
t.Error("Prepare should have given error on empty import root, but gave:", err)
59+
}
60+
61+
params.RootPackageTree = pkgtree.PackageTree{
62+
ImportRoot: pn,
63+
}
64+
_, err = Prepare(params, sm)
65+
if err == nil {
66+
t.Errorf("Prepare should have errored on empty name")
67+
} else if !strings.Contains(err.Error(), "at least one package") {
68+
t.Error("Prepare should have given error on empty import root, but gave:", err)
69+
}
70+
71+
params.RootPackageTree = pkgtree.PackageTree{
72+
ImportRoot: pn,
73+
Packages: map[string]pkgtree.PackageOrErr{
74+
pn: {
75+
P: pkgtree.Package{
76+
ImportPath: pn,
77+
Name: pn,
78+
},
79+
},
80+
},
81+
}
82+
params.TraceLogger = log.New(ioutil.Discard, "", 0)
83+
84+
params.Manifest = simpleRootManifest{
85+
ovr: ProjectConstraints{
86+
ProjectRoot("foo"): ProjectProperties{},
87+
},
88+
}
89+
_, err = Prepare(params, sm)
90+
if err == nil {
91+
t.Errorf("Should have errored on override with empty ProjectProperties")
92+
} else if !strings.Contains(err.Error(), "foo, but without any non-zero properties") {
93+
t.Error("Prepare should have given error override with empty ProjectProperties, but gave:", err)
94+
}
95+
96+
params.Manifest = simpleRootManifest{
97+
ig: map[string]bool{"foo": true},
98+
req: map[string]bool{"foo": true},
99+
}
100+
_, err = Prepare(params, sm)
101+
if err == nil {
102+
t.Errorf("Should have errored on pkg both ignored and required")
103+
} else if !strings.Contains(err.Error(), "was given as both a required and ignored package") {
104+
t.Error("Prepare should have given error with single ignore/require conflict error, but gave:", err)
105+
}
106+
107+
params.Manifest = simpleRootManifest{
108+
ig: map[string]bool{"foo": true, "bar": true},
109+
req: map[string]bool{"foo": true, "bar": true},
110+
}
111+
_, err = Prepare(params, sm)
112+
if err == nil {
113+
t.Errorf("Should have errored on pkg both ignored and required")
114+
} else if !strings.Contains(err.Error(), "multiple packages given as both required and ignored:") {
115+
t.Error("Prepare should have given error with multiple ignore/require conflict error, but gave:", err)
116+
}
117+
params.Manifest = nil
118+
119+
params.ToChange = []ProjectRoot{"foo"}
120+
_, err = Prepare(params, sm)
121+
if err == nil {
122+
t.Errorf("Should have errored on non-empty ToChange without a lock provided")
123+
} else if !strings.Contains(err.Error(), "update specifically requested for") {
124+
t.Error("Prepare should have given error on ToChange without Lock, but gave:", err)
125+
}
126+
127+
params.Lock = safeLock{
128+
p: []LockedProject{
129+
NewLockedProject(mkPI("bar"), Revision("makebelieve"), nil),
130+
},
131+
}
132+
_, err = Prepare(params, sm)
133+
if err == nil {
134+
t.Errorf("Should have errored on ToChange containing project not in lock")
135+
} else if !strings.Contains(err.Error(), "cannot update foo as it is not in the lock") {
136+
t.Error("Prepare should have given error on ToChange with item not present in Lock, but gave:", err)
137+
}
138+
139+
params.Lock, params.ToChange = nil, nil
140+
_, err = Prepare(params, sm)
141+
if err != nil {
142+
t.Error("Basic conditions satisfied, prepare should have completed successfully, err as:", err)
143+
}
144+
145+
// swap out the test mkBridge override temporarily, just to make sure we get
146+
// the right error
147+
params.mkBridgeFn = nil
148+
149+
_, err = Prepare(params, sm)
150+
if err == nil {
151+
t.Errorf("Should have errored on nonexistent root")
152+
} else if !strings.Contains(err.Error(), "could not read project root") {
153+
t.Error("Prepare should have given error nonexistent project root dir, but gave:", err)
154+
}
155+
156+
// Pointing it at a file should also be an err
157+
params.RootDir = "solve_test.go"
158+
_, err = Prepare(params, sm)
159+
if err == nil {
160+
t.Errorf("Should have errored on file for RootDir")
161+
} else if !strings.Contains(err.Error(), "is a file, not a directory") {
162+
t.Error("Prepare should have given error on file as RootDir, but gave:", err)
163+
}
164+
}
165+
14166
func TestValidateParams(t *testing.T) {
15167
h := test.NewHelper(t)
16168
defer h.Cleanup()

0 commit comments

Comments
 (0)