Skip to content

Commit

Permalink
Use packit v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Wigmore authored and ryanmoran committed Jan 31, 2022
1 parent 8f69980 commit 905bc34
Show file tree
Hide file tree
Showing 12 changed files with 837 additions and 89 deletions.
10 changes: 5 additions & 5 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"time"

"github.com/Masterminds/semver"
"github.com/paketo-buildpacks/packit"
"github.com/paketo-buildpacks/packit/chronos"
"github.com/paketo-buildpacks/packit/postal"
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/chronos"
"github.com/paketo-buildpacks/packit/v2/postal"
)

//go:generate faux --interface EntryResolver --output fakes/entry_resolver.go
Expand All @@ -19,7 +19,7 @@ type EntryResolver interface {
//go:generate faux --interface DependencyManager --output fakes/dependency_manager.go
type DependencyManager interface {
Resolve(path, id, version, stack string) (postal.Dependency, error)
Install(dependency postal.Dependency, cnbPath, layerPath string) error
Deliver(dependency postal.Dependency, cnbPath, layerPath, platformPath string) error
GenerateBillOfMaterials(dependencies ...postal.Dependency) []packit.BOMEntry
}

Expand Down Expand Up @@ -100,7 +100,7 @@ func Build(

logger.Subprocess("Installing Bundler %s", dependency.Version)
duration, err := clock.Measure(func() error {
err := dependencies.Install(dependency, context.CNBPath, bundlerLayer.Path)
err := dependencies.Deliver(dependency, context.CNBPath, bundlerLayer.Path, context.Platform.Path)
if err != nil {
return err
}
Expand Down
81 changes: 44 additions & 37 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import (

"github.com/paketo-buildpacks/bundler"
"github.com/paketo-buildpacks/bundler/fakes"
"github.com/paketo-buildpacks/packit"
"github.com/paketo-buildpacks/packit/chronos"
"github.com/paketo-buildpacks/packit/postal"
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/chronos"
"github.com/paketo-buildpacks/packit/v2/postal"

//nolint Ignore SA1019, informed usage of deprecated package
"github.com/paketo-buildpacks/packit/v2/paketosbom"
"github.com/sclevine/spec"

. "github.com/onsi/gomega"
Expand Down Expand Up @@ -86,10 +89,10 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
dependencyManager.GenerateBillOfMaterialsCall.Returns.BOMEntrySlice = []packit.BOMEntry{
{
Name: "bundler",
Metadata: packit.BOMMetadata{
Metadata: paketosbom.BOMMetadata{
Version: "bundler-dependency-version",
Checksum: packit.BOMChecksum{
Algorithm: packit.SHA256,
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "bundler-dependency-sha",
},
URI: "bundler-dependency-uri",
Expand Down Expand Up @@ -142,7 +145,8 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
},
},
},
Layers: packit.Layers{Path: layersDir},
Platform: packit.Platform{Path: "platform"},
Layers: packit.Layers{Path: layersDir},
})
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal(packit.BuildResult{
Expand Down Expand Up @@ -170,10 +174,10 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
BOM: []packit.BOMEntry{
{
Name: "bundler",
Metadata: packit.BOMMetadata{
Metadata: paketosbom.BOMMetadata{
Version: "bundler-dependency-version",
Checksum: packit.BOMChecksum{
Algorithm: packit.SHA256,
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "bundler-dependency-sha",
},
URI: "bundler-dependency-uri",
Expand All @@ -185,10 +189,10 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
BOM: []packit.BOMEntry{
{
Name: "bundler",
Metadata: packit.BOMMetadata{
Metadata: paketosbom.BOMMetadata{
Version: "bundler-dependency-version",
Checksum: packit.BOMChecksum{
Algorithm: packit.SHA256,
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "bundler-dependency-sha",
},
URI: "bundler-dependency-uri",
Expand Down Expand Up @@ -237,12 +241,13 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
},
}))

Expect(dependencyManager.InstallCall.Receives.Dependency).To(Equal(postal.Dependency{
Expect(dependencyManager.DeliverCall.Receives.Dependency).To(Equal(postal.Dependency{
Name: "Bundler",
Version: "2.0.1",
}))
Expect(dependencyManager.InstallCall.Receives.CnbPath).To(Equal(cnbDir))
Expect(dependencyManager.InstallCall.Receives.LayerPath).To(Equal(filepath.Join(layersDir, "bundler")))
Expect(dependencyManager.DeliverCall.Receives.CnbPath).To(Equal(cnbDir))
Expect(dependencyManager.DeliverCall.Receives.LayerPath).To(Equal(filepath.Join(layersDir, "bundler")))
Expect(dependencyManager.DeliverCall.Receives.PlatformPath).To(Equal("platform"))

Expect(versionShimmer.ShimCall.Receives.Path).To(Equal(filepath.Join(layersDir, "bundler", "bin")))
Expect(versionShimmer.ShimCall.Receives.Version).To(Equal("2.0.1"))
Expand Down Expand Up @@ -326,10 +331,10 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
BOM: []packit.BOMEntry{
{
Name: "bundler",
Metadata: packit.BOMMetadata{
Metadata: paketosbom.BOMMetadata{
Version: "bundler-dependency-version",
Checksum: packit.BOMChecksum{
Algorithm: packit.SHA256,
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "bundler-dependency-sha",
},
URI: "bundler-dependency-uri",
Expand Down Expand Up @@ -410,10 +415,10 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
BOM: []packit.BOMEntry{
{
Name: "bundler",
Metadata: packit.BOMMetadata{
Metadata: paketosbom.BOMMetadata{
Version: "bundler-dependency-version",
Checksum: packit.BOMChecksum{
Algorithm: packit.SHA256,
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "bundler-dependency-sha",
},
URI: "bundler-dependency-uri",
Expand Down Expand Up @@ -483,10 +488,10 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
BOM: []packit.BOMEntry{
{
Name: "bundler",
Metadata: packit.BOMMetadata{
Metadata: paketosbom.BOMMetadata{
Version: "bundler-dependency-version",
Checksum: packit.BOMChecksum{
Algorithm: packit.SHA256,
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "bundler-dependency-sha",
},
URI: "bundler-dependency-uri",
Expand All @@ -503,7 +508,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
},
}))

Expect(dependencyManager.InstallCall.CallCount).To(Equal(0))
Expect(dependencyManager.DeliverCall.CallCount).To(Equal(0))

Expect(buffer.String()).To(ContainSubstring("Some Buildpack some-version"))
Expect(buffer.String()).To(ContainSubstring("Resolving Bundler version"))
Expand Down Expand Up @@ -552,7 +557,8 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
},
},
},
Layers: packit.Layers{Path: layersDir},
Platform: packit.Platform{Path: "platform"},
Layers: packit.Layers{Path: layersDir},
})
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal(packit.BuildResult{
Expand Down Expand Up @@ -580,10 +586,10 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
BOM: []packit.BOMEntry{
{
Name: "bundler",
Metadata: packit.BOMMetadata{
Metadata: paketosbom.BOMMetadata{
Version: "bundler-dependency-version",
Checksum: packit.BOMChecksum{
Algorithm: packit.SHA256,
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "bundler-dependency-sha",
},
URI: "bundler-dependency-uri",
Expand All @@ -595,10 +601,10 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
BOM: []packit.BOMEntry{
{
Name: "bundler",
Metadata: packit.BOMMetadata{
Metadata: paketosbom.BOMMetadata{
Version: "bundler-dependency-version",
Checksum: packit.BOMChecksum{
Algorithm: packit.SHA256,
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "bundler-dependency-sha",
},
URI: "bundler-dependency-uri",
Expand Down Expand Up @@ -647,12 +653,13 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
},
}))

Expect(dependencyManager.InstallCall.Receives.Dependency).To(Equal(postal.Dependency{
Expect(dependencyManager.DeliverCall.Receives.Dependency).To(Equal(postal.Dependency{
Name: "Bundler",
Version: "1.17.x",
}))
Expect(dependencyManager.InstallCall.Receives.CnbPath).To(Equal(cnbDir))
Expect(dependencyManager.InstallCall.Receives.LayerPath).To(Equal(filepath.Join(layersDir, "bundler")))
Expect(dependencyManager.DeliverCall.Receives.CnbPath).To(Equal(cnbDir))
Expect(dependencyManager.DeliverCall.Receives.LayerPath).To(Equal(filepath.Join(layersDir, "bundler")))
Expect(dependencyManager.DeliverCall.Receives.PlatformPath).To(Equal("platform"))

Expect(versionShimmer.ShimCall.Receives.Path).To(Equal(filepath.Join(layersDir, "bundler", "bin")))
Expect(versionShimmer.ShimCall.Receives.Version).To(Equal("1.17.x"))
Expand Down Expand Up @@ -696,7 +703,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {

context("when a dependency cannot be installed", func() {
it.Before(func() {
dependencyManager.InstallCall.Returns.Error = errors.New("failed to install dependency")
dependencyManager.DeliverCall.Returns.Error = errors.New("failed to install dependency")
})

it("returns an error", func() {
Expand Down
2 changes: 1 addition & 1 deletion detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"
"path/filepath"

"github.com/paketo-buildpacks/packit"
"github.com/paketo-buildpacks/packit/v2"
)

//go:generate faux --interface VersionParser --output fakes/version_parser.go
Expand Down
2 changes: 1 addition & 1 deletion detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/paketo-buildpacks/bundler"
"github.com/paketo-buildpacks/bundler/fakes"
"github.com/paketo-buildpacks/packit"
"github.com/paketo-buildpacks/packit/v2"
"github.com/sclevine/spec"

. "github.com/onsi/gomega"
Expand Down
50 changes: 26 additions & 24 deletions fakes/dependency_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,35 @@ package fakes
import (
"sync"

"github.com/paketo-buildpacks/packit"
"github.com/paketo-buildpacks/packit/postal"
packit "github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/postal"
)

type DependencyManager struct {
GenerateBillOfMaterialsCall struct {
DeliverCall struct {
mutex sync.Mutex
CallCount int
Receives struct {
Dependencies []postal.Dependency
Dependency postal.Dependency
CnbPath string
LayerPath string
PlatformPath string
}
Returns struct {
BOMEntrySlice []packit.BOMEntry
Error error
}
Stub func(...postal.Dependency) []packit.BOMEntry
Stub func(postal.Dependency, string, string, string) error
}
InstallCall struct {
GenerateBillOfMaterialsCall struct {
mutex sync.Mutex
CallCount int
Receives struct {
Dependency postal.Dependency
CnbPath string
LayerPath string
Dependencies []postal.Dependency
}
Returns struct {
Error error
BOMEntrySlice []packit.BOMEntry
}
Stub func(postal.Dependency, string, string) error
Stub func(...postal.Dependency) []packit.BOMEntry
}
ResolveCall struct {
mutex sync.Mutex
Expand All @@ -49,6 +50,19 @@ type DependencyManager struct {
}
}

func (f *DependencyManager) Deliver(param1 postal.Dependency, param2 string, param3 string, param4 string) error {
f.DeliverCall.mutex.Lock()
defer f.DeliverCall.mutex.Unlock()
f.DeliverCall.CallCount++
f.DeliverCall.Receives.Dependency = param1
f.DeliverCall.Receives.CnbPath = param2
f.DeliverCall.Receives.LayerPath = param3
f.DeliverCall.Receives.PlatformPath = param4
if f.DeliverCall.Stub != nil {
return f.DeliverCall.Stub(param1, param2, param3, param4)
}
return f.DeliverCall.Returns.Error
}
func (f *DependencyManager) GenerateBillOfMaterials(param1 ...postal.Dependency) []packit.BOMEntry {
f.GenerateBillOfMaterialsCall.mutex.Lock()
defer f.GenerateBillOfMaterialsCall.mutex.Unlock()
Expand All @@ -59,18 +73,6 @@ func (f *DependencyManager) GenerateBillOfMaterials(param1 ...postal.Dependency)
}
return f.GenerateBillOfMaterialsCall.Returns.BOMEntrySlice
}
func (f *DependencyManager) Install(param1 postal.Dependency, param2 string, param3 string) error {
f.InstallCall.mutex.Lock()
defer f.InstallCall.mutex.Unlock()
f.InstallCall.CallCount++
f.InstallCall.Receives.Dependency = param1
f.InstallCall.Receives.CnbPath = param2
f.InstallCall.Receives.LayerPath = param3
if f.InstallCall.Stub != nil {
return f.InstallCall.Stub(param1, param2, param3)
}
return f.InstallCall.Returns.Error
}
func (f *DependencyManager) Resolve(param1 string, param2 string, param3 string, param4 string) (postal.Dependency, error) {
f.ResolveCall.mutex.Lock()
defer f.ResolveCall.mutex.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion fakes/entry_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fakes
import (
"sync"

"github.com/paketo-buildpacks/packit"
packit "github.com/paketo-buildpacks/packit/v2"
)

type EntryResolver struct {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require (
github.com/Masterminds/semver v1.5.0
github.com/onsi/gomega v1.18.1
github.com/paketo-buildpacks/occam v0.3.0
github.com/paketo-buildpacks/packit v1.3.1
github.com/paketo-buildpacks/packit/v2 v2.0.3
github.com/sclevine/spec v1.4.0
gopkg.in/yaml.v2 v2.4.0
)
Expand Down
Loading

0 comments on commit 905bc34

Please sign in to comment.