From 6f59ab3d1954dfe7bb3ceca18879c62408a8f422 Mon Sep 17 00:00:00 2001 From: Daniel Mikusa Date: Tue, 31 Mar 2020 15:45:50 -0400 Subject: [PATCH 1/2] Added support for multiple build plans during detection. [#171748623] Co-authored-by: Timothy Hitchener --- detect.go | 4 +++ detect_test.go | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/detect.go b/detect.go index da95d1a8..6ab258d5 100644 --- a/detect.go +++ b/detect.go @@ -55,6 +55,10 @@ type BuildPlan struct { // Requires is a list of BuildPlanRequirements that are required by this // buildpack. Requires []BuildPlanRequirement `toml:"requires"` + + // Or is a list of additional BuildPlans that may be selected by the + // lifecycle + Or []BuildPlan `toml:"or,omitepty"` } // BuildPlanProvision is a representation of a dependency that can be provided diff --git a/detect_test.go b/detect_test.go index 8fe7f602..e9d35f38 100644 --- a/detect_test.go +++ b/detect_test.go @@ -127,6 +127,95 @@ some-key = "some-value" `)) }) + it("writes out the buildplan.toml with multiple plans", func() { + path := filepath.Join(tmpDir, "buildplan.toml") + + packit.Detect(func(packit.DetectContext) (packit.DetectResult, error) { + return packit.DetectResult{ + Plan: packit.BuildPlan{ + Provides: []packit.BuildPlanProvision{ + {Name: "some-provision"}, + }, + Requires: []packit.BuildPlanRequirement{ + { + Name: "some-requirement", + Version: "some-version", + Metadata: map[string]string{ + "some-key": "some-value", + }, + }, + }, + Or: []packit.BuildPlan{ + { + Provides: []packit.BuildPlanProvision{ + {Name: "some-other-provision"}, + }, + Requires: []packit.BuildPlanRequirement{ + { + Name: "some-other-requirement", + Version: "some-other-version", + Metadata: map[string]string{ + "some-other-key": "some-other-value", + }, + }, + }, + }, + { + Provides: []packit.BuildPlanProvision{ + {Name: "some-another-provision"}, + }, + Requires: []packit.BuildPlanRequirement{ + { + Name: "some-another-requirement", + Version: "some-another-version", + Metadata: map[string]string{ + "some-another-key": "some-another-value", + }, + }, + }, + }, + }, + }, + }, nil + }, packit.WithArgs([]string{binaryPath, "", path})) + + contents, err := ioutil.ReadFile(path) + Expect(err).NotTo(HaveOccurred()) + + Expect(string(contents)).To(MatchTOML(` +[[provides]] + name = "some-provision" + +[[requires]] + name = "some-requirement" + version = "some-version" + [requires.metadata] + some-key = "some-value" + +[[or]] + + [[or.provides]] + name = "some-other-provision" + + [[or.requires]] + name = "some-other-requirement" + version = "some-other-version" + [or.requires.metadata] + some-other-key = "some-other-value" + +[[or]] + + [[or.provides]] + name = "some-another-provision" + + [[or.requires]] + name = "some-another-requirement" + version = "some-another-version" + [or.requires.metadata] + some-another-key = "some-another-value" +`)) + }) + context("when the DetectFunc returns an error", func() { it("calls the ExitHandler with that error", func() { packit.Detect(func(ctx packit.DetectContext) (packit.DetectResult, error) { From d9727e881daa1032e54a3a5b65b411ed541e00b9 Mon Sep 17 00:00:00 2001 From: Daniel Mikusa Date: Thu, 2 Apr 2020 10:37:05 -0400 Subject: [PATCH 2/2] Update detect.go Fixed typo --- detect.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detect.go b/detect.go index 6ab258d5..07f26515 100644 --- a/detect.go +++ b/detect.go @@ -58,7 +58,7 @@ type BuildPlan struct { // Or is a list of additional BuildPlans that may be selected by the // lifecycle - Or []BuildPlan `toml:"or,omitepty"` + Or []BuildPlan `toml:"or,omitempty"` } // BuildPlanProvision is a representation of a dependency that can be provided