From a8e42637c42fb39f57301dde1c8111dc2515b8c6 Mon Sep 17 00:00:00 2001 From: Daniel Mikusa Date: Fri, 4 Oct 2024 10:16:24 -0400 Subject: [PATCH] Do not use effect.NewExecutor use CommandExecutor instead When running `syft`, do not use effect.NewExecutor which runs the command with a tty. This seems to cause an issue with syft (or possibly with our tty library pty), and in either case you end up with stray formatting characters even though we tell syft to be quiet. Using CommandExecutor is basically the same, but it doesn't run with a tty. Signed-off-by: Daniel Mikusa --- lein/build.go | 2 +- lein/build_test.go | 9 +++++---- lein/detect_test.go | 5 ++--- lein/distribution_test.go | 3 +-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lein/build.go b/lein/build.go index 269591d..86804f6 100644 --- a/lein/build.go +++ b/lein/build.go @@ -102,7 +102,7 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) { InterestingFileDetector: libbs.AlwaysInterestingFileDetector{}, } - sbomScanner := sbom.NewSyftCLISBOMScanner(context.Layers, effect.NewExecutor(), b.Logger) + sbomScanner := sbom.NewSyftCLISBOMScanner(context.Layers, effect.CommandExecutor{}, b.Logger) a, err := b.ApplicationFactory.NewApplication( map[string]interface{}{}, diff --git a/lein/build_test.go b/lein/build_test.go index 049277f..a26ceec 100644 --- a/lein/build_test.go +++ b/lein/build_test.go @@ -17,7 +17,6 @@ package lein_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -43,12 +42,14 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - ctx.Application.Path, err = ioutil.TempDir("", "build-application") + ctx.Application.Path, err = os.MkdirTemp("", "build-application") Expect(err).NotTo(HaveOccurred()) - ctx.Layers.Path, err = ioutil.TempDir("", "build-layers") + ctx.Layers.Path, err = os.MkdirTemp("", "build-layers") Expect(err).NotTo(HaveOccurred()) leinBuild = lein.Build{ApplicationFactory: &FakeApplicationFactory{}} + + t.Setenv("BP_ARCH", "amd64") }) it.After(func() { @@ -57,7 +58,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { }) it("does not contribute distribution if wrapper exists", func() { - Expect(ioutil.WriteFile(filepath.Join(ctx.Application.Path, "lein"), []byte{}, 0644)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(ctx.Application.Path, "lein"), []byte{}, 0644)).To(Succeed()) ctx.StackID = "test-stack-id" result, err := leinBuild.Build(ctx) diff --git a/lein/detect_test.go b/lein/detect_test.go index f9426d8..fc37fe9 100644 --- a/lein/detect_test.go +++ b/lein/detect_test.go @@ -17,7 +17,6 @@ package lein_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -40,7 +39,7 @@ func testDetect(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - ctx.Application.Path, err = ioutil.TempDir("", "lein") + ctx.Application.Path, err = os.MkdirTemp("", "lein") Expect(err).NotTo(HaveOccurred()) }) @@ -53,7 +52,7 @@ func testDetect(t *testing.T, context spec.G, it spec.S) { }) it("passes with project.clj", func() { - Expect(ioutil.WriteFile(filepath.Join(ctx.Application.Path, "project.clj"), []byte{}, 0644)) + Expect(os.WriteFile(filepath.Join(ctx.Application.Path, "project.clj"), []byte{}, 0644)) Expect(detect.Detect(ctx)).To(Equal(libcnb.DetectResult{ Pass: true, diff --git a/lein/distribution_test.go b/lein/distribution_test.go index ce05efc..ab407a3 100644 --- a/lein/distribution_test.go +++ b/lein/distribution_test.go @@ -17,7 +17,6 @@ package lein_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -42,7 +41,7 @@ func testDistribution(t *testing.T, context spec.G, it spec.S) { Expect(err).NotTo(HaveOccurred()) - ctx.Layers.Path, err = ioutil.TempDir("", "distribution-layers") + ctx.Layers.Path, err = os.MkdirTemp("", "distribution-layers") Expect(err).NotTo(HaveOccurred()) })