@@ -11,7 +11,7 @@ import (
11
11
"go.jetpack.io/devbox/planner/plansdk"
12
12
)
13
13
14
- func TestDevboxPlan (t * testing.T ) {
14
+ func TestDevbox (t * testing.T ) {
15
15
testPaths , err := doublestar .FilepathGlob ("./testdata/**/devbox.json" )
16
16
assert .NoError (t , err , "Reading testdata/ should not fail" )
17
17
@@ -22,11 +22,11 @@ func TestDevboxPlan(t *testing.T) {
22
22
assert .Greater (t , len (testPaths ), 0 , "testdata/ and examples/ should contain at least 1 test" )
23
23
24
24
for _ , testPath := range testPaths {
25
- testIndividualPlan (t , testPath )
25
+ testExample (t , testPath )
26
26
}
27
27
}
28
28
29
- func testIndividualPlan (t * testing.T , testPath string ) {
29
+ func testExample (t * testing.T , testPath string ) {
30
30
baseDir := filepath .Dir (testPath )
31
31
t .Run (baseDir , func (t * testing.T ) {
32
32
assert := assert .New (t )
@@ -37,6 +37,9 @@ func testIndividualPlan(t *testing.T, testPath string) {
37
37
assert .NoErrorf (err , "%s should be a valid devbox project" , baseDir )
38
38
plan := box .Plan ()
39
39
40
+ err = box .Generate ()
41
+ assert .NoError (err , "devbox generate should not fail" )
42
+
40
43
if ! hasGoldenFile {
41
44
assert .NotEmpty (plan .DevPackages , "the plan should have dev packages" )
42
45
return
@@ -48,22 +51,27 @@ func testIndividualPlan(t *testing.T, testPath string) {
48
51
expected := & plansdk.Plan {}
49
52
err = json .Unmarshal (data , & expected )
50
53
assert .NoError (err , "plan.json should parse correctly" )
51
- expected .Errors = nil
52
-
53
- assert .ElementsMatch (expected .DevPackages , plan .DevPackages , "DevPackages should match" )
54
- assert .ElementsMatch (expected .RuntimePackages , plan .RuntimePackages , "RuntimePackages should match" )
55
- assert .Equal (expected .InstallStage .GetCommand (), plan .InstallStage .GetCommand (), "Install stage should match" )
56
- assert .Equal (expected .BuildStage .GetCommand (), plan .BuildStage .GetCommand (), "Build stage should match" )
57
- assert .Equal (expected .StartStage .GetCommand (), plan .StartStage .GetCommand (), "Start stage should match" )
58
- // Check that input files are the same for all stages.
59
- // Depending on where the test command is invoked, the input file paths can be different.
60
- // We will compare the file name only.
61
- assert .ElementsMatch (expected .InstallStage .GetInputFiles (), getFileNames (plan .InstallStage .GetInputFiles ()), "InstallStage.InputFiles should match" )
62
- assert .ElementsMatch (expected .BuildStage .GetInputFiles (), getFileNames (plan .BuildStage .GetInputFiles ()), "BuildStage.InputFiles should match" )
63
- assert .ElementsMatch (expected .StartStage .GetInputFiles (), getFileNames (plan .StartStage .GetInputFiles ()), "StartStage.InputFiles should match" )
54
+
55
+ assertPlansMatch (t , expected , plan )
64
56
})
65
57
}
66
58
59
+ func assertPlansMatch (t * testing.T , expected * plansdk.Plan , actual * plansdk.Plan ) {
60
+ assert := assert .New (t )
61
+
62
+ assert .ElementsMatch (expected .DevPackages , actual .DevPackages , "DevPackages should match" )
63
+ assert .ElementsMatch (expected .RuntimePackages , actual .RuntimePackages , "RuntimePackages should match" )
64
+ assert .Equal (expected .InstallStage .GetCommand (), actual .InstallStage .GetCommand (), "Install stage should match" )
65
+ assert .Equal (expected .BuildStage .GetCommand (), actual .BuildStage .GetCommand (), "Build stage should match" )
66
+ assert .Equal (expected .StartStage .GetCommand (), actual .StartStage .GetCommand (), "Start stage should match" )
67
+ // Check that input files are the same for all stages.
68
+ // Depending on where the test command is invoked, the input file paths can be different.
69
+ // We will compare the file name only.
70
+ assert .ElementsMatch (expected .InstallStage .GetInputFiles (), getFileNames (actual .InstallStage .GetInputFiles ()), "InstallStage.InputFiles should match" )
71
+ assert .ElementsMatch (expected .BuildStage .GetInputFiles (), getFileNames (actual .BuildStage .GetInputFiles ()), "BuildStage.InputFiles should match" )
72
+ assert .ElementsMatch (expected .StartStage .GetInputFiles (), getFileNames (actual .StartStage .GetInputFiles ()), "StartStage.InputFiles should match" )
73
+ }
74
+
67
75
func fileExists (path string ) bool {
68
76
_ , err := os .Stat (path )
69
77
return err == nil
0 commit comments