Skip to content

Commit

Permalink
Merge pull request #85 from paketo-buildpacks/revert-81-bindings
Browse files Browse the repository at this point in the history
Revert "Add Logging of Bindings Information for better UX"
  • Loading branch information
pivotal-david-osullivan authored Sep 6, 2021
2 parents e01c381 + 8384ce1 commit d150e29
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 78 deletions.
34 changes: 0 additions & 34 deletions bindings/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@ package bindings

import (
"fmt"
"os"
"sort"
"strings"

"github.com/heroku/color"
"github.com/paketo-buildpacks/libpak/bard"

"github.com/buildpacks/libcnb"
)

Expand All @@ -50,46 +45,17 @@ func OfProvider(p string) Predicate {
// Resolve returns all bindings from binds that match every Predicate in predicates.
func Resolve(binds libcnb.Bindings, predicates ...Predicate) libcnb.Bindings {
var result libcnb.Bindings
logger := bard.NewLogger(os.Stdout)

// deep copy
for _, bind := range binds {
result = append(result, bind)
}

// filter on predicates
for _, p := range predicates {
result = filter(result, p)
}

LogBindings(result, logger)
return result
}

func LogBindings(bindings libcnb.Bindings, logger bard.Logger) {
f := color.New(color.Bold)

if len(bindings) > 0 {
logger.Header(f.Sprint("Bindings Identified:"))
} else {
logger.Header(f.Sprint("No Bindings Found"))
}

var s []string
for _, binding := range bindings {

for k := range binding.Secret {
s = append(s, k)
}
sort.Strings(s)

logger.Bodyf("Name: %s", binding.Name)
logger.Bodyf("Keys: %s", s)
s = nil
}

}

// ResolveOne returns a single binding from bindings that match every Predicate if present. If exactly one match is found
// ResolveOne returns the binding and true. If zero matches are found, ResolveOne returns an empty binding and false.
// An error is returned if multiple matches are found.
Expand Down
46 changes: 2 additions & 44 deletions bindings/resolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
package bindings_test

import (
"bytes"
"testing"

"github.com/paketo-buildpacks/libpak/bard"

"github.com/buildpacks/libcnb"
. "github.com/onsi/gomega"
"github.com/sclevine/spec"
Expand All @@ -32,9 +29,8 @@ import (
func testResolve(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
b *bytes.Buffer
logger bard.Logger
binds libcnb.Bindings

binds libcnb.Bindings
)

it.Before(func() {
Expand Down Expand Up @@ -167,42 +163,4 @@ func testResolve(t *testing.T, context spec.G, it spec.S) {
})
})
})

context("bindings are logged", func() {

it.Before(func() {
b = bytes.NewBuffer(nil)
logger = bard.NewLogger(b)
binds = []libcnb.Binding{
{
Name: "name1",
Type: "some-type",
Provider: "some-provider",
Secret: map[string]string{"my-key1": "my-sec1"},
},
{
Name: "name2",
Type: "some-type",
Provider: "some-provider",
Secret: map[string]string{"my-key2": "my-sec2"},
},
}
})

it("checks that binding info is logged", func() {

bindings.LogBindings(binds, logger)
Expect(b.String()).To(ContainSubstring("name1"))
Expect(b.String()).To(ContainSubstring("my-key1"))

Expect(b.String()).To(ContainSubstring("name2"))
Expect(b.String()).To(ContainSubstring("my-key2"))
})

it("checks that nothing is logged is no bindings found", func() {
binds = []libcnb.Binding{}
bindings.LogBindings(binds, logger)
Expect(b.String()).To(ContainSubstring("No Bindings Found"))
})
})
}

0 comments on commit d150e29

Please sign in to comment.