Skip to content

Commit

Permalink
Add first failing test for the flattener
Browse files Browse the repository at this point in the history
Signed-off-by: Domenico Luciani <[email protected]>
  • Loading branch information
Domenico Luciani committed Sep 28, 2023
1 parent 208fc87 commit 4591bc8
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/buildpack/flattener.go
Original file line number Diff line number Diff line change
@@ -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
}
70 changes: 70 additions & 0 deletions pkg/buildpack/flattener_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
})
}

0 comments on commit 4591bc8

Please sign in to comment.