diff --git a/pkg/cmd/extension/extension.go b/pkg/cmd/extension/extension.go index ead9204cd..b4106228f 100644 --- a/pkg/cmd/extension/extension.go +++ b/pkg/cmd/extension/extension.go @@ -48,3 +48,7 @@ func (e *Extension) UpdateAvailable() bool { } return true } + +func (e *Extension) IsBinary() bool { + return e.kind == BinaryKind +} diff --git a/pkg/cmd/extension/manager.go b/pkg/cmd/extension/manager.go index aec54f5b2..7110254a4 100644 --- a/pkg/cmd/extension/manager.go +++ b/pkg/cmd/extension/manager.go @@ -69,9 +69,11 @@ func (m *Manager) Dispatch(args []string, stdin io.Reader, stdout, stderr io.Wri forwardArgs := args[1:] exts, _ := m.list(false) + var ext Extension for _, e := range exts { if e.Name() == extName { - exe = e.Path() + ext = e + exe = ext.Path() break } } @@ -81,7 +83,9 @@ func (m *Manager) Dispatch(args []string, stdin io.Reader, stdout, stderr io.Wri var externalCmd *exec.Cmd - if runtime.GOOS == "windows" { + if ext.IsBinary() { + externalCmd = m.newCommand(exe, forwardArgs...) + } else if runtime.GOOS == "windows" { // Dispatch all extension calls through the `sh` interpreter to support executable files with a // shebang line on Windows. shExe, err := m.findSh() diff --git a/pkg/extensions/extension.go b/pkg/extensions/extension.go index f0962a87a..ee55bfabc 100644 --- a/pkg/extensions/extension.go +++ b/pkg/extensions/extension.go @@ -13,6 +13,7 @@ type Extension interface { URL() string IsLocal() bool UpdateAvailable() bool + IsBinary() bool } //go:generate moq -rm -out manager_mock.go . ExtensionManager diff --git a/pkg/extensions/extension_mock.go b/pkg/extensions/extension_mock.go index 17e2a3f6b..b999ab955 100644 --- a/pkg/extensions/extension_mock.go +++ b/pkg/extensions/extension_mock.go @@ -17,6 +17,9 @@ var _ Extension = &ExtensionMock{} // // // make and configure a mocked Extension // mockedExtension := &ExtensionMock{ +// IsBinaryFunc: func() bool { +// panic("mock out the IsBinary method") +// }, // IsLocalFunc: func() bool { // panic("mock out the IsLocal method") // }, @@ -39,6 +42,9 @@ var _ Extension = &ExtensionMock{} // // } type ExtensionMock struct { + // IsBinaryFunc mocks the IsBinary method. + IsBinaryFunc func() bool + // IsLocalFunc mocks the IsLocal method. IsLocalFunc func() bool @@ -56,6 +62,9 @@ type ExtensionMock struct { // calls tracks calls to the methods. calls struct { + // IsBinary holds details about calls to the IsBinary method. + IsBinary []struct { + } // IsLocal holds details about calls to the IsLocal method. IsLocal []struct { } @@ -72,6 +81,7 @@ type ExtensionMock struct { UpdateAvailable []struct { } } + lockIsBinary sync.RWMutex lockIsLocal sync.RWMutex lockName sync.RWMutex lockPath sync.RWMutex @@ -79,6 +89,32 @@ type ExtensionMock struct { lockUpdateAvailable sync.RWMutex } +// IsBinary calls IsBinaryFunc. +func (mock *ExtensionMock) IsBinary() bool { + if mock.IsBinaryFunc == nil { + panic("ExtensionMock.IsBinaryFunc: method is nil but Extension.IsBinary was just called") + } + callInfo := struct { + }{} + mock.lockIsBinary.Lock() + mock.calls.IsBinary = append(mock.calls.IsBinary, callInfo) + mock.lockIsBinary.Unlock() + return mock.IsBinaryFunc() +} + +// IsBinaryCalls gets all the calls that were made to IsBinary. +// Check the length with: +// len(mockedExtension.IsBinaryCalls()) +func (mock *ExtensionMock) IsBinaryCalls() []struct { +} { + var calls []struct { + } + mock.lockIsBinary.RLock() + calls = mock.calls.IsBinary + mock.lockIsBinary.RUnlock() + return calls +} + // IsLocal calls IsLocalFunc. func (mock *ExtensionMock) IsLocal() bool { if mock.IsLocalFunc == nil {