Skip to content

Commit

Permalink
Pass logger pointer around instead of copying the struct
Browse files Browse the repository at this point in the history
This is to remove flakes in test like
(https://buildpacks.ci.cf-app.com/teams/feature-eng/pipelines/npm-cnb/jobs/integration-tests/builds/4)
The writer doesn't seem to show deterministic write behavior
when logging using copies of logger. Hence pass a pointer
to the same logger around.
  • Loading branch information
arjun024 committed Apr 3, 2020
1 parent 6984829 commit 01c3544
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cmd/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func main() {
logger := scribe.NewLogger(os.Stdout)

checksumCalculator := fs.NewChecksumCalculator()
resolver := npm.NewBuildProcessResolver(executable, checksumCalculator, logger)
resolver := npm.NewBuildProcessResolver(executable, checksumCalculator, &logger)
clock := npm.NewClock(time.Now)

packit.Build(npm.Build(resolver, clock, logger))
packit.Build(npm.Build(resolver, clock, &logger))
}
2 changes: 1 addition & 1 deletion npm/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type BuildManager interface {
Resolve(workingDir, cacheDir string) (BuildProcess, error)
}

func Build(buildManager BuildManager, clock Clock, logger scribe.Logger) packit.BuildFunc {
func Build(buildManager BuildManager, clock Clock, logger *scribe.Logger) packit.BuildFunc {
return func(context packit.BuildContext) (packit.BuildResult, error) {
logger.Title("%s %s", context.BuildpackInfo.Name, context.BuildpackInfo.Version)

Expand Down
4 changes: 2 additions & 2 deletions npm/build_process_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ type Summer interface {
type BuildProcessResolver struct {
executable Executable
summer Summer
logger scribe.Logger
logger *scribe.Logger
}

func NewBuildProcessResolver(executable Executable, summer Summer, logger scribe.Logger) BuildProcessResolver {
func NewBuildProcessResolver(executable Executable, summer Summer, logger *scribe.Logger) BuildProcessResolver {
return BuildProcessResolver{
executable: executable,
summer: summer,
Expand Down
5 changes: 3 additions & 2 deletions npm/build_process_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func testBuildProcessResolver(t *testing.T, context spec.G, it spec.S) {
buffer = bytes.NewBuffer(nil)
logger := scribe.NewLogger(buffer)

resolver = npm.NewBuildProcessResolver(executable, summer, logger)
resolver = npm.NewBuildProcessResolver(executable, summer, &logger)
})
it.After(func() {
Expect(os.RemoveAll(workingDir)).To(Succeed())
Expand Down Expand Up @@ -258,7 +258,8 @@ func testBuildProcessResolver(t *testing.T, context spec.G, it spec.S) {
workingDir, err = ioutil.TempDir("", "working-dir")
Expect(err).NotTo(HaveOccurred())

resolver = npm.NewBuildProcessResolver(executable, summer, scribe.NewLogger(bytes.NewBuffer(nil)))
logger := scribe.NewLogger(bytes.NewBuffer(nil))
resolver = npm.NewBuildProcessResolver(executable, summer, &logger)
})

it.After(func() {
Expand Down
8 changes: 5 additions & 3 deletions npm/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
buffer = bytes.NewBuffer(nil)
logger := scribe.NewLogger(buffer)

build = npm.Build(buildManager, clock, logger)
build = npm.Build(buildManager, clock, &logger)
})

it.After(func() {
Expand Down Expand Up @@ -239,7 +239,8 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
return nil
}

build = npm.Build(buildManager, clock, scribe.NewLogger(buffer))
logger := scribe.NewLogger(buffer)
build = npm.Build(buildManager, clock, &logger)
})

it("filters out empty layers", func() {
Expand Down Expand Up @@ -283,7 +284,8 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
it.Before(func() {
buildProcess.RunCall.Stub = func(ld, cd, wd string) error { return nil }

build = npm.Build(buildManager, clock, scribe.NewLogger(buffer))
logger := scribe.NewLogger(buffer)
build = npm.Build(buildManager, clock, &logger)
})

it("filters out empty layers", func() {
Expand Down

0 comments on commit 01c3544

Please sign in to comment.