Skip to content

Commit

Permalink
fix: mocking get_etc-passwd_file_content function
Browse files Browse the repository at this point in the history
  • Loading branch information
pacostas committed Oct 23, 2023
1 parent b0200df commit 4b2d60c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
7 changes: 0 additions & 7 deletions fakes/get_etc_passwd_file_content.go

This file was deleted.

4 changes: 2 additions & 2 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ func NewDuringBuildPermissionsGetter(epfg EtcPasswdFileContentGetter) DuringBuil
return DuringBuildPermissionsGetter{get_etc_passwd_file_content: epfg}
}

func Generate(dependencyManager DependencyManager, logger scribe.Emitter, p DuringBuildPermissionsGetter) packit.GenerateFunc {
func Generate(dependencyManager DependencyManager, logger scribe.Emitter, duringBuildPermissionsGetter DuringBuildPermissionsGetter) packit.GenerateFunc {
return func(context packit.GenerateContext) (packit.GenerateResult, error) {
logger.Title("%s %s", context.Info.Name, context.Info.Version)
logger.Process("Resolving Node Engine version")

duringBuildPermissions, err := p.duringBuildPermissionsGetter()
duringBuildPermissions, err := duringBuildPermissionsGetter.duringBuildPermissionsGetter()
if err != nil {
return packit.GenerateResult{}, err
}
Expand Down
15 changes: 10 additions & 5 deletions generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/paketo-buildpacks/packit/cargo"
"github.com/paketo-buildpacks/packit/v2"
ubinodejsextension "github.com/paketo-community/ubi-nodejs-extension"
"github.com/paketo-community/ubi-nodejs-extension/fakes"
"github.com/sclevine/spec"

"github.com/paketo-buildpacks/packit/v2/scribe"
Expand All @@ -39,6 +38,12 @@ type BuildDockerfileProps struct {
//go:embed templates/build.Dockerfile
var buildDockerfileTemplate string

func mocked_get_etc_passwd_file_content(etcPasswdFileContent string) func() (string, error) {
return func() (string, error) {
return etcPasswdFileContent, nil
}
}

func testFillPropsToTemplate(t *testing.T, context spec.G, it spec.S) {

var (
Expand Down Expand Up @@ -126,7 +131,7 @@ func testGenerate(t *testing.T, context spec.G, it spec.S) {
workingDir = t.TempDir()
Expect(err).NotTo(HaveOccurred())

p := ubinodejsextension.NewDuringBuildPermissionsGetter(fakes.Get_etc_passwd_file_content(`root:x:0:0:root:/root:/bin/bash
p := ubinodejsextension.NewDuringBuildPermissionsGetter(mocked_get_etc_passwd_file_content(`root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
Expand Down Expand Up @@ -175,7 +180,7 @@ cnb:x:1001:1000::/home/cnb:/bin/bash
workingDir = t.TempDir()
cnbDir, err = os.MkdirTemp("", "cnb")

p := ubinodejsextension.NewDuringBuildPermissionsGetter(fakes.Get_etc_passwd_file_content(`root:x:0:0:root:/root:/bin/bash
p := ubinodejsextension.NewDuringBuildPermissionsGetter(mocked_get_etc_passwd_file_content(`root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
Expand Down Expand Up @@ -565,7 +570,7 @@ cnb:x:1001:1000::/home/cnb:/bin/bash
workingDir = t.TempDir()
Expect(err).NotTo(HaveOccurred())

p := ubinodejsextension.NewDuringBuildPermissionsGetter(fakes.Get_etc_passwd_file_content(""))
p := ubinodejsextension.NewDuringBuildPermissionsGetter(mocked_get_etc_passwd_file_content(""))
generate = ubinodejsextension.Generate(dependencyManager, logger, p)

err = toml.NewEncoder(buf).Encode(testBuildPlan)
Expand Down Expand Up @@ -708,7 +713,7 @@ cnb:x:1001:1000::/home/cnb:/bin/bash
workingDir = t.TempDir()
cnbDir, err = os.MkdirTemp("", "cnb")

p := ubinodejsextension.NewDuringBuildPermissionsGetter(fakes.Get_etc_passwd_file_content(`root:x:0:0:root:/root:/bin/bash
p := ubinodejsextension.NewDuringBuildPermissionsGetter(mocked_get_etc_passwd_file_content(`root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
Expand Down
4 changes: 2 additions & 2 deletions run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
func main() {
dependencyManager := postal.NewService(cargo.NewTransport())
logEmitter := scribe.NewEmitter(os.Stdout).WithLevel(os.Getenv("BP_LOG_LEVEL"))
p := ubinodejsextension.NewDuringBuildPermissionsGetter(ubinodejsextension.Get_etc_passwd_file_content)
duringBuildPermissionsGetter := ubinodejsextension.NewDuringBuildPermissionsGetter(ubinodejsextension.Get_etc_passwd_file_content)

packit.RunExtension(
ubinodejsextension.Detect(),
ubinodejsextension.Generate(dependencyManager, logEmitter, p),
ubinodejsextension.Generate(dependencyManager, logEmitter, duringBuildPermissionsGetter),
)
}

0 comments on commit 4b2d60c

Please sign in to comment.