Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
Upgrade Go dependencies - fix nil PlanEntry
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Eltgroth <[email protected]>
  • Loading branch information
joeeltgroth committed Aug 18, 2023
1 parent 37ff789 commit b9dd7ed
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 0 deletions.
4 changes: 4 additions & 0 deletions buildpacks/java/java/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) {

functionClass, isOverride := cr.Resolve("BP_FUNCTION")

if e.Metadata["func_yaml_envs"] == nil {
e.Metadata["func_yaml_envs"] = map[string]any{}
}

functionLayer := NewFunction(context.Application.Path,
WithLogger(b.Logger),
WithFunctionClass(functionClass, isOverride),
Expand Down
69 changes: 69 additions & 0 deletions buildpacks/java/tests/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,47 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {

})

when("always but nil plan entry", func() {
it.Before(func() {
var (
appDir string
err error
)

appDir, cleanupAppDir = tests.SetupTestDirectory(
tests.WithFuncYaml(),
)

context = makeBuildContextWithNilPlanEntry(
withBuildApplicationPath(appDir),
withDependencies([]map[string]any{
{"id": "invoker", "version": "2.3.4"},
}),
withOptions(map[string]any{
"some-other-option": "some-other-value",
"some-option": "some-value",
}),
)

result, err = build.Build(context)
Expect(err).NotTo(HaveOccurred())
})

it("adds launch command", func() {
Expect(result.Processes).To(Equal([]libcnb.Process{
{
Type: "func",
Command: "java",
Arguments: []string{"org.springframework.boot.loader.JarLauncher"},
Direct: false,
WorkingDirectory: "",
Default: true,
},
}))
})

})

when("without tomcat", func() {

it.Before(func() {
Expand Down Expand Up @@ -202,6 +243,34 @@ func makeBuildContext(opts ...func(*libcnb.BuildContext)) libcnb.BuildContext {
return ctx
}

func makeBuildContextWithNilPlanEntry(opts ...func(*libcnb.BuildContext)) libcnb.BuildContext {
ctx := libcnb.BuildContext{
Application: libcnb.Application{},
Buildpack: libcnb.Buildpack{
Metadata: map[string]any{},
},
Platform: libcnb.Platform{
Environment: map[string]string{},
},
Plan: libcnb.BuildpackPlan{
Entries: []libcnb.BuildpackPlanEntry{
{
Name: "java-function",
Metadata: map[string]any{
"func_yaml_envs": nil,
},
},
},
},
}

for _, opt := range opts {
opt(&ctx)
}

return ctx
}

func withBuildApplicationPath(path string) func(*libcnb.BuildContext) {
return func(bc *libcnb.BuildContext) {
bc.Application.Path = path
Expand Down
4 changes: 4 additions & 0 deletions buildpacks/python/python/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) {
return result, nil
}

if functionPlan.Metadata["func_yaml_envs"] == nil {
functionPlan.Metadata["func_yaml_envs"] = map[string]any{}
}

functionLayer := NewFunction(
WithLogger(b.Logger),
WithFuncYamlEnvs(functionPlan.Metadata["func_yaml_envs"].(map[string]any)),
Expand Down
72 changes: 72 additions & 0 deletions buildpacks/python/tests/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,50 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
})
})

when("nil plan entry", func() {
it.Before(func() {
var (
appDir string
err error
)

t.Setenv("BP_FUNCTION", "some_module.some_function")

appDir, cleanupAppDir = tests.SetupTestDirectory(
tests.WithFuncYaml(),
WithFunctionFile("some_module", "some_function", HTTPFuncTemplate),
)

context = makeBuildContextWithNilPlanEntry(
withBuildApplicationPath(appDir),
withDependencies([]map[string]any{
{"id": "invoker-deps", "version": "1.2.3"},
{"id": "invoker", "version": "2.3.4"},
}),
withOptions(map[string]any{
"some-option": "some-value",
"some-other-option": "some-other-value",
}),
)

result, err = build.Build(context)
Expect(err).NotTo(HaveOccurred())
})

it("adds launch command", func() {
Expect(result.Processes).To(Equal([]libcnb.Process{
{
Type: "func",
Command: "python",
Arguments: []string{"-m", "pyfunc", "start", "-m", "some_module", "-f", "some_function"},
Direct: false,
WorkingDirectory: "",
Default: true,
},
}))
})
})

when("BP_FUNCTION is invalid", func() {
it.Before(func() {
var (
Expand Down Expand Up @@ -160,6 +204,34 @@ func makeBuildContext(opts ...func(*libcnb.BuildContext)) libcnb.BuildContext {
return ctx
}

func makeBuildContextWithNilPlanEntry(opts ...func(*libcnb.BuildContext)) libcnb.BuildContext {
ctx := libcnb.BuildContext{
Application: libcnb.Application{},
Buildpack: libcnb.Buildpack{
Metadata: map[string]any{},
},
Platform: libcnb.Platform{
Environment: map[string]string{},
},
Plan: libcnb.BuildpackPlan{
Entries: []libcnb.BuildpackPlanEntry{
{
Name: "python-function",
Metadata: map[string]any{
"func_yaml_envs": nil,
},
},
},
},
}

for _, opt := range opts {
opt(&ctx)
}

return ctx
}

func withBuildApplicationPath(path string) func(*libcnb.BuildContext) {
return func(bc *libcnb.BuildContext) {
bc.Application.Path = path
Expand Down

0 comments on commit b9dd7ed

Please sign in to comment.