@@ -11,34 +11,49 @@ import (
11
11
"go.jetpack.io/devbox/planner"
12
12
)
13
13
14
- func TestPlan (t * testing.T ) {
14
+ func TestDevboxPlan (t * testing.T ) {
15
15
testPaths , err := doublestar .FilepathGlob ("./testdata/**/devbox.json" )
16
16
assert .NoError (t , err , "Reading testdata/ should not fail" )
17
- assert .Greater (t , len (testPaths ), 0 , "testdata/ should contain at least 1 test" )
17
+
18
+ examplePaths , err := doublestar .FilepathGlob ("./examples/**/devbox.json" )
19
+ assert .NoError (t , err , "Reading examples/ should not fail" )
20
+
21
+ testPaths = append (testPaths , examplePaths ... )
22
+ assert .Greater (t , len (testPaths ), 0 , "testdata/ and examples/ should contain at least 1 test" )
18
23
19
24
for _ , testPath := range testPaths {
20
- baseDir := filepath .Dir (testPath )
21
- t .Run (baseDir , func (t * testing.T ) {
22
- assert := assert .New (t )
23
- goldenFile := filepath .Join (baseDir , "plan.json" )
24
- hasGoldenFile := fileExists (goldenFile )
25
-
26
- box , err := Open (baseDir )
27
- assert .NoErrorf (err , "%s should be a valid devbox project" , baseDir )
28
- plan := box .Plan ()
25
+ testIndividualPlan (t , testPath )
26
+ }
27
+ }
28
+
29
+ func testIndividualPlan (t * testing.T , testPath string ) {
30
+ baseDir := filepath .Dir (testPath )
31
+ t .Run (baseDir , func (t * testing.T ) {
32
+ assert := assert .New (t )
33
+ goldenFile := filepath .Join (baseDir , "plan.json" )
34
+ hasGoldenFile := fileExists (goldenFile )
35
+
36
+ box , err := Open (baseDir )
37
+ assert .NoErrorf (err , "%s should be a valid devbox project" , baseDir )
38
+ plan := box .Plan ()
39
+
40
+ if ! hasGoldenFile {
29
41
assert .NotEmpty (plan .DevPackages , "the plan should have dev packages" )
30
- if hasGoldenFile {
31
- data , err := os .ReadFile (goldenFile )
32
- assert .NoError (err , "plan.json should be readable" )
42
+ return
43
+ }
33
44
34
- expected := & planner.Plan {}
35
- err = json .Unmarshal (data , & expected )
36
- assert .NoError (err , "plan.json should parse correctly" )
45
+ data , err := os .ReadFile (goldenFile )
46
+ assert .NoError (err , "plan.json should be readable" )
37
47
38
- assert .Equal (expected , plan )
39
- }
40
- })
41
- }
48
+ expected := & planner.Plan {}
49
+ err = json .Unmarshal (data , & expected )
50
+ assert .NoError (err , "plan.json should parse correctly" )
51
+ expected .Errors = nil
52
+
53
+ // For now we only compare the DevPackages and RuntimePackages fields:
54
+ assert .ElementsMatch (expected .DevPackages , plan .DevPackages , "DevPackages should match" )
55
+ assert .ElementsMatch (expected .RuntimePackages , plan .RuntimePackages , "RuntimePackages should match" )
56
+ })
42
57
}
43
58
44
59
func fileExists (path string ) bool {
0 commit comments