Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow storing multiple commands instead of a single string #920

Merged
merged 15 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions acceptance/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
h.AssertStringContains(t, md.Buildpacks[0].API, "0.2")
h.AssertStringContains(t, md.Buildpacks[0].ID, "hello_world")
h.AssertStringContains(t, md.Buildpacks[0].Version, "0.0.1")
h.AssertEq(t, 1, len(md.Processes))
h.AssertEq(t, "hello", md.Processes[0].Type)
h.AssertEq(t, "echo world", md.Processes[0].Command[0])
h.AssertEq(t, 1, len(md.Processes[0].Args))
h.AssertEq(t, "arg1", md.Processes[0].Args[0])
h.AssertEq(t, false, md.Processes[0].Direct)
h.AssertEq(t, "", md.Processes[0].WorkingDirectory)
h.AssertEq(t, false, md.Processes[0].Default)
})
})

Expand Down Expand Up @@ -445,6 +453,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
}

func getBuilderMetadata(t *testing.T, path string) *platform.BuildMetadata {
t.Helper()
contents, _ := ioutil.ReadFile(path)
h.AssertEq(t, len(contents) > 0, true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ echo "plan contents:"
cat ${plan_path}
echo

# Set default start command
cat > "${layers_dir}/launch.toml" << EOL
[[processes]]
type = "hello"
command = "echo world"
args = ["arg1"]
direct = false
EOL

echo "---> Done"
74 changes: 40 additions & 34 deletions builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/apex/log/handlers/memory"
"github.com/golang/mock/gomock"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pkg/errors"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
Expand All @@ -37,6 +38,11 @@ func TestBuilder(t *testing.T) {
//go:generate mockgen -package testmock -destination testmock/dir_store.go github.com/buildpacks/lifecycle DirStore
//go:generate mockgen -package testmock -destination testmock/build_module.go github.com/buildpacks/lifecycle/buildpack BuildModule

// RawCommandValue should be ignored because it is a toml.Primitive that has not been exported.
var processCmpOpts = []cmp.Option{
cmpopts.IgnoreFields(launch.Process{}, "RawCommandValue"),
}

func testBuilder(t *testing.T, when spec.G, it spec.S) {
var (
builder *lifecycle.Builder
Expand Down Expand Up @@ -494,14 +500,14 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
Processes: []launch.Process{
{
Type: "some-type",
Command: "some-command",
Command: []string{"some-command"},
Args: []string{"some-arg"},
Direct: true,
BuildpackID: "A",
},
{
Type: "override-type",
Command: "bpA-command",
Command: []string{"bpA-command"},
Args: []string{"bpA-arg"},
Direct: true,
BuildpackID: "A",
Expand All @@ -514,14 +520,14 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
Processes: []launch.Process{
{
Type: "some-other-type",
Command: "some-other-command",
Command: []string{"some-other-command"},
Args: []string{"some-other-arg"},
Direct: true,
BuildpackID: "B",
},
{
Type: "override-type",
Command: "bpB-command",
Command: []string{"bpB-command"},
Args: []string{"bpB-arg"},
Direct: false,
BuildpackID: "B",
Expand All @@ -534,26 +540,26 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
if s := cmp.Diff(metadata.Processes, []launch.Process{
{
Type: "override-type",
Command: "bpB-command",
Command: []string{"bpB-command"},
Args: []string{"bpB-arg"},
Direct: false,
BuildpackID: "B",
},
{
Type: "some-other-type",
Command: "some-other-command",
Command: []string{"some-other-command"},
Args: []string{"some-other-arg"},
Direct: true,
BuildpackID: "B",
},
{
Type: "some-type",
Command: "some-command",
Command: []string{"some-command"},
Args: []string{"some-arg"},
Direct: true,
BuildpackID: "A",
},
}); s != "" {
}, processCmpOpts...); s != "" {
t.Fatalf("Unexpected:\n%s\n", s)
}
h.AssertEq(t, metadata.BuildpackDefaultProcessType, "")
Expand All @@ -575,7 +581,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
Processes: []launch.Process{
{
Type: "override-type",
Command: "bpA-command",
Command: []string{"bpA-command"},
Args: []string{"bpA-arg"},
Direct: true,
BuildpackID: "A",
Expand All @@ -589,7 +595,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
Processes: []launch.Process{
{
Type: "some-type",
Command: "bpB-command",
Command: []string{"bpB-command"},
Args: []string{"bpB-arg"},
Direct: false,
BuildpackID: "B",
Expand All @@ -604,7 +610,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
Processes: []launch.Process{
{
Type: "override-type",
Command: "bpC-command",
Command: []string{"bpC-command"},
Args: []string{"bpC-arg"},
Direct: false,
BuildpackID: "C",
Expand All @@ -618,19 +624,19 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
if s := cmp.Diff(metadata.Processes, []launch.Process{
{
Type: "override-type",
Command: "bpC-command",
Command: []string{"bpC-command"},
Args: []string{"bpC-arg"},
Direct: false,
BuildpackID: "C",
},
{
Type: "some-type",
Command: "bpB-command",
Command: []string{"bpB-command"},
Args: []string{"bpB-arg"},
Direct: false,
BuildpackID: "B",
},
}); s != "" {
}, processCmpOpts...); s != "" {
t.Fatalf("Unexpected:\n%s\n", s)
}
h.AssertEq(t, metadata.BuildpackDefaultProcessType, "some-type")
Expand All @@ -653,7 +659,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
Processes: []launch.Process{
{
Type: "some-type",
Command: "bpA-command",
Command: []string{"bpA-command"},
Args: []string{"bpA-arg"},
Direct: false,
BuildpackID: "A",
Expand All @@ -668,7 +674,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
Processes: []launch.Process{
{
Type: "override-type",
Command: "bpB-command",
Command: []string{"bpB-command"},
Args: []string{"bpB-arg"},
Direct: true,
BuildpackID: "B",
Expand All @@ -683,7 +689,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
Processes: []launch.Process{
{
Type: "override-type",
Command: "bpC-command",
Command: []string{"bpC-command"},
Args: []string{"bpC-arg"},
Direct: false,
BuildpackID: "C",
Expand All @@ -696,19 +702,19 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
if s := cmp.Diff(metadata.Processes, []launch.Process{
{
Type: "override-type",
Command: "bpC-command",
Command: []string{"bpC-command"},
Args: []string{"bpC-arg"},
Direct: false,
BuildpackID: "C",
},
{
Type: "some-type",
Command: "bpA-command",
Command: []string{"bpA-command"},
Args: []string{"bpA-arg"},
Direct: false,
BuildpackID: "A",
},
}); s != "" {
}, processCmpOpts...); s != "" {
t.Fatalf("Unexpected:\n%s\n", s)
}

Expand All @@ -734,7 +740,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
Processes: []launch.Process{
{
Type: "web",
Command: "web-cmd",
Command: []string{"web-cmd"},
Args: []string{"web-arg"},
Direct: false,
BuildpackID: "A",
Expand All @@ -749,13 +755,13 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
if s := cmp.Diff(metadata.Processes, []launch.Process{
{
Type: "web",
Command: "web-cmd",
Command: []string{"web-cmd"},
Args: []string{"web-arg"},
Direct: false,
BuildpackID: "A",
Default: false,
},
}); s != "" {
}, processCmpOpts...); s != "" {
t.Fatalf("Unexpected:\n%s\n", s)
}
h.AssertEq(t, metadata.BuildpackDefaultProcessType, "")
Expand All @@ -776,15 +782,15 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
Processes: []launch.Process{
{
Type: "web",
Command: "web-cmd",
Command: []string{"web-cmd"},
Args: []string{"web-arg"},
Direct: false,
BuildpackID: "A",
Default: false,
},
{
Type: "not-web",
Command: "not-web-cmd",
Command: []string{"not-web-cmd"},
Args: []string{"not-web-arg"},
Direct: true,
BuildpackID: "A",
Expand All @@ -799,19 +805,19 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
if s := cmp.Diff(metadata.Processes, []launch.Process{
{
Type: "not-web",
Command: "not-web-cmd",
Command: []string{"not-web-cmd"},
Args: []string{"not-web-arg"},
Direct: true,
BuildpackID: "A",
},
{
Type: "web",
Command: "web-cmd",
Command: []string{"web-cmd"},
Args: []string{"web-arg"},
Direct: false,
BuildpackID: "A",
},
}); s != "" {
}, processCmpOpts...); s != "" {
t.Fatalf("Unexpected:\n%s\n", s)
}
h.AssertEq(t, metadata.BuildpackDefaultProcessType, "web")
Expand Down Expand Up @@ -953,7 +959,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
Processes: []launch.Process{
{
Type: "web",
Command: "web-cmd",
Command: []string{"web-cmd"},
Args: []string{"web-arg"},
Direct: false,
BuildpackID: "A",
Expand All @@ -968,13 +974,13 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
if s := cmp.Diff(metadata.Processes, []launch.Process{
{
Type: "web",
Command: "web-cmd",
Command: []string{"web-cmd"},
Args: []string{"web-arg"},
Direct: false,
BuildpackID: "A",
Default: false,
},
}); s != "" {
}, processCmpOpts...); s != "" {
t.Fatalf("Unexpected:\n%s\n", s)
}
h.AssertEq(t, metadata.BuildpackDefaultProcessType, "")
Expand All @@ -995,7 +1001,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
Processes: []launch.Process{
{
Type: "web",
Command: "web-cmd",
Command: []string{"web-cmd"},
Args: []string{"web-arg"},
Direct: false,
BuildpackID: "A",
Expand All @@ -1010,13 +1016,13 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
if s := cmp.Diff(metadata.Processes, []launch.Process{
{
Type: "web",
Command: "web-cmd",
Command: []string{"web-cmd"},
Args: []string{"web-arg"},
Direct: false,
BuildpackID: "A",
Default: false,
},
}); s != "" {
}, processCmpOpts...); s != "" {
t.Fatalf("Unexpected:\n%s\n", s)
}
h.AssertEq(t, metadata.BuildpackDefaultProcessType, "")
Expand Down
Loading