Skip to content

Commit 6edc177

Browse files
authored
Add Node planner test and additional checks for planner fields (#87)
## Summary Add Node planner test and additional checks for planner fields ## How was it tested? go test ./...
1 parent 7828042 commit 6edc177

File tree

31 files changed

+335
-70
lines changed

31 files changed

+335
-70
lines changed

devbox_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,34 @@ func testIndividualPlan(t *testing.T, testPath string) {
5050
assert.NoError(err, "plan.json should parse correctly")
5151
expected.Errors = nil
5252

53-
// For now we only compare the DevPackages and RuntimePackages fields:
5453
assert.ElementsMatch(expected.DevPackages, plan.DevPackages, "DevPackages should match")
5554
assert.ElementsMatch(expected.RuntimePackages, plan.RuntimePackages, "RuntimePackages should match")
5655
assert.Equal(expected.InstallStage.GetCommand(), plan.InstallStage.GetCommand(), "Install stage should match")
5756
assert.Equal(expected.BuildStage.GetCommand(), plan.BuildStage.GetCommand(), "Build stage should match")
5857
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")
5964
})
6065
}
6166

6267
func fileExists(path string) bool {
6368
_, err := os.Stat(path)
6469
return err == nil
6570
}
71+
72+
func getFileNames(paths []string) []string {
73+
names := []string{}
74+
for _, path := range paths {
75+
if path == "." {
76+
names = append(names, path)
77+
} else {
78+
names = append(names, filepath.Base(path))
79+
}
80+
}
81+
82+
return names
83+
}

examples/go/devbox.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"packages": []
3+
}

examples/nodejs/devbox.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"packages": []
3+
}

examples/php/devbox.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"packages": []
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"packages": []
3+
}

examples/python-poetry/devbox.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"packages": []
3+
}

planner/plan.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ func (s *Stage) GetCommand() string {
5959
return s.Command
6060
}
6161

62+
func (s *Stage) GetInputFiles() []string {
63+
if s == nil {
64+
return []string{}
65+
}
66+
return s.InputFiles
67+
}
68+
6269
func (p *Plan) String() string {
6370
b, err := json.MarshalIndent(p, "", " ")
6471
if err != nil {

testdata/go/go-1.17/plan.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
{
2-
"dev_packages": [
3-
"go_1_17"
4-
],
5-
"runtime_packages": [],
62
"install_stage": {
7-
"command": "go get"
3+
"command": "go get",
4+
"input_files": [
5+
"."
6+
]
87
},
98
"build_stage": {
109
"command": "CGO_ENABLED=0 go build -o app"
1110
},
1211
"start_stage": {
13-
"command": "./app"
14-
}
15-
}
12+
"command": "./app",
13+
"input_files": [
14+
"."
15+
]
16+
},
17+
"dev_packages": [
18+
"go_1_17"
19+
],
20+
"runtime_packages": []
21+
}

testdata/go/go-1.18/plan.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
{
2-
"dev_packages": [
3-
"go"
4-
],
5-
"runtime_packages": [],
62
"install_stage": {
7-
"command": "go get"
3+
"command": "go get",
4+
"input_files": [
5+
"."
6+
]
87
},
98
"build_stage": {
109
"command": "CGO_ENABLED=0 go build -o app"
1110
},
1211
"start_stage": {
13-
"command": "./app"
14-
}
15-
}
12+
"command": "./app",
13+
"input_files": [
14+
"."
15+
]
16+
},
17+
"dev_packages": [
18+
"go"
19+
],
20+
"runtime_packages": []
21+
}

testdata/go/go-1.19/plan.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
{
2-
"dev_packages": [
3-
"go_1_19"
4-
],
5-
"runtime_packages": [],
62
"install_stage": {
7-
"command": "go get"
3+
"command": "go get",
4+
"input_files": [
5+
"."
6+
]
87
},
98
"build_stage": {
109
"command": "CGO_ENABLED=0 go build -o app"
1110
},
1211
"start_stage": {
13-
"command": "./app"
14-
}
15-
}
12+
"command": "./app",
13+
"input_files": [
14+
"."
15+
]
16+
},
17+
"dev_packages": [
18+
"go_1_19"
19+
],
20+
"runtime_packages": []
21+
}

0 commit comments

Comments
 (0)