Skip to content

Commit

Permalink
fixup; backwards compat
Browse files Browse the repository at this point in the history
  • Loading branch information
menehune23 committed Sep 24, 2021
1 parent cb730d7 commit 623e6c7
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 332 deletions.
16 changes: 9 additions & 7 deletions postal/fakes/mapping_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@ import "sync"

type MappingResolver struct {
FindDependencyMappingCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
SHA256 string
SHA256 string
PlatformDir string
}
Returns struct {
String string
Error error
}
Stub func(string) (string, error)
Stub func(string, string) (string, error)
}
}

func (f *MappingResolver) FindDependencyMapping(param1 string) (string, error) {
f.FindDependencyMappingCall.Lock()
defer f.FindDependencyMappingCall.Unlock()
func (f *MappingResolver) FindDependencyMapping(param1 string, param2 string) (string, error) {
f.FindDependencyMappingCall.mutex.Lock()
defer f.FindDependencyMappingCall.mutex.Unlock()
f.FindDependencyMappingCall.CallCount++
f.FindDependencyMappingCall.Receives.SHA256 = param1
f.FindDependencyMappingCall.Receives.PlatformDir = param2
if f.FindDependencyMappingCall.Stub != nil {
return f.FindDependencyMappingCall.Stub(param1)
return f.FindDependencyMappingCall.Stub(param1, param2)
}
return f.FindDependencyMappingCall.Returns.String, f.FindDependencyMappingCall.Returns.Error
}
8 changes: 4 additions & 4 deletions postal/internal/dependency_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

//go:generate faux --interface BindingResolver --output fakes/binding_resolver.go
type BindingResolver interface {
Resolve(typ string, provider string) ([]servicebindings.Binding, error)
Resolve(typ string, provider string, platformDir string) ([]servicebindings.Binding, error)
}

type DependencyMappingResolver struct {
Expand All @@ -20,9 +20,9 @@ func NewDependencyMappingResolver(bindingResolver BindingResolver) DependencyMap
}
}

// FindDependencyMapping looks up if there is a matching dependency mapping at the given binding path
func (d DependencyMappingResolver) FindDependencyMapping(sha256 string) (string, error) {
bindings, err := d.bindingResolver.Resolve("dependency-mapping", "")
// FindDependencyMapping looks up if there is a matching dependency mapping
func (d DependencyMappingResolver) FindDependencyMapping(sha256 string, platformDir string) (string, error) {
bindings, err := d.bindingResolver.Resolve("dependency-mapping", "", platformDir)
if err != nil {
return "", fmt.Errorf("failed to resolve 'dependency-mapping' binding: %w", err)
}
Expand Down
7 changes: 5 additions & 2 deletions postal/internal/dependency_mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,18 @@ func testDependencyMappings(t *testing.T, context spec.G, it spec.S) {

context("given a set of bindings and a dependency", func() {
it("finds a matching dependency mappings in the platform bindings if there is one", func() {
boundDependency, err := resolver.FindDependencyMapping("some-sha")
boundDependency, err := resolver.FindDependencyMapping("some-sha", "some-platform-dir")
Expect(err).ToNot(HaveOccurred())
Expect(bindingResolver.ResolveCall.Receives.Typ).To(Equal("dependency-mapping"))
Expect(bindingResolver.ResolveCall.Receives.Provider).To(BeEmpty())
Expect(bindingResolver.ResolveCall.Receives.PlatformDir).To(Equal("some-platform-dir"))
Expect(boundDependency).To(Equal("dependency-mapping-entry.tgz"))
})
})

context("given a set of bindings and a dependency", func() {
it("returns an empty DependencyMapping if there is no match", func() {
boundDependency, err := resolver.FindDependencyMapping("unmatched-sha")
boundDependency, err := resolver.FindDependencyMapping("unmatched-sha", "")
Expect(err).ToNot(HaveOccurred())
Expect(boundDependency).To(Equal(""))
})
Expand Down
18 changes: 10 additions & 8 deletions postal/internal/fakes/binding_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,30 @@ import (

type BindingResolver struct {
ResolveCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
Typ string
Provider string
Typ string
Provider string
PlatformDir string
}
Returns struct {
BindingSlice []servicebindings.Binding
Error error
}
Stub func(string, string) ([]servicebindings.Binding, error)
Stub func(string, string, string) ([]servicebindings.Binding, error)
}
}

func (f *BindingResolver) Resolve(param1 string, param2 string) ([]servicebindings.Binding, error) {
f.ResolveCall.Lock()
defer f.ResolveCall.Unlock()
func (f *BindingResolver) Resolve(param1 string, param2 string, param3 string) ([]servicebindings.Binding, error) {
f.ResolveCall.mutex.Lock()
defer f.ResolveCall.mutex.Unlock()
f.ResolveCall.CallCount++
f.ResolveCall.Receives.Typ = param1
f.ResolveCall.Receives.Provider = param2
f.ResolveCall.Receives.PlatformDir = param3
if f.ResolveCall.Stub != nil {
return f.ResolveCall.Stub(param1, param2)
return f.ResolveCall.Stub(param1, param2, param3)
}
return f.ResolveCall.Returns.BindingSlice, f.ResolveCall.Returns.Error
}
19 changes: 6 additions & 13 deletions postal/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Transport interface {
// MappingResolver serves as the interface that looks up platform binding provided
// dependency mappings given a SHA256
type MappingResolver interface {
FindDependencyMapping(SHA256 string) (string, error)
FindDependencyMapping(SHA256 string, platformDir string) (string, error)
}

// Service provides a mechanism for resolving and installing dependencies given
Expand All @@ -40,12 +40,12 @@ type Service struct {
mappingResolver MappingResolver
}

// NewService creates an instance of a Servicel given a Transport.
func NewService(transport Transport, platformDir string) Service {
// NewService creates an instance of a Service given a Transport.
func NewService(transport Transport) Service {
return Service{
transport: transport,
mappingResolver: internal.NewDependencyMappingResolver(
servicebindings.NewResolver(platformDir),
servicebindings.NewResolver(),
),
}
}
Expand Down Expand Up @@ -143,8 +143,8 @@ func (s Service) Resolve(path, id, version, stack string) (Dependency, error) {
// the given dependency mapping URI to fetch the dependency. The dependency is
// validated against the checksum value provided on the Dependency and will
// error if there are inconsistencies in the fetched result.
func (s Service) Deliver(dependency Dependency, cnbPath, layerPath string) error {
dependencyMappingURI, err := s.mappingResolver.FindDependencyMapping(dependency.SHA256)
func (s Service) Deliver(dependency Dependency, cnbPath, layerPath, platformPath string) error {
dependencyMappingURI, err := s.mappingResolver.FindDependencyMapping(dependency.SHA256, platformPath)
if err != nil {
return fmt.Errorf("failure checking for dependency mappings: %s", err)
}
Expand Down Expand Up @@ -179,13 +179,6 @@ func (s Service) Deliver(dependency Dependency, cnbPath, layerPath string) error
return nil
}

// Install will invoke Deliver.
//
// Deprecated: Use Deliver instead.
func (s Service) Install(dependency Dependency, cnbPath, layerPath string) error {
return s.Deliver(dependency, cnbPath, layerPath)
}

// GenerateBillOfMaterials will generate a list of BOMEntry values given a
// collection of Dependency values.
func (s Service) GenerateBillOfMaterials(dependencies ...Dependency) []packit.BOMEntry {
Expand Down
Loading

0 comments on commit 623e6c7

Please sign in to comment.