From 5e05852376725b88fac06227d65f688bca199342 Mon Sep 17 00:00:00 2001 From: Sambhav Kothari Date: Tue, 5 Oct 2021 18:29:35 +0100 Subject: [PATCH] Rename executor to execd Signed-off-by: Sambhav Kothari --- exec_d.go | 12 +++++------ exec_d_test.go | 36 ++++++++++++++++---------------- mocks/builder.go | 3 ++- mocks/detector.go | 3 ++- mocks/{executor.go => exec_d.go} | 6 +++--- mocks/layer_contributor.go | 3 ++- 6 files changed, 33 insertions(+), 30 deletions(-) rename mocks/{executor.go => exec_d.go} (77%) diff --git a/exec_d.go b/exec_d.go index 6812845..d290632 100644 --- a/exec_d.go +++ b/exec_d.go @@ -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(), @@ -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 diff --git a/exec_d_test.go b/exec_d_test.go index 26b2702..01f3c39 100644 --- a/exec_d_test.go +++ b/exec_d_test.go @@ -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), ) @@ -55,7 +55,7 @@ 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), ) @@ -63,27 +63,27 @@ func testExecD(t *testing.T, context spec.G, it spec.S) { 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), @@ -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), @@ -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), diff --git a/mocks/builder.go b/mocks/builder.go index f1c03ac..44ea7a7 100644 --- a/mocks/builder.go +++ b/mocks/builder.go @@ -3,8 +3,9 @@ package mocks import ( - libcnb "github.com/buildpacks/libcnb" mock "github.com/stretchr/testify/mock" + + libcnb "github.com/buildpacks/libcnb" ) // Builder is an autogenerated mock type for the Builder type diff --git a/mocks/detector.go b/mocks/detector.go index e422366..8d3174f 100644 --- a/mocks/detector.go +++ b/mocks/detector.go @@ -3,8 +3,9 @@ package mocks import ( - libcnb "github.com/buildpacks/libcnb" mock "github.com/stretchr/testify/mock" + + libcnb "github.com/buildpacks/libcnb" ) // Detector is an autogenerated mock type for the Detector type diff --git a/mocks/executor.go b/mocks/exec_d.go similarity index 77% rename from mocks/executor.go rename to mocks/exec_d.go index d33e5a2..7d8075e 100644 --- a/mocks/executor.go +++ b/mocks/exec_d.go @@ -4,13 +4,13 @@ package mocks import mock "github.com/stretchr/testify/mock" -// Executor is an autogenerated mock type for the Executor type -type Executor struct { +// ExecD is an autogenerated mock type for the ExecD type +type ExecD struct { mock.Mock } // Execute provides a mock function with given fields: -func (_m *Executor) Execute() (map[string]string, error) { +func (_m *ExecD) Execute() (map[string]string, error) { ret := _m.Called() var r0 map[string]string diff --git a/mocks/layer_contributor.go b/mocks/layer_contributor.go index 64dc61a..23ef13d 100644 --- a/mocks/layer_contributor.go +++ b/mocks/layer_contributor.go @@ -3,8 +3,9 @@ package mocks import ( - libcnb "github.com/buildpacks/libcnb" mock "github.com/stretchr/testify/mock" + + libcnb "github.com/buildpacks/libcnb" ) // LayerContributor is an autogenerated mock type for the LayerContributor type