Skip to content

Commit

Permalink
Fix binding handling when binding root doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
menehune23 authored and sophiewigmore committed Oct 12, 2021
1 parent d600cb5 commit fc612d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion servicebindings/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ func (r *Resolver) ResolveOne(typ, provider, platformDir string) (Binding, error

func loadBindings(bindingRoot string) ([]Binding, error) {
files, err := os.ReadDir(bindingRoot)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
} else if err != nil {
return nil, err
}

Expand Down
8 changes: 8 additions & 0 deletions servicebindings/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,14 @@ func testResolver(t *testing.T, context spec.G, it spec.S) {
_, err = resolver.Resolve("bad-type", "", "")
Expect(err).To(MatchError(HavePrefix("failed to load bindings from '%s': failed to read binding 'bad-binding': open %s: permission denied", bindingRoot, filepath.Join(bindingRoot, "bad-binding", "type"))))
})

it("returns empty list if binding root doesn't exist", func() {
Expect(os.RemoveAll(bindingRoot)).To(Succeed())

bindings, err := resolver.Resolve("type-1", "", "")
Expect(err).NotTo(HaveOccurred())
Expect(bindings).To(BeEmpty())
})
})

context("ResolveOne", func() {
Expand Down

0 comments on commit fc612d6

Please sign in to comment.