Skip to content

Commit

Permalink
Adds test for unparseable BP_NATIVE_IMAGE
Browse files Browse the repository at this point in the history
Fixes mistake from #61 and adds a test for the case where BP_NATIVE_IMAGE is not a parseable bool

Signed-off-by: Emily Casey <ecasey@vmware.com>
  • Loading branch information
ekcasey committed Mar 31, 2021
1 parent 625cdc3 commit 3f1df21
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 41 deletions.
4 changes: 2 additions & 2 deletions native/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ func (d Detect) Detect(context libcnb.DetectContext) (libcnb.DetectResult, error
}

if ok, err := d.nativeImageEnabled(cr); err != nil {
return libcnb.DetectResult{}, nil
return libcnb.DetectResult{}, err
} else if !ok {
// still participates if a downstream buildpack requires native-image-applications
return result, err
return result, nil
}

for i := range result.Plans {
Expand Down
145 changes: 106 additions & 39 deletions native/detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,58 +78,125 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
})

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

it.After(func() {
Expect(os.Unsetenv("BP_NATIVE_IMAGE")).To(Succeed())
})
it.After(func() {
Expect(os.Unsetenv("BP_NATIVE_IMAGE")).To(Succeed())
})

it("provides and requires native-image-application", func() {
Expect(detect.Detect(ctx)).To(Equal(libcnb.DetectResult{
Pass: true,
Plans: []libcnb.BuildPlan{
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
},
Requires: []libcnb.BuildPlanRequire{
{
Name: "native-image-builder",
it("provides and requires native-image-application", func() {
Expect(detect.Detect(ctx)).To(Equal(libcnb.DetectResult{
Pass: true,
Plans: []libcnb.BuildPlan{
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
},
{
Name: "jvm-application",
Metadata: map[string]interface{}{"native-image": true},
Requires: []libcnb.BuildPlanRequire{
{
Name: "native-image-builder",
},
{
Name: "jvm-application",
Metadata: map[string]interface{}{"native-image": true},
},
{
Name: "spring-boot",
Metadata: map[string]interface{}{"native-image": true},
},
{
Name: "native-image-application",
},
},
{
Name: "spring-boot",
Metadata: map[string]interface{}{"native-image": true},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
},
{
Name: "native-image-application",
Requires: []libcnb.BuildPlanRequire{
{
Name: "native-image-builder",
},
{
Name: "jvm-application",
Metadata: map[string]interface{}{"native-image": true},
},
{
Name: "native-image-application",
},
},
},
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
},
Requires: []libcnb.BuildPlanRequire{
{
Name: "native-image-builder",
}))
})
})

context("false", func() {
it.Before(func() {
Expect(os.Setenv("BP_NATIVE_IMAGE", "false")).To(Succeed())
})

it.After(func() {
Expect(os.Unsetenv("BP_NATIVE_IMAGE")).To(Succeed())
})

it("provides but does not requires native-image-application", func() {
Expect(detect.Detect(ctx)).To(Equal(libcnb.DetectResult{
Pass: true,
Plans: []libcnb.BuildPlan{
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
},
{
Name: "jvm-application",
Metadata: map[string]interface{}{"native-image": true},
Requires: []libcnb.BuildPlanRequire{
{
Name: "native-image-builder",
},
{
Name: "jvm-application",
Metadata: map[string]interface{}{"native-image": true},
},
{
Name: "spring-boot",
Metadata: map[string]interface{}{"native-image": true},
},
},
{
Name: "native-image-application",
},
{
Provides: []libcnb.BuildPlanProvide{
{Name: "native-image-application"},
},
Requires: []libcnb.BuildPlanRequire{
{
Name: "native-image-builder",
},
{
Name: "jvm-application",
Metadata: map[string]interface{}{"native-image": true},
},
},
},
},
},
}))
}))
})
})

context("not a bool", func() {
it.Before(func() {
Expect(os.Setenv("BP_NATIVE_IMAGE", "foo")).To(Succeed())
})

it.After(func() {
Expect(os.Unsetenv("BP_NATIVE_IMAGE")).To(Succeed())
})

it("errors", func() {
_, err := detect.Detect(ctx)
Expect(err).To(HaveOccurred())
})
})
})

Expand Down

0 comments on commit 3f1df21

Please sign in to comment.