Skip to content

Commit

Permalink
fixup; rename package, secret reader
Browse files Browse the repository at this point in the history
  • Loading branch information
menehune23 committed Sep 21, 2021
1 parent a423807 commit 2110375
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 186 deletions.
15 changes: 0 additions & 15 deletions bindings/init_test.go

This file was deleted.

10 changes: 5 additions & 5 deletions postal/internal/dependency_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package internal
import (
"github.com/pkg/errors"

"github.com/paketo-buildpacks/packit/bindings"
"github.com/paketo-buildpacks/packit/servicebindings"
)

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

type DependencyMappingResolver struct {
Expand All @@ -23,13 +23,13 @@ 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) {
binds, err := d.bindingResolver.Resolve("dependency-mapping", "")
bindings, err := d.bindingResolver.Resolve("dependency-mapping", "")
if err != nil {
return "", errors.Wrap(err, "getting dependency-mapping binding")
}

for _, bind := range binds {
if uri, ok := bind.Secret[sha256]; ok {
for _, binding := range bindings {
if uri, ok := binding.Entries[sha256]; ok {
return uri.String(), nil
}
}
Expand Down
16 changes: 8 additions & 8 deletions postal/internal/dependency_mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"os"
"testing"

"github.com/paketo-buildpacks/packit/bindings"
"github.com/paketo-buildpacks/packit/postal/internal"
"github.com/paketo-buildpacks/packit/postal/internal/fakes"
"github.com/paketo-buildpacks/packit/servicebindings"
"github.com/sclevine/spec"

. "github.com/onsi/gomega"
Expand All @@ -33,29 +33,29 @@ func testDependencyMappings(t *testing.T, context spec.G, it spec.S) {

context("FindDependencyMapping", func() {
it.Before(func() {
bindingResolver.ResolveCall.Returns.BindingSlice = []bindings.Binding{
bindingResolver.ResolveCall.Returns.BindingSlice = []servicebindings.Binding{
{
Name: "some-binding",
Path: "some-path",
Type: "dependency-mapping",
Secret: map[string]bindings.SecretReader{
"some-sha": bindings.MakeSecretReader([]byte("dependency-mapping-entry.tgz")),
Entries: map[string]servicebindings.Entry{
"some-sha": servicebindings.MakeEntry([]byte("dependency-mapping-entry.tgz")),
},
},
{
Name: "other-binding",
Path: "other-path",
Type: "dependency-mapping",
Secret: map[string]bindings.SecretReader{
"other-sha": bindings.MakeSecretReader([]byte("dependency-mapping-entry.tgz")),
Entries: map[string]servicebindings.Entry{
"other-sha": servicebindings.MakeEntry([]byte("dependency-mapping-entry.tgz")),
},
},
{
Name: "another-binding",
Path: "another-path",
Type: "another type",
Secret: map[string]bindings.SecretReader{
"some-sha": bindings.MakeSecretReader([]byte("entry.tgz")),
Entries: map[string]servicebindings.Entry{
"some-sha": servicebindings.MakeEntry([]byte("entry.tgz")),
},
},
}
Expand Down
8 changes: 4 additions & 4 deletions postal/internal/fakes/binding_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/bindings"
"github.com/paketo-buildpacks/packit/servicebindings"
)

type BindingResolver struct {
Expand All @@ -15,14 +15,14 @@ type BindingResolver struct {
Provider string
}
Returns struct {
BindingSlice []bindings.Binding
BindingSlice []servicebindings.Binding
Error error
}
Stub func(string, string) ([]bindings.Binding, error)
Stub func(string, string) ([]servicebindings.Binding, error)
}
}

func (f *BindingResolver) Resolve(param1 string, param2 string) ([]bindings.Binding, error) {
func (f *BindingResolver) Resolve(param1 string, param2 string) ([]servicebindings.Binding, error) {
f.ResolveCall.Lock()
defer f.ResolveCall.Unlock()
f.ResolveCall.CallCount++
Expand Down
4 changes: 2 additions & 2 deletions postal/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"github.com/Masterminds/semver/v3"

"github.com/paketo-buildpacks/packit"
"github.com/paketo-buildpacks/packit/bindings"
"github.com/paketo-buildpacks/packit/cargo"
"github.com/paketo-buildpacks/packit/postal/internal"
"github.com/paketo-buildpacks/packit/servicebindings"
"github.com/paketo-buildpacks/packit/vacation"
)

Expand Down Expand Up @@ -45,7 +45,7 @@ func NewService(transport Transport, platformDir string) Service {
return Service{
transport: transport,
mappingResolver: internal.NewDependencyMappingResolver(
bindings.NewResolver(platformDir),
servicebindings.NewResolver(platformDir),
),
}
}
Expand Down
31 changes: 31 additions & 0 deletions servicebindings/entry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package servicebindings

import "bytes"

// Entry represents the read-only content of a binding entry.
type Entry struct {
data *bytes.Buffer
}

// MakeEntry returns an Entry from the given content.
func MakeEntry(data []byte) Entry {
return Entry{
data: bytes.NewBuffer(data),
}
}

// Bytes returns the raw content of the entry.
func (e Entry) Bytes() []byte {
return e.data.Bytes()
}

// String returns the content of the entry as a string.
func (e Entry) String() string {
return e.data.String()
}

// Read reads the next len(p) bytes from the entry or until the entry is drained. The return value n is the number of
// bytes read. If the entry has no data to return, err is io.EOF (unless len(p) is zero); otherwise it is nil.
func (e Entry) Read(p []byte) (int, error) {
return e.data.Read(p)
}
12 changes: 6 additions & 6 deletions bindings/secret_reader_test.go → servicebindings/entry_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package bindings_test
package servicebindings_test

import (
"io/ioutil"
"testing"

"github.com/paketo-buildpacks/packit/bindings"
"github.com/paketo-buildpacks/packit/servicebindings"
"github.com/sclevine/spec"

. "github.com/onsi/gomega"
)

func testSecretReader(t *testing.T, context spec.G, it spec.S) {
func testEntry(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
reader = bindings.MakeSecretReader([]byte("some data"))
reader = servicebindings.MakeEntry([]byte("some data"))
)

it("adheres to io.Reader interface", func() {
Expand All @@ -23,13 +23,13 @@ func testSecretReader(t *testing.T, context spec.G, it spec.S) {
})

context("Bytes", func() {
it("returns raw bytes of secret", func() {
it("returns the raw bytes of the entry", func() {
Expect(reader.Bytes()).To(Equal([]byte("some data")))
})
})

context("String", func() {
it("returns the string value of the secret", func() {
it("returns the string value of the entry", func() {
Expect(reader.String()).To(Equal("some data"))
})
})
Expand Down
15 changes: 15 additions & 0 deletions servicebindings/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package servicebindings_test

import (
"testing"

"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
)

func TestUnitServiceBindings(t *testing.T) {
suite := spec.New("packit/servicebindings", spec.Report(report.Terminal{}))
suite("Resolver", testResolver)
suite("Entry", testEntry)
suite.Run(t)
}
Loading

0 comments on commit 2110375

Please sign in to comment.