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

Bump packit to v2. #238

Merged
merged 1 commit into from
Mar 17, 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
12 changes: 6 additions & 6 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"strings"
"time"

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

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

Expand Down Expand Up @@ -118,7 +118,7 @@ func Build(installProcess InstallProcess, entries EntryResolver, dependencies De
logs.Subprocess(fmt.Sprintf("Installing Pip %s", dependency.Version))

duration, err := clock.Measure(func() error {
err = dependencies.Install(dependency, context.CNBPath, pipSrcDir)
err = dependencies.Deliver(dependency, context.CNBPath, pipSrcDir, context.Platform.Path)
if err != nil {
return err
}
Expand Down
70 changes: 38 additions & 32 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import (
"testing"
"time"

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

//nolint Ignore SA1019, informed usage of deprecated package
"github.com/paketo-buildpacks/packit/v2/paketosbom"
"github.com/paketo-buildpacks/packit/v2/postal"
"github.com/paketo-buildpacks/packit/v2/scribe"
pip "github.com/paketo-buildpacks/pip"
"github.com/paketo-buildpacks/pip/fakes"
"github.com/sclevine/spec"
Expand Down Expand Up @@ -83,9 +86,9 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
dependencyManager.GenerateBillOfMaterialsCall.Returns.BOMEntrySlice = []packit.BOMEntry{
{
Name: "pip",
Metadata: packit.BOMMetadata{
Checksum: packit.BOMChecksum{
Algorithm: packit.SHA256,
Metadata: paketosbom.BOMMetadata{
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "pip-dependency-sha",
},
URI: "pip-dependency-uri",
Expand Down Expand Up @@ -136,8 +139,9 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
},
},
},
Layers: packit.Layers{Path: layersDir},
Stack: "some-stack",
Platform: packit.Platform{Path: "platform"},
Layers: packit.Layers{Path: layersDir},
Stack: "some-stack",
})
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -166,9 +170,9 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
BOM: []packit.BOMEntry{
{
Name: "pip",
Metadata: packit.BOMMetadata{
Checksum: packit.BOMChecksum{
Algorithm: packit.SHA256,
Metadata: paketosbom.BOMMetadata{
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "pip-dependency-sha",
},
URI: "pip-dependency-uri",
Expand All @@ -181,9 +185,9 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
BOM: []packit.BOMEntry{
{
Name: "pip",
Metadata: packit.BOMMetadata{
Checksum: packit.BOMChecksum{
Algorithm: packit.SHA256,
Metadata: paketosbom.BOMMetadata{
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "pip-dependency-sha",
},
URI: "pip-dependency-uri",
Expand Down Expand Up @@ -217,7 +221,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
Expect(dependencyManager.ResolveCall.Receives.Version).To(Equal(""))
Expect(dependencyManager.ResolveCall.Receives.Stack).To(Equal("some-stack"))

Expect(dependencyManager.InstallCall.Receives.Dependency).To(Equal(postal.Dependency{
Expect(dependencyManager.DeliverCall.Receives.Dependency).To(Equal(postal.Dependency{
ID: "pip",
Name: "Pip",
SHA256: "some-sha",
Expand All @@ -226,10 +230,11 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
Version: "21.0",
}))

Expect(dependencyManager.InstallCall.Receives.CnbPath).To(Equal(cnbDir))
Expect(dependencyManager.InstallCall.Receives.DestPath).To(ContainSubstring("pip-source"))
Expect(dependencyManager.DeliverCall.Receives.CnbPath).To(Equal(cnbDir))
Expect(dependencyManager.DeliverCall.Receives.DestinationPath).To(ContainSubstring("pip-source"))
Expect(dependencyManager.DeliverCall.Receives.PlatformPath).To(Equal("platform"))

Expect(installProcess.ExecuteCall.Receives.SrcPath).To(Equal(dependencyManager.InstallCall.Receives.DestPath))
Expect(installProcess.ExecuteCall.Receives.SrcPath).To(Equal(dependencyManager.DeliverCall.Receives.DestinationPath))
Expect(installProcess.ExecuteCall.Receives.TargetLayerPath).To(Equal(filepath.Join(layersDir, "pip")))

Expect(buffer.String()).To(ContainSubstring("Some Buildpack some-version"))
Expand Down Expand Up @@ -262,8 +267,9 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
},
},
},
Layers: packit.Layers{Path: layersDir},
Stack: "some-stack",
Platform: packit.Platform{Path: "platform"},
Layers: packit.Layers{Path: layersDir},
Stack: "some-stack",
})
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -292,9 +298,9 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
BOM: []packit.BOMEntry{
{
Name: "pip",
Metadata: packit.BOMMetadata{
Checksum: packit.BOMChecksum{
Algorithm: packit.SHA256,
Metadata: paketosbom.BOMMetadata{
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "pip-dependency-sha",
},
URI: "pip-dependency-uri",
Expand All @@ -307,9 +313,9 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
BOM: []packit.BOMEntry{
{
Name: "pip",
Metadata: packit.BOMMetadata{
Checksum: packit.BOMChecksum{
Algorithm: packit.SHA256,
Metadata: paketosbom.BOMMetadata{
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "pip-dependency-sha",
},
URI: "pip-dependency-uri",
Expand Down Expand Up @@ -438,9 +444,9 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
BOM: []packit.BOMEntry{
{
Name: "pip",
Metadata: packit.BOMMetadata{
Checksum: packit.BOMChecksum{
Algorithm: packit.SHA256,
Metadata: paketosbom.BOMMetadata{
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "pip-dependency-sha",
},
URI: "pip-dependency-uri",
Expand All @@ -454,7 +460,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
Expect(buffer.String()).ToNot(ContainSubstring("Executing build process"))
Expect(buffer.String()).To(ContainSubstring("Reusing cached layer"))

Expect(dependencyManager.InstallCall.CallCount).To(Equal(0))
Expect(dependencyManager.DeliverCall.CallCount).To(Equal(0))
Expect(installProcess.ExecuteCall.CallCount).To(Equal(0))
})
})
Expand Down Expand Up @@ -551,7 +557,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {

context("when 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() {
_, err := build(packit.BuildContext{
Expand Down
2 changes: 1 addition & 1 deletion detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pip
import (
"os"

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

// BuildPlanMetadata is the buildpack specific data included in build plan
Expand Down
2 changes: 1 addition & 1 deletion detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"
"testing"

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

Expand Down
64 changes: 33 additions & 31 deletions fakes/dependency_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,38 @@ 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 {
sync.Mutex
DeliverCall struct {
mutex sync.Mutex
CallCount int
Receives struct {
Dependencies []postal.Dependency
Dependency postal.Dependency
CnbPath string
DestinationPath 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 {
sync.Mutex
GenerateBillOfMaterialsCall struct {
mutex sync.Mutex
CallCount int
Receives struct {
Dependency postal.Dependency
CnbPath string
DestPath 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 {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
Path string
Expand All @@ -49,31 +50,32 @@ 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.DestinationPath = 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.Lock()
defer f.GenerateBillOfMaterialsCall.Unlock()
f.GenerateBillOfMaterialsCall.mutex.Lock()
defer f.GenerateBillOfMaterialsCall.mutex.Unlock()
f.GenerateBillOfMaterialsCall.CallCount++
f.GenerateBillOfMaterialsCall.Receives.Dependencies = param1
if f.GenerateBillOfMaterialsCall.Stub != nil {
return f.GenerateBillOfMaterialsCall.Stub(param1...)
}
return f.GenerateBillOfMaterialsCall.Returns.BOMEntrySlice
}
func (f *DependencyManager) Install(param1 postal.Dependency, param2 string, param3 string) error {
f.InstallCall.Lock()
defer f.InstallCall.Unlock()
f.InstallCall.CallCount++
f.InstallCall.Receives.Dependency = param1
f.InstallCall.Receives.CnbPath = param2
f.InstallCall.Receives.DestPath = 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.Lock()
defer f.ResolveCall.Unlock()
f.ResolveCall.mutex.Lock()
defer f.ResolveCall.mutex.Unlock()
f.ResolveCall.CallCount++
f.ResolveCall.Receives.Path = param1
f.ResolveCall.Receives.Id = param2
Expand Down
14 changes: 7 additions & 7 deletions fakes/entry_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package fakes
import (
"sync"

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

type EntryResolver struct {
MergeLayerTypesCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
String string
Expand All @@ -21,7 +21,7 @@ type EntryResolver struct {
Stub func(string, []packit.BuildpackPlanEntry) (bool, bool)
}
ResolveCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
String string
Expand All @@ -39,8 +39,8 @@ type EntryResolver struct {
}

func (f *EntryResolver) MergeLayerTypes(param1 string, param2 []packit.BuildpackPlanEntry) (bool, bool) {
f.MergeLayerTypesCall.Lock()
defer f.MergeLayerTypesCall.Unlock()
f.MergeLayerTypesCall.mutex.Lock()
defer f.MergeLayerTypesCall.mutex.Unlock()
f.MergeLayerTypesCall.CallCount++
f.MergeLayerTypesCall.Receives.String = param1
f.MergeLayerTypesCall.Receives.BuildpackPlanEntrySlice = param2
Expand All @@ -51,8 +51,8 @@ func (f *EntryResolver) MergeLayerTypes(param1 string, param2 []packit.Buildpack
}
func (f *EntryResolver) Resolve(param1 string, param2 []packit.BuildpackPlanEntry, param3 []interface {
}) (packit.BuildpackPlanEntry, []packit.BuildpackPlanEntry) {
f.ResolveCall.Lock()
defer f.ResolveCall.Unlock()
f.ResolveCall.mutex.Lock()
defer f.ResolveCall.mutex.Unlock()
f.ResolveCall.CallCount++
f.ResolveCall.Receives.String = param1
f.ResolveCall.Receives.BuildpackPlanEntrySlice = param2
Expand Down
8 changes: 4 additions & 4 deletions fakes/executable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package fakes
import (
"sync"

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

type Executable struct {
ExecuteCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
Execution pexec.Execution
Expand All @@ -21,8 +21,8 @@ type Executable struct {
}

func (f *Executable) Execute(param1 pexec.Execution) error {
f.ExecuteCall.Lock()
defer f.ExecuteCall.Unlock()
f.ExecuteCall.mutex.Lock()
defer f.ExecuteCall.mutex.Unlock()
f.ExecuteCall.CallCount++
f.ExecuteCall.Receives.Execution = param1
if f.ExecuteCall.Stub != nil {
Expand Down
Loading