Skip to content

Commit

Permalink
Merge pull request #121 from jakesmolka/fix-env-var-honoring
Browse files Browse the repository at this point in the history
Fix BPL_JPROFILER_ENABLED BP_JPROFILER_ENABLED, now reading it as pro…
  • Loading branch information
dmikusa authored Oct 25, 2024
2 parents da6db41 + 73ab620 commit 93a6394
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion helper/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ import (
"strings"

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

type Properties struct {
Logger bard.Logger
}

func (p Properties) Execute() (map[string]string, error) {
if _, ok := os.LookupEnv("BPL_JPROFILER_ENABLED"); !ok {

if isEnabled := sherpa.ResolveBool("BPL_JPROFILER_ENABLED"); !isEnabled {
return nil, nil
}

Expand Down
8 changes: 7 additions & 1 deletion helper/properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ func testProperties(t *testing.T, context spec.G, it spec.S) {
Expect(p.Execute()).To(BeNil())
})

it("returns nil if $BPL_JPROFILER_ENABLED is false", func() {
Expect(os.Setenv("BPL_JPROFILER_ENABLED", "false")).To(Succeed())
Expect(p.Execute()).To(BeNil())
Expect(os.Unsetenv("BPL_JPROFILER_ENABLED")).To(Succeed())
})

context("$BPL_JPROFILER_ENABLED", func() {
it.Before(func() {
Expect(os.Setenv("BPL_JPROFILER_ENABLED", "")).To(Succeed())
Expect(os.Setenv("BPL_JPROFILER_ENABLED", "true")).To(Succeed())
})

it.After(func() {
Expand Down
2 changes: 1 addition & 1 deletion jprofiler/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (Detect) Detect(context libcnb.DetectContext) (libcnb.DetectResult, error)
return libcnb.DetectResult{}, fmt.Errorf("unable to create configuration resolver\n%w", err)
}

if _, ok := cr.Resolve("BP_JPROFILER_ENABLED"); !ok {
if isEnabled := cr.ResolveBool("BP_JPROFILER_ENABLED"); !isEnabled {
return libcnb.DetectResult{Pass: false}, nil
}

Expand Down
5 changes: 5 additions & 0 deletions jprofiler/detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
Expect(detect.Detect(ctx)).To(Equal(libcnb.DetectResult{Pass: false}))
})

it("fails with BP_JPROFILER_ENABLED set to false", func() {
Expect(os.Setenv("BP_JPROFILER_ENABLED", "false")).To(Succeed())
Expect(detect.Detect(ctx)).To(Equal(libcnb.DetectResult{Pass: false}))
})

context("$BP_JPROFILER_ENABLED", func() {
it.Before(func() {
Expect(os.Setenv("BP_JPROFILER_ENABLED", "true")).To(Succeed())
Expand Down

0 comments on commit 93a6394

Please sign in to comment.