From 4591bc8d97ace946189202e1c2e89e031593faea Mon Sep 17 00:00:00 2001 From: Domenico Luciani Date: Thu, 28 Sep 2023 17:46:51 +0200 Subject: [PATCH] Add first failing test for the flattener Signed-off-by: Domenico Luciani --- pkg/buildpack/flattener.go | 16 ++++++++ pkg/buildpack/flattener_test.go | 70 +++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 pkg/buildpack/flattener.go create mode 100644 pkg/buildpack/flattener_test.go diff --git a/pkg/buildpack/flattener.go b/pkg/buildpack/flattener.go new file mode 100644 index 000000000..77b93bd20 --- /dev/null +++ b/pkg/buildpack/flattener.go @@ -0,0 +1,16 @@ +package buildpack + +type Flattener interface { + FlatBuildpacks() +} + +type BuildpacksFlattener struct { +} + +func NewBuildpacksFlattener() BuildpacksFlattener { + return BuildpacksFlattener{} +} + +func (bp BuildpacksFlattener) FlatBuildpacks(bps []BuildModule) []BuildModule { + return bps //TODO: Implementation +} diff --git a/pkg/buildpack/flattener_test.go b/pkg/buildpack/flattener_test.go new file mode 100644 index 000000000..a838eff2d --- /dev/null +++ b/pkg/buildpack/flattener_test.go @@ -0,0 +1,70 @@ +package buildpack_test + +import ( + "testing" + + "github.com/buildpacks/lifecycle/api" + "github.com/sclevine/spec" + "github.com/sclevine/spec/report" + + ifakes "github.com/buildpacks/pack/internal/fakes" + "github.com/buildpacks/pack/pkg/buildpack" + "github.com/buildpacks/pack/pkg/dist" + h "github.com/buildpacks/pack/testhelpers" +) + +func TestFlattener(t *testing.T) { + spec.Run(t, "Flattener", testFlattener, spec.Report(report.Terminal{})) +} + +func testFlattener(t *testing.T, when spec.G, it spec.S) { + var ( + bp1 buildpack.BuildModule + bp2 buildpack.BuildModule + bp3 buildpack.BuildModule + err error + ) + + it.Before(func() { + bp1, err = ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{ + WithAPI: api.MustParse("0.2"), + WithInfo: dist.ModuleInfo{ + ID: "buildpack-1-id", + Version: "buildpack-1-version", + }, + }, 0644) + h.AssertNil(t, err) + + bp2, err = ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{ + WithAPI: api.MustParse("0.2"), + WithInfo: dist.ModuleInfo{ + ID: "buildpack-2-id", + Version: "buildpack-2-version", + }, + }, 0644) + h.AssertNil(t, err) + + bp3, err = ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{ + WithAPI: api.MustParse("0.2"), + WithInfo: dist.ModuleInfo{ + ID: "buildpack-3-id", + Version: "buildpack-3-version", + }, + }, 0644) + h.AssertNil(t, err) + }) + + when("Flattener has been called", func() { + var ( + flattener buildpack.BuildpacksFlattener + ) + it.Before(func() { + flattener = buildpack.NewBuildpacksFlattener() + }) + + it("flats the buildpacks that has been passed", func() { + bps := flattener.FlatBuildpacks([]buildpack.BuildModule{bp1, bp2, bp3}) + h.AssertEq(t, len(bps), 1) + }) + }) +}