Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9ebea35

Browse files
committedJun 25, 2021
Refactoring to remove ioutil and custom logger
1 parent 24ab9d9 commit 9ebea35

22 files changed

+72
-100
lines changed
 

‎build.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/paketo-buildpacks/packit"
88
"github.com/paketo-buildpacks/packit/chronos"
9+
"github.com/paketo-buildpacks/packit/scribe"
910
)
1011

1112
//go:generate faux --interface BuildProcess --output fakes/build_process.go
@@ -29,7 +30,7 @@ func Build(
2930
buildProcess BuildProcess,
3031
pathManager PathManager,
3132
clock chronos.Clock,
32-
logs LogEmitter,
33+
logs scribe.Emitter,
3334
sourceRemover SourceRemover,
3435
) packit.BuildFunc {
3536

@@ -104,8 +105,7 @@ func Build(
104105
})
105106
}
106107

107-
logs.Process("Assigning launch processes")
108-
logs.ListProcesses(processes)
108+
logs.LaunchProcesses(processes)
109109

110110
return packit.BuildResult{
111111
Layers: []packit.Layer{targetsLayer, goCacheLayer},

‎build_configuration_parser_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package gobuild_test
22

33
import (
44
"errors"
5-
"io/ioutil"
65
"os"
76
"path/filepath"
87
"testing"
@@ -28,7 +27,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) {
2827

2928
it.Before(func() {
3029
var err error
31-
workingDir, err = ioutil.TempDir("", "working-dir")
30+
workingDir, err = os.MkdirTemp("", "working-dir")
3231
Expect(err).NotTo(HaveOccurred())
3332

3433
targetManager = &fakes.TargetManager{}
@@ -208,7 +207,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) {
208207

209208
context("when there is a buildpack.yml and environment variables are not set", func() {
210209
it.Before(func() {
211-
err := ioutil.WriteFile(filepath.Join(workingDir, "buildpack.yml"), nil, 0644)
210+
err := os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), nil, 0644)
212211
Expect(err).NotTo(HaveOccurred())
213212

214213
targetManager.CleanAndValidateCall.Returns.StringSlice = []string{"./first", "./second"}
@@ -234,7 +233,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) {
234233

235234
context("when there is a buildpack.yml and environment variables are set", func() {
236235
it.Before(func() {
237-
err := ioutil.WriteFile(filepath.Join(workingDir, "buildpack.yml"), nil, 0644)
236+
err := os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), nil, 0644)
238237
Expect(err).NotTo(HaveOccurred())
239238

240239
os.Setenv("BP_GO_BUILD_IMPORT_PATH", "./some/import/path")
@@ -269,7 +268,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) {
269268

270269
context("buildpack.yml specifies flags including -ldflags and BP_GO_BUILD_LDFLAGS is set", func() {
271270
it.Before(func() {
272-
err := ioutil.WriteFile(filepath.Join(workingDir, "buildpack.yml"), nil, 0644)
271+
err := os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), nil, 0644)
273272
Expect(err).NotTo(HaveOccurred())
274273

275274
buildpackYMLParser.ParseCall.Returns.BuildConfiguration = gobuild.BuildConfiguration{
@@ -319,7 +318,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) {
319318

320319
context("buildpack.yml parsing fails", func() {
321320
it.Before(func() {
322-
err := ioutil.WriteFile(filepath.Join(workingDir, "buildpack.yml"), nil, 0644)
321+
err := os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), nil, 0644)
323322
Expect(err).NotTo(HaveOccurred())
324323

325324
buildpackYMLParser.ParseCall.Returns.Error = errors.New("failed to parse buildpack.yml")

‎build_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package gobuild_test
33
import (
44
"bytes"
55
"errors"
6-
"io/ioutil"
76
"os"
87
"path/filepath"
98
"testing"
@@ -13,6 +12,7 @@ import (
1312
"github.com/paketo-buildpacks/go-build/fakes"
1413
"github.com/paketo-buildpacks/packit"
1514
"github.com/paketo-buildpacks/packit/chronos"
15+
"github.com/paketo-buildpacks/packit/scribe"
1616
"github.com/sclevine/spec"
1717

1818
. "github.com/onsi/gomega"
@@ -38,13 +38,13 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
3838

3939
it.Before(func() {
4040
var err error
41-
layersDir, err = ioutil.TempDir("", "layers")
41+
layersDir, err = os.MkdirTemp("", "layers")
4242
Expect(err).NotTo(HaveOccurred())
4343

44-
cnbDir, err = ioutil.TempDir("", "cnb")
44+
cnbDir, err = os.MkdirTemp("", "cnb")
4545
Expect(err).NotTo(HaveOccurred())
4646

47-
workingDir, err = ioutil.TempDir("", "working-dir")
47+
workingDir, err = os.MkdirTemp("", "working-dir")
4848
Expect(err).NotTo(HaveOccurred())
4949

5050
buildProcess = &fakes.BuildProcess{}
@@ -75,7 +75,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
7575
buildProcess,
7676
pathManager,
7777
clock,
78-
gobuild.NewLogEmitter(logs),
78+
scribe.NewEmitter(logs),
7979
sourceRemover,
8080
)
8181
})
@@ -242,7 +242,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
242242
context("failure cases", func() {
243243
context("when the targets layer cannot be retrieved", func() {
244244
it.Before(func() {
245-
Expect(ioutil.WriteFile(filepath.Join(layersDir, "targets.toml"), nil, 0000)).To(Succeed())
245+
Expect(os.WriteFile(filepath.Join(layersDir, "targets.toml"), nil, 0000)).To(Succeed())
246246
})
247247

248248
it("returns an error", func() {
@@ -263,7 +263,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
263263

264264
context("when the gocache layer cannot be retrieved", func() {
265265
it.Before(func() {
266-
Expect(ioutil.WriteFile(filepath.Join(layersDir, "gocache.toml"), nil, 0000)).To(Succeed())
266+
Expect(os.WriteFile(filepath.Join(layersDir, "gocache.toml"), nil, 0000)).To(Succeed())
267267
})
268268

269269
it("returns an error", func() {

‎buildpack.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
api = "0.4"
1+
api = "0.5"
22

33
[buildpack]
44
homepage = "https://github.com/paketo-buildpacks/go-build"

‎go_build_process.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/paketo-buildpacks/packit/chronos"
1616
"github.com/paketo-buildpacks/packit/pexec"
17+
"github.com/paketo-buildpacks/packit/scribe"
1718
)
1819

1920
//go:generate faux --interface Executable --output fakes/executable.go
@@ -32,11 +33,11 @@ type GoBuildConfiguration struct {
3233

3334
type GoBuildProcess struct {
3435
executable Executable
35-
logs LogEmitter
36+
logs scribe.Emitter
3637
clock chronos.Clock
3738
}
3839

39-
func NewGoBuildProcess(executable Executable, logs LogEmitter, clock chronos.Clock) GoBuildProcess {
40+
func NewGoBuildProcess(executable Executable, logs scribe.Emitter, clock chronos.Clock) GoBuildProcess {
4041
return GoBuildProcess{
4142
executable: executable,
4243
logs: logs,

‎go_build_process_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7-
"io/ioutil"
87
"os"
98
"path/filepath"
109
"testing"
@@ -14,6 +13,7 @@ import (
1413
"github.com/paketo-buildpacks/go-build/fakes"
1514
"github.com/paketo-buildpacks/packit/chronos"
1615
"github.com/paketo-buildpacks/packit/pexec"
16+
"github.com/paketo-buildpacks/packit/scribe"
1717
"github.com/sclevine/spec"
1818

1919
. "github.com/onsi/gomega"
@@ -38,16 +38,16 @@ func testGoBuildProcess(t *testing.T, context spec.G, it spec.S) {
3838

3939
it.Before(func() {
4040
var err error
41-
layerPath, err = ioutil.TempDir("", "layer")
41+
layerPath, err = os.MkdirTemp("", "layer")
4242
Expect(err).NotTo(HaveOccurred())
4343

44-
workspacePath, err = ioutil.TempDir("", "workspace")
44+
workspacePath, err = os.MkdirTemp("", "workspace")
4545
Expect(err).NotTo(HaveOccurred())
4646

47-
goPath, err = ioutil.TempDir("", "go-path")
47+
goPath, err = os.MkdirTemp("", "go-path")
4848
Expect(err).NotTo(HaveOccurred())
4949

50-
goCache, err = ioutil.TempDir("", "gocache")
50+
goCache, err = os.MkdirTemp("", "gocache")
5151
Expect(err).NotTo(HaveOccurred())
5252

5353
logs = bytes.NewBuffer(nil)
@@ -77,7 +77,7 @@ func testGoBuildProcess(t *testing.T, context spec.G, it spec.S) {
7777
return t
7878
})
7979

80-
buildProcess = gobuild.NewGoBuildProcess(executable, gobuild.NewLogEmitter(logs), clock)
80+
buildProcess = gobuild.NewGoBuildProcess(executable, scribe.NewEmitter(logs), clock)
8181
})
8282

8383
it.After(func() {
@@ -134,7 +134,7 @@ func testGoBuildProcess(t *testing.T, context spec.G, it spec.S) {
134134

135135
context("when there are build flags", func() {
136136
it.Before(func() {
137-
Expect(ioutil.WriteFile(filepath.Join(workspacePath, "go.mod"), nil, 0644)).To(Succeed())
137+
Expect(os.WriteFile(filepath.Join(workspacePath, "go.mod"), nil, 0644)).To(Succeed())
138138
Expect(os.Mkdir(filepath.Join(workspacePath, "vendor"), os.ModePerm)).To(Succeed())
139139
})
140140

@@ -181,7 +181,7 @@ func testGoBuildProcess(t *testing.T, context spec.G, it spec.S) {
181181

182182
context("when the GOPATH is empty", func() {
183183
it.Before(func() {
184-
Expect(ioutil.WriteFile(filepath.Join(workspacePath, "go.mod"), nil, 0644)).To(Succeed())
184+
Expect(os.WriteFile(filepath.Join(workspacePath, "go.mod"), nil, 0644)).To(Succeed())
185185
Expect(os.Mkdir(filepath.Join(workspacePath, "vendor"), os.ModePerm)).To(Succeed())
186186
})
187187

‎go_buildpack_yml_parser.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import (
88

99
"github.com/Masterminds/semver"
1010
"github.com/buildkite/interpolate"
11+
"github.com/paketo-buildpacks/packit/scribe"
1112
"gopkg.in/yaml.v2"
1213
)
1314

1415
type GoBuildpackYMLParser struct {
15-
logger LogEmitter
16+
logger scribe.Emitter
1617
}
1718

18-
func NewGoBuildpackYMLParser(logger LogEmitter) GoBuildpackYMLParser {
19+
func NewGoBuildpackYMLParser(logger scribe.Emitter) GoBuildpackYMLParser {
1920
return GoBuildpackYMLParser{
2021
logger: logger,
2122
}

‎go_buildpack_yml_parser_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package gobuild_test
22

33
import (
44
"bytes"
5-
"io/ioutil"
65
"os"
76
"path/filepath"
87
"testing"
98

109
gobuild "github.com/paketo-buildpacks/go-build"
10+
"github.com/paketo-buildpacks/packit/scribe"
1111
"github.com/sclevine/spec"
1212

1313
. "github.com/onsi/gomega"
@@ -25,10 +25,10 @@ func testGoBuildpackYMLParser(t *testing.T, context spec.G, it spec.S) {
2525

2626
it.Before(func() {
2727
var err error
28-
workingDir, err = ioutil.TempDir("", "working-dir")
28+
workingDir, err = os.MkdirTemp("", "working-dir")
2929
Expect(err).NotTo(HaveOccurred())
3030

31-
Expect(ioutil.WriteFile(filepath.Join(workingDir, "buildpack.yml"), []byte(`---
31+
Expect(os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), []byte(`---
3232
go:
3333
targets:
3434
- first
@@ -42,7 +42,7 @@ go:
4242
`), 0644)).To(Succeed())
4343

4444
logs = bytes.NewBuffer(nil)
45-
goBuildpackYMLParser = gobuild.NewGoBuildpackYMLParser(gobuild.NewLogEmitter(logs))
45+
goBuildpackYMLParser = gobuild.NewGoBuildpackYMLParser(scribe.NewEmitter(logs))
4646
})
4747

4848
it.After(func() {
@@ -70,7 +70,7 @@ go:
7070

7171
context("when the flags have an env var in them", func() {
7272
it.Before(func() {
73-
Expect(ioutil.WriteFile(filepath.Join(workingDir, "buildpack.yml"), []byte(`---
73+
Expect(os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), []byte(`---
7474
go:
7575
build:
7676
flags:
@@ -104,7 +104,7 @@ go:
104104

105105
context("when the buildpack.yml does not contain go configuration", func() {
106106
it.Before(func() {
107-
Expect(ioutil.WriteFile(filepath.Join(workingDir, "buildpack.yml"), []byte(`---
107+
Expect(os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), []byte(`---
108108
not-go:
109109
build:
110110
flags:
@@ -136,7 +136,7 @@ not-go:
136136

137137
context("buildpack.yml fails to parse", func() {
138138
it.Before(func() {
139-
Expect(ioutil.WriteFile(filepath.Join(workingDir, "buildpack.yml"), []byte(`%%%`), 0644)).To(Succeed())
139+
Expect(os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), []byte(`%%%`), 0644)).To(Succeed())
140140
})
141141

142142
it("returns an error", func() {
@@ -148,7 +148,7 @@ not-go:
148148

149149
context("when a the env var interpolation fails", func() {
150150
it.Before(func() {
151-
Expect(ioutil.WriteFile(filepath.Join(workingDir, "buildpack.yml"), []byte(`---
151+
Expect(os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), []byte(`---
152152
go:
153153
build:
154154
flags:

‎go_path_manager.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package gobuild
22

33
import (
44
"fmt"
5-
"io/ioutil"
65
"os"
76
"path/filepath"
87

@@ -25,7 +24,7 @@ func (m GoPathManager) Setup(workspace, importPath string) (string, string, erro
2524
return "", workspace, nil
2625
}
2726

28-
path, err := ioutil.TempDir(m.tempDir, "gopath")
27+
path, err := os.MkdirTemp(m.tempDir, "gopath")
2928
if err != nil {
3029
return "", "", fmt.Errorf("failed to setup GOPATH: %w", err)
3130
}

‎go_path_manager_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package gobuild_test
22

33
import (
4-
"io/ioutil"
54
"os"
65
"path/filepath"
76
"testing"
@@ -22,7 +21,7 @@ func testGoPathManager(t *testing.T, context spec.G, it spec.S) {
2221

2322
it.Before(func() {
2423
var err error
25-
tempDir, err = ioutil.TempDir("", "tmp")
24+
tempDir, err = os.MkdirTemp("", "tmp")
2625
Expect(err).NotTo(HaveOccurred())
2726

2827
pathManager = gobuild.NewGoPathManager(tempDir)
@@ -37,10 +36,10 @@ func testGoPathManager(t *testing.T, context spec.G, it spec.S) {
3736

3837
it.Before(func() {
3938
var err error
40-
workspacePath, err = ioutil.TempDir("", "workspace")
39+
workspacePath, err = os.MkdirTemp("", "workspace")
4140
Expect(err).NotTo(HaveOccurred())
4241

43-
Expect(ioutil.WriteFile(filepath.Join(workspacePath, "some-file"), nil, 0644)).To(Succeed())
42+
Expect(os.WriteFile(filepath.Join(workspacePath, "some-file"), nil, 0644)).To(Succeed())
4443
})
4544

4645
it.After(func() {
@@ -62,7 +61,7 @@ func testGoPathManager(t *testing.T, context spec.G, it spec.S) {
6261

6362
context("when the workspace contains a go.mod file", func() {
6463
it.Before(func() {
65-
Expect(ioutil.WriteFile(filepath.Join(workspacePath, "go.mod"), nil, 0644)).To(Succeed())
64+
Expect(os.WriteFile(filepath.Join(workspacePath, "go.mod"), nil, 0644)).To(Succeed())
6665
})
6766

6867
it("does not setup a GOPATH", func() {
@@ -110,7 +109,7 @@ func testGoPathManager(t *testing.T, context spec.G, it spec.S) {
110109

111110
it.Before(func() {
112111
var err error
113-
path, err = ioutil.TempDir("", "gopath")
112+
path, err = os.MkdirTemp("", "gopath")
114113
Expect(err).NotTo(HaveOccurred())
115114
})
116115

‎go_target_manager_test.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package gobuild_test
22

33
import (
44
"fmt"
5-
"io/ioutil"
65
"os"
76
"path/filepath"
87
"testing"
@@ -24,7 +23,7 @@ func testGoTargetManager(t *testing.T, context spec.G, it spec.S) {
2423

2524
it.Before(func() {
2625
var err error
27-
workingDir, err = ioutil.TempDir("", "working-dir")
26+
workingDir, err = os.MkdirTemp("", "working-dir")
2827
Expect(err).NotTo(HaveOccurred())
2928

3029
targetManager = gobuild.NewGoTargetManager()
@@ -40,11 +39,11 @@ func testGoTargetManager(t *testing.T, context spec.G, it spec.S) {
4039
it.Before(func() {
4140
targetDir := filepath.Join(workingDir, "first")
4241
Expect(os.MkdirAll(targetDir, os.ModePerm)).To(Succeed())
43-
Expect(ioutil.WriteFile(filepath.Join(targetDir, "main.go"), nil, 0644)).To(Succeed())
42+
Expect(os.WriteFile(filepath.Join(targetDir, "main.go"), nil, 0644)).To(Succeed())
4443

4544
targetDir = filepath.Join(workingDir, "second")
4645
Expect(os.MkdirAll(targetDir, os.ModePerm)).To(Succeed())
47-
Expect(ioutil.WriteFile(filepath.Join(targetDir, "main.go"), nil, 0644)).To(Succeed())
46+
Expect(os.WriteFile(filepath.Join(targetDir, "main.go"), nil, 0644)).To(Succeed())
4847
})
4948

5049
it("returns a slice of targets that have been cleaned", func() {
@@ -66,7 +65,7 @@ func testGoTargetManager(t *testing.T, context spec.G, it spec.S) {
6665
it.Before(func() {
6766
targetDir := filepath.Join(workingDir, "first")
6867
Expect(os.MkdirAll(targetDir, os.ModePerm)).To(Succeed())
69-
Expect(ioutil.WriteFile(filepath.Join(targetDir, "main.go"), nil, 0644)).To(Succeed())
68+
Expect(os.WriteFile(filepath.Join(targetDir, "main.go"), nil, 0644)).To(Succeed())
7069

7170
})
7271

@@ -90,7 +89,7 @@ func testGoTargetManager(t *testing.T, context spec.G, it spec.S) {
9089
context("GenerateDefaults", func() {
9190
context("when there is a *.go file in the workingDir", func() {
9291
it.Before(func() {
93-
Expect(ioutil.WriteFile(filepath.Join(workingDir, "main.go"), nil, 0644)).To(Succeed())
92+
Expect(os.WriteFile(filepath.Join(workingDir, "main.go"), nil, 0644)).To(Succeed())
9493
})
9594

9695
it("returns . as the target", func() {
@@ -105,11 +104,11 @@ func testGoTargetManager(t *testing.T, context spec.G, it spec.S) {
105104
it.Before(func() {
106105
targetDir := filepath.Join(workingDir, "cmd", "first")
107106
Expect(os.MkdirAll(targetDir, os.ModePerm)).To(Succeed())
108-
Expect(ioutil.WriteFile(filepath.Join(targetDir, "main.go"), nil, 0644)).To(Succeed())
107+
Expect(os.WriteFile(filepath.Join(targetDir, "main.go"), nil, 0644)).To(Succeed())
109108

110109
targetDir = filepath.Join(workingDir, "cmd", "something", "second")
111110
Expect(os.MkdirAll(targetDir, os.ModePerm)).To(Succeed())
112-
Expect(ioutil.WriteFile(filepath.Join(targetDir, "main.go"), nil, 0644)).To(Succeed())
111+
Expect(os.WriteFile(filepath.Join(targetDir, "main.go"), nil, 0644)).To(Succeed())
113112
})
114113

115114
it("returns a target list of all top level directories in ./cmd that contain *.go files", func() {

‎integration/build_flags_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func testBuildFlags(t *testing.T, context spec.G, it spec.S) {
8888
fmt.Sprintf(" Running 'go build -o /layers/%s/targets/bin -buildmode=default -tags=paketo \"-ldflags=-X main.variable=some-value\" .'", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
8989
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
9090
"",
91-
" Assigning launch processes",
91+
" Assigning launch processes:",
9292
fmt.Sprintf(" web: /layers/%s/targets/bin/workspace", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
9393
))
9494
})
@@ -138,7 +138,7 @@ func testBuildFlags(t *testing.T, context spec.G, it spec.S) {
138138
fmt.Sprintf(" Running 'go build -o /layers/%s/targets/bin -buildmode=default -tags=paketo \"-ldflags=-X main.variable=env-value\" .'", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
139139
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
140140
"",
141-
" Assigning launch processes",
141+
" Assigning launch processes:",
142142
fmt.Sprintf(" web: /layers/%s/targets/bin/workspace", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
143143
))
144144
})

‎integration/buildpack_yml_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package integration_test
22

33
import (
44
"fmt"
5-
"io/ioutil"
65
"os"
76
"path/filepath"
87
"strings"
@@ -46,7 +45,7 @@ func testBuildpackYML(t *testing.T, context spec.G, it spec.S) {
4645
source, err = occam.Source(filepath.Join("testdata", "targets"))
4746
Expect(err).NotTo(HaveOccurred())
4847

49-
err = ioutil.WriteFile(filepath.Join(source, "buildpack.yml"), []byte(`---
48+
err = os.WriteFile(filepath.Join(source, "buildpack.yml"), []byte(`---
5049
go:
5150
targets:
5251
- first
@@ -91,7 +90,7 @@ go:
9190
fmt.Sprintf(" Running 'go build -o /layers/%s/targets/bin -buildmode pie ./first ./second'", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
9291
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
9392
"",
94-
" Assigning launch processes",
93+
" Assigning launch processes:",
9594
fmt.Sprintf(" web: /layers/%s/targets/bin/first", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
9695
))
9796
})
@@ -128,7 +127,7 @@ go:
128127
fmt.Sprintf(" Running 'go build -o /layers/%s/targets/bin -buildmode pie ./third'", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
129128
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
130129
"",
131-
" Assigning launch processes",
130+
" Assigning launch processes:",
132131
fmt.Sprintf(" web: /layers/%s/targets/bin/third", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
133132
))
134133
})

‎integration/default_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func testDefault(t *testing.T, context spec.G, it spec.S) {
8787
fmt.Sprintf(" Running 'go build -o /layers/%s/targets/bin -buildmode pie .'", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
8888
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
8989
"",
90-
" Assigning launch processes",
90+
" Assigning launch processes:",
9191
fmt.Sprintf(" web: /layers/%s/targets/bin/workspace", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
9292
))
9393
})

‎integration/import_path_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func testImportPath(t *testing.T, context spec.G, it spec.S) {
8888
fmt.Sprintf(" Running 'go build -o /layers/%s/targets/bin -buildmode pie .'", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
8989
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
9090
"",
91-
" Assigning launch processes",
91+
" Assigning launch processes:",
9292
fmt.Sprintf(" web: /layers/%s/targets/bin/import_path", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
9393
))
9494
})

‎integration/mod_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func testMod(t *testing.T, context spec.G, it spec.S) {
8080
fmt.Sprintf(" Running 'go build -o /layers/%s/targets/bin -buildmode pie .'", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
8181
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
8282
"",
83-
" Assigning launch processes",
83+
" Assigning launch processes:",
8484
fmt.Sprintf(" web: /layers/%s/targets/bin/mod", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
8585
))
8686
})

‎integration/targets_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func testTargets(t *testing.T, context spec.G, it spec.S) {
8181
fmt.Sprintf(" Running 'go build -o /layers/%s/targets/bin -buildmode pie ./first ./second'", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
8282
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
8383
"",
84-
" Assigning launch processes",
84+
" Assigning launch processes:",
8585
fmt.Sprintf(" web: /layers/%s/targets/bin/first", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
8686
fmt.Sprintf(" first: /layers/%s/targets/bin/first", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
8787
fmt.Sprintf(" second: /layers/%s/targets/bin/second", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),

‎integration/testdata/keep_files/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"fmt"
5-
"io/ioutil"
65
"log"
76
"net/http"
87
"os"
@@ -17,7 +16,7 @@ func main() {
1716
paths, _ := filepath.Glob("/workspace/*")
1817
fmt.Fprintf(w, "/workspace contents: %v\n", paths)
1918

20-
contents, _ := ioutil.ReadFile("./assets/some-file")
19+
contents, _ := os.ReadFile("./assets/some-file")
2120
fmt.Fprintf(w, "file contents: %s\n", string(contents))
2221
})
2322

‎integration/vendor_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func testVendor(t *testing.T, context spec.G, it spec.S) {
8080
fmt.Sprintf(" Running 'go build -o /layers/%s/targets/bin -buildmode pie .'", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
8181
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
8282
"",
83-
" Assigning launch processes",
83+
" Assigning launch processes:",
8484
fmt.Sprintf(" web: /layers/%s/targets/bin/workspace", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
8585
))
8686
})

‎log_emitter.go

-24
This file was deleted.

‎run/main.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77
"github.com/paketo-buildpacks/packit"
88
"github.com/paketo-buildpacks/packit/chronos"
99
"github.com/paketo-buildpacks/packit/pexec"
10+
"github.com/paketo-buildpacks/packit/scribe"
1011
)
1112

1213
func main() {
13-
logEmitter := gobuild.NewLogEmitter(os.Stdout)
14-
configParser := gobuild.NewBuildConfigurationParser(gobuild.NewGoTargetManager(), gobuild.NewGoBuildpackYMLParser(logEmitter))
14+
emitter := scribe.NewEmitter(os.Stdout)
15+
configParser := gobuild.NewBuildConfigurationParser(gobuild.NewGoTargetManager(), gobuild.NewGoBuildpackYMLParser(emitter))
1516

1617
packit.Run(
1718
gobuild.Detect(
@@ -21,12 +22,12 @@ func main() {
2122
configParser,
2223
gobuild.NewGoBuildProcess(
2324
pexec.NewExecutable("go"),
24-
logEmitter,
25+
emitter,
2526
chronos.DefaultClock,
2627
),
2728
gobuild.NewGoPathManager(os.TempDir()),
2829
chronos.DefaultClock,
29-
logEmitter,
30+
emitter,
3031
gobuild.NewSourceDeleter(),
3132
),
3233
)

‎source_deleter_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package gobuild_test
22

33
import (
4-
"io/ioutil"
54
"os"
65
"path/filepath"
76
"testing"
@@ -23,14 +22,14 @@ func testSourceDeleter(t *testing.T, context spec.G, it spec.S) {
2322

2423
it.Before(func() {
2524
var err error
26-
path, err = ioutil.TempDir("", "source")
25+
path, err = os.MkdirTemp("", "source")
2726
Expect(err).NotTo(HaveOccurred())
2827

29-
Expect(ioutil.WriteFile(filepath.Join(path, "some-file"), nil, os.ModePerm)).To(Succeed())
28+
Expect(os.WriteFile(filepath.Join(path, "some-file"), nil, os.ModePerm)).To(Succeed())
3029
Expect(os.MkdirAll(filepath.Join(path, "some-dir", "some-other-dir", "another-dir"), os.ModePerm)).To(Succeed())
31-
Expect(ioutil.WriteFile(filepath.Join(path, "some-dir", "some-file"), nil, os.ModePerm)).To(Succeed())
32-
Expect(ioutil.WriteFile(filepath.Join(path, "some-dir", "some-other-dir", "some-file"), nil, os.ModePerm)).To(Succeed())
33-
Expect(ioutil.WriteFile(filepath.Join(path, "some-dir", "some-other-dir", "another-dir", "some-file"), nil, os.ModePerm)).To(Succeed())
30+
Expect(os.WriteFile(filepath.Join(path, "some-dir", "some-file"), nil, os.ModePerm)).To(Succeed())
31+
Expect(os.WriteFile(filepath.Join(path, "some-dir", "some-other-dir", "some-file"), nil, os.ModePerm)).To(Succeed())
32+
Expect(os.WriteFile(filepath.Join(path, "some-dir", "some-other-dir", "another-dir", "some-file"), nil, os.ModePerm)).To(Succeed())
3433

3534
deleter = gobuild.NewSourceDeleter()
3635
})

0 commit comments

Comments
 (0)
Please sign in to comment.