Skip to content

Commit d2e6638

Browse files
Ryan Moranryanmoran
Ryan Moran
authored andcommitted
Resolve issue with gexec executable names being unguessable
1 parent cbc7f72 commit d2e6638

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

pexec/executable_test.go

+3-13
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ func testPexec(t *testing.T, context spec.G, it spec.S) {
2020
var (
2121
Expect = NewWithT(t).Expect
2222

23-
fakeCLI string
24-
existingPath string
2523
tmpDir string
2624
stdout, stderr *bytes.Buffer
2725

@@ -39,18 +37,10 @@ func testPexec(t *testing.T, context spec.G, it spec.S) {
3937
stdout = bytes.NewBuffer(nil)
4038
stderr = bytes.NewBuffer(nil)
4139

42-
executable = pexec.NewExecutable("some-executable")
43-
44-
fakeCLI, err = gexec.Build("github.com/paketo-buildpacks/packit/fakes/some-executable")
45-
Expect(err).NotTo(HaveOccurred())
46-
47-
existingPath = os.Getenv("PATH")
48-
os.Setenv("PATH", filepath.Dir(fakeCLI))
40+
executable = pexec.NewExecutable(filepath.Base(fakeCLI))
4941
})
5042

5143
it.After(func() {
52-
os.Setenv("PATH", existingPath)
53-
gexec.CleanupBuildArtifacts()
5444
Expect(os.RemoveAll(tmpDir)).To(Succeed())
5545
})
5646

@@ -119,12 +109,12 @@ func testPexec(t *testing.T, context spec.G, it spec.S) {
119109
context("failure cases", func() {
120110
context("when the executable cannot be found on the path", func() {
121111
it.Before(func() {
122-
Expect(os.Unsetenv("PATH")).To(Succeed())
112+
executable = pexec.NewExecutable("unknown-executable")
123113
})
124114

125115
it("returns an error", func() {
126116
err := executable.Execute(pexec.Execution{})
127-
Expect(err).To(MatchError("exec: \"some-executable\": executable file not found in $PATH"))
117+
Expect(err).To(MatchError("exec: \"unknown-executable\": executable file not found in $PATH"))
128118
})
129119
})
130120

pexec/init_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,39 @@
11
package pexec_test
22

33
import (
4+
"os"
5+
"path/filepath"
46
"testing"
57

8+
"github.com/onsi/gomega/gexec"
69
"github.com/sclevine/spec"
710
"github.com/sclevine/spec/report"
11+
12+
. "github.com/onsi/gomega"
13+
)
14+
15+
var (
16+
existingPath string
17+
fakeCLI string
818
)
919

1020
func TestUnitExec(t *testing.T) {
21+
var Expect = NewWithT(t).Expect
22+
1123
suite := spec.New("packit/pexec", spec.Report(report.Terminal{}))
1224
suite("pexec", testPexec)
25+
26+
var err error
27+
fakeCLI, err = gexec.Build("github.com/paketo-buildpacks/packit/fakes/some-executable")
28+
Expect(err).NotTo(HaveOccurred())
29+
30+
existingPath = os.Getenv("PATH")
31+
os.Setenv("PATH", filepath.Dir(fakeCLI))
32+
33+
t.Cleanup(func() {
34+
os.Setenv("PATH", existingPath)
35+
gexec.CleanupBuildArtifacts()
36+
})
37+
1338
suite.Run(t)
1439
}

0 commit comments

Comments
 (0)