diff --git a/pexec/executable_test.go b/pexec/executable_test.go index 0daba3c9..20359d3f 100644 --- a/pexec/executable_test.go +++ b/pexec/executable_test.go @@ -20,8 +20,6 @@ func testPexec(t *testing.T, context spec.G, it spec.S) { var ( Expect = NewWithT(t).Expect - fakeCLI string - existingPath string tmpDir string stdout, stderr *bytes.Buffer @@ -39,18 +37,10 @@ func testPexec(t *testing.T, context spec.G, it spec.S) { stdout = bytes.NewBuffer(nil) stderr = bytes.NewBuffer(nil) - executable = pexec.NewExecutable("some-executable") - - fakeCLI, err = gexec.Build("github.com/paketo-buildpacks/packit/fakes/some-executable") - Expect(err).NotTo(HaveOccurred()) - - existingPath = os.Getenv("PATH") - os.Setenv("PATH", filepath.Dir(fakeCLI)) + executable = pexec.NewExecutable(filepath.Base(fakeCLI)) }) it.After(func() { - os.Setenv("PATH", existingPath) - gexec.CleanupBuildArtifacts() Expect(os.RemoveAll(tmpDir)).To(Succeed()) }) @@ -119,12 +109,12 @@ func testPexec(t *testing.T, context spec.G, it spec.S) { context("failure cases", func() { context("when the executable cannot be found on the path", func() { it.Before(func() { - Expect(os.Unsetenv("PATH")).To(Succeed()) + executable = pexec.NewExecutable("unknown-executable") }) it("returns an error", func() { err := executable.Execute(pexec.Execution{}) - Expect(err).To(MatchError("exec: \"some-executable\": executable file not found in $PATH")) + Expect(err).To(MatchError("exec: \"unknown-executable\": executable file not found in $PATH")) }) }) diff --git a/pexec/init_test.go b/pexec/init_test.go index aaeab9b6..c5de5924 100644 --- a/pexec/init_test.go +++ b/pexec/init_test.go @@ -1,14 +1,39 @@ package pexec_test import ( + "os" + "path/filepath" "testing" + "github.com/onsi/gomega/gexec" "github.com/sclevine/spec" "github.com/sclevine/spec/report" + + . "github.com/onsi/gomega" +) + +var ( + existingPath string + fakeCLI string ) func TestUnitExec(t *testing.T) { + var Expect = NewWithT(t).Expect + suite := spec.New("packit/pexec", spec.Report(report.Terminal{})) suite("pexec", testPexec) + + var err error + fakeCLI, err = gexec.Build("github.com/paketo-buildpacks/packit/fakes/some-executable") + Expect(err).NotTo(HaveOccurred()) + + existingPath = os.Getenv("PATH") + os.Setenv("PATH", filepath.Dir(fakeCLI)) + + t.Cleanup(func() { + os.Setenv("PATH", existingPath) + gexec.CleanupBuildArtifacts() + }) + suite.Run(t) }