@@ -11,7 +11,7 @@ import (
1111"go.jetpack.io/devbox/planner/plansdk"
1212)
1313
14- func TestDevboxPlan (t * testing.T ) {
14+ func TestDevbox (t * testing.T ) {
1515testPaths , err := doublestar .FilepathGlob ("./testdata/**/devbox.json" )
1616assert .NoError (t , err , "Reading testdata/ should not fail" )
1717
@@ -22,11 +22,11 @@ func TestDevboxPlan(t *testing.T) {
2222assert .Greater (t , len (testPaths ), 0 , "testdata/ and examples/ should contain at least 1 test" )
2323
2424for _ , testPath := range testPaths {
25- testIndividualPlan (t , testPath )
25+ testExample (t , testPath )
2626}
2727}
2828
29- func testIndividualPlan (t * testing.T , testPath string ) {
29+ func testExample (t * testing.T , testPath string ) {
3030baseDir := filepath .Dir (testPath )
3131t .Run (baseDir , func (t * testing.T ) {
3232assert := assert .New (t )
@@ -37,6 +37,9 @@ func testIndividualPlan(t *testing.T, testPath string) {
3737assert .NoErrorf (err , "%s should be a valid devbox project" , baseDir )
3838plan := box .Plan ()
3939
40+ err = box .Generate ()
41+ assert .NoError (err , "devbox generate should not fail" )
42+
4043if ! hasGoldenFile {
4144assert .NotEmpty (plan .DevPackages , "the plan should have dev packages" )
4245return
@@ -48,22 +51,27 @@ func testIndividualPlan(t *testing.T, testPath string) {
4851expected := & plansdk.Plan {}
4952err = json .Unmarshal (data , & expected )
5053assert .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 )
6456})
6557}
6658
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+
6775func fileExists (path string ) bool {
6876_ , err := os .Stat (path )
6977return err == nil
0 commit comments