dispatch binary extensions directly

This commit is contained in:
nate smith 2021-10-19 14:15:48 -05:00
parent d84a7c7fa7
commit 42ce8faafa
4 changed files with 47 additions and 2 deletions

View file

@ -48,3 +48,7 @@ func (e *Extension) UpdateAvailable() bool {
}
return true
}
func (e *Extension) IsBinary() bool {
return e.kind == BinaryKind
}

View file

@ -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()

View file

@ -13,6 +13,7 @@ type Extension interface {
URL() string
IsLocal() bool
UpdateAvailable() bool
IsBinary() bool
}
//go:generate moq -rm -out manager_mock.go . ExtensionManager

View file

@ -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 {