Skip to content

Commit 5b494ed

Browse files
authored
Run generate as part of TestDevbox (#101)
## Summary In addition to running `devbox plan`, also run `devbox generate` as part of `TestDevbox`. This will ensure that we also exercise the ability to convert the plan into generated files via go templates. In the process: + Cleanup the `devbox_test.go` logic a bit. Move `assertPlansMatch` into its own function. + Move `python-poetry-not-buildable` from `examples/` to `testdata/` – although is it different from the existing `poetry-no-entrypoint`? ## How was it tested? `go test -v ./...`
1 parent 26e7e82 commit 5b494ed

File tree

8 files changed

+24
-16
lines changed

8 files changed

+24
-16
lines changed

devbox_test.go

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {
1515
testPaths, err := doublestar.FilepathGlob("./testdata/**/devbox.json")
1616
assert.NoError(t, err, "Reading testdata/ should not fail")
1717

@@ -22,11 +22,11 @@ func TestDevboxPlan(t *testing.T) {
2222
assert.Greater(t, len(testPaths), 0, "testdata/ and examples/ should contain at least 1 test")
2323

2424
for _, 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) {
3030
baseDir := filepath.Dir(testPath)
3131
t.Run(baseDir, func(t *testing.T) {
3232
assert := assert.New(t)
@@ -37,6 +37,9 @@ func testIndividualPlan(t *testing.T, testPath string) {
3737
assert.NoErrorf(err, "%s should be a valid devbox project", baseDir)
3838
plan := box.Plan()
3939

40+
err = box.Generate()
41+
assert.NoError(err, "devbox generate should not fail")
42+
4043
if !hasGoldenFile {
4144
assert.NotEmpty(plan.DevPackages, "the plan should have dev packages")
4245
return
@@ -48,22 +51,27 @@ func testIndividualPlan(t *testing.T, testPath string) {
4851
expected := &plansdk.Plan{}
4952
err = json.Unmarshal(data, &expected)
5053
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)
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+
6775
func fileExists(path string) bool {
6876
_, err := os.Stat(path)
6977
return err == nil
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)