Skip to content

Commit

Permalink
Rename executor to execd
Browse files Browse the repository at this point in the history
Signed-off-by: Sambhav Kothari <skothari44@bloomberg.net>
  • Loading branch information
sambhav committed Oct 5, 2021
1 parent c36f48d commit 5e05852
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 30 deletions.
12 changes: 6 additions & 6 deletions exec_d.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ import (
"github.com/buildpacks/libcnb/internal"
)

//go:generate mockery --name Executor --case=underscore
//go:generate mockery --name ExecD --case=underscore

// Executor describes an interface for types that follow the Exec.d specification.
// ExecD describes an interface for types that follow the Exec.d specification.
// It should return a map of environment variables and their values as output.
type Executor interface {
type ExecD interface {
Execute() (map[string]string, error)
}

// ExecD is called by the main function of a buildpack's execd binary, encompassing multiple execd
// RunExecD is called by the main function of a buildpack's execd binary, encompassing multiple execd
// executors in one binary.
func ExecD(executors map[string]Executor, options ...Option) {
func RunExecD(execDMap map[string]ExecD, options ...Option) {
config := Config{
arguments: os.Args,
execdWriter: internal.NewExecDWriter(),
Expand All @@ -52,7 +52,7 @@ func ExecD(executors map[string]Executor, options ...Option) {
}

c := filepath.Base(config.arguments[0])
e, ok := executors[c]
e, ok := execDMap[c]
if !ok {
config.exitHandler.Error(fmt.Errorf("unsupported command %s", c))
return
Expand Down
36 changes: 18 additions & 18 deletions exec_d_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func testExecD(t *testing.T, context spec.G, it spec.S) {
})

it("encounters the wrong number of arguments", func() {
libcnb.ExecD(map[string]libcnb.Executor{},
libcnb.RunExecD(map[string]libcnb.ExecD{},
libcnb.WithArguments([]string{}),
libcnb.WithExitHandler(exitHandler),
)
Expand All @@ -55,35 +55,35 @@ func testExecD(t *testing.T, context spec.G, it spec.S) {
})

it("encounters an unsupported execd binary name", func() {
libcnb.ExecD(map[string]libcnb.Executor{},
libcnb.RunExecD(map[string]libcnb.ExecD{},
libcnb.WithArguments([]string{"/dne"}),
libcnb.WithExitHandler(exitHandler),
)

Expect(exitHandler.Calls[0].Arguments.Get(0)).To(MatchError("unsupported command dne"))
})

it("calls the appropriate executor for a given execd binary", func() {
executor1 := &mocks.Executor{}
executor2 := &mocks.Executor{}
executor1.On("Execute", mock.Anything).Return(map[string]string{}, nil)
it("calls the appropriate execd for a given execd invoker binary", func() {
execd1 := &mocks.ExecD{}
execd2 := &mocks.ExecD{}
execd1.On("Execute", mock.Anything).Return(map[string]string{}, nil)

libcnb.ExecD(map[string]libcnb.Executor{"executor1": executor1, "executor2": executor2},
libcnb.WithArguments([]string{"executor1"}),
libcnb.RunExecD(map[string]libcnb.ExecD{"execd1": execd1, "execd2": execd2},
libcnb.WithArguments([]string{"execd1"}),
libcnb.WithExitHandler(exitHandler),
libcnb.WithExecDWriter(execdWriter),
)

Expect(executor1.Calls).To(HaveLen(1))
Expect(executor2.Calls).To(BeEmpty())
Expect(execd1.Calls).To(HaveLen(1))
Expect(execd2.Calls).To(BeEmpty())
})

it("calls exitHandler with the error from the executor", func() {
e := &mocks.Executor{}
it("calls exitHandler with the error from the execd", func() {
e := &mocks.ExecD{}
err := fmt.Errorf("example error")
e.On("Execute", mock.Anything).Return(nil, err)

libcnb.ExecD(map[string]libcnb.Executor{"e": e},
libcnb.RunExecD(map[string]libcnb.ExecD{"e": e},
libcnb.WithArguments([]string{"/bin/e"}),
libcnb.WithExitHandler(exitHandler),
libcnb.WithExecDWriter(execdWriter),
Expand All @@ -95,11 +95,11 @@ func testExecD(t *testing.T, context spec.G, it spec.S) {
})

it("calls execdWriter.write with the appropriate input", func() {
e := &mocks.Executor{}
e := &mocks.ExecD{}
o := map[string]string{"test": "test"}
e.On("Execute", mock.Anything).Return(o, nil)

libcnb.ExecD(map[string]libcnb.Executor{"e": e},
libcnb.RunExecD(map[string]libcnb.ExecD{"e": e},
libcnb.WithArguments([]string{"/bin/e"}),
libcnb.WithExitHandler(exitHandler),
libcnb.WithExecDWriter(execdWriter),
Expand All @@ -112,12 +112,12 @@ func testExecD(t *testing.T, context spec.G, it spec.S) {
Expect(execdWriter.Calls[0].Arguments[0]).To(Equal(o))
})

it("calls exitHandler with the error from the executor", func() {
e := &mocks.Executor{}
it("calls exitHandler with the error from the execd", func() {
e := &mocks.ExecD{}
err := fmt.Errorf("example error")
e.On("Execute", mock.Anything).Return(nil, err)

libcnb.ExecD(map[string]libcnb.Executor{"e": e},
libcnb.RunExecD(map[string]libcnb.ExecD{"e": e},
libcnb.WithArguments([]string{"/bin/e"}),
libcnb.WithExitHandler(exitHandler),
libcnb.WithExecDWriter(execdWriter),
Expand Down
3 changes: 2 additions & 1 deletion mocks/builder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion mocks/detector.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions mocks/executor.go → mocks/exec_d.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion mocks/layer_contributor.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5e05852

Please sign in to comment.