WIP refactoring

This commit is contained in:
vilmibm 2021-09-20 17:05:19 -05:00
parent f5d269ebad
commit 0e2861a507
3 changed files with 4 additions and 110 deletions

View file

@ -195,7 +195,7 @@ func (m *Manager) Install(client *http.Client, repo ghrepo.Interface, io *iostre
return fmt.Errorf("could not check for binary extension: %w", err)
}
if isBin {
return m.InstallBin(client, repo)
return m.installBin(client, repo)
}
hs, err := hasScript(client, repo)
@ -208,10 +208,10 @@ func (m *Manager) Install(client *http.Client, repo ghrepo.Interface, io *iostre
}
protocol, _ := cfg.Get(repo.RepoHost(), "git_protocol")
return m.InstallGit(ghrepo.FormatRemoteURL(repo, protocol), io.Out, io.ErrOut)
return m.installGit(ghrepo.FormatRemoteURL(repo, protocol), io.Out, io.ErrOut)
}
func (m *Manager) InstallBin(client *http.Client, repo ghrepo.Interface) error {
func (m *Manager) installBin(client *http.Client, repo ghrepo.Interface) error {
var r *release
r, err := fetchLatestRelease(client, repo)
if err != nil {
@ -276,7 +276,7 @@ func (m *Manager) InstallBin(client *http.Client, repo ghrepo.Interface) error {
return nil
}
func (m *Manager) InstallGit(cloneURL string, stdout, stderr io.Writer) error {
func (m *Manager) installGit(cloneURL string, stdout, stderr io.Writer) error {
exe, err := m.lookPath("git")
if err != nil {
return err

View file

@ -22,8 +22,6 @@ type Extension interface {
type ExtensionManager interface {
List(includeMetadata bool) []Extension
Install(*http.Client, ghrepo.Interface, *iostreams.IOStreams, config.Config) error
InstallBin(*http.Client, ghrepo.Interface) error
InstallGit(string, io.Writer, io.Writer) error
InstallLocal(dir string) error
Upgrade(name string, force bool, stdout, stderr io.Writer) error
Remove(name string) error

View file

@ -31,12 +31,6 @@ var _ ExtensionManager = &ExtensionManagerMock{}
// InstallFunc: func(client *http.Client, interfaceMoqParam ghrepo.Interface, iOStreams *iostreams.IOStreams, configMoqParam config.Config) error {
// panic("mock out the Install method")
// },
// InstallBinFunc: func(client *http.Client, interfaceMoqParam ghrepo.Interface) error {
// panic("mock out the InstallBin method")
// },
// InstallGitFunc: func(s string, writer1 io.Writer, writer2 io.Writer) error {
// panic("mock out the InstallGit method")
// },
// InstallLocalFunc: func(dir string) error {
// panic("mock out the InstallLocal method")
// },
@ -65,12 +59,6 @@ type ExtensionManagerMock struct {
// InstallFunc mocks the Install method.
InstallFunc func(client *http.Client, interfaceMoqParam ghrepo.Interface, iOStreams *iostreams.IOStreams, configMoqParam config.Config) error
// InstallBinFunc mocks the InstallBin method.
InstallBinFunc func(client *http.Client, interfaceMoqParam ghrepo.Interface) error
// InstallGitFunc mocks the InstallGit method.
InstallGitFunc func(s string, writer1 io.Writer, writer2 io.Writer) error
// InstallLocalFunc mocks the InstallLocal method.
InstallLocalFunc func(dir string) error
@ -112,22 +100,6 @@ type ExtensionManagerMock struct {
// ConfigMoqParam is the configMoqParam argument value.
ConfigMoqParam config.Config
}
// InstallBin holds details about calls to the InstallBin method.
InstallBin []struct {
// Client is the client argument value.
Client *http.Client
// InterfaceMoqParam is the interfaceMoqParam argument value.
InterfaceMoqParam ghrepo.Interface
}
// InstallGit holds details about calls to the InstallGit method.
InstallGit []struct {
// S is the s argument value.
S string
// Writer1 is the writer1 argument value.
Writer1 io.Writer
// Writer2 is the writer2 argument value.
Writer2 io.Writer
}
// InstallLocal holds details about calls to the InstallLocal method.
InstallLocal []struct {
// Dir is the dir argument value.
@ -158,8 +130,6 @@ type ExtensionManagerMock struct {
lockCreate sync.RWMutex
lockDispatch sync.RWMutex
lockInstall sync.RWMutex
lockInstallBin sync.RWMutex
lockInstallGit sync.RWMutex
lockInstallLocal sync.RWMutex
lockList sync.RWMutex
lockRemove sync.RWMutex
@ -283,80 +253,6 @@ func (mock *ExtensionManagerMock) InstallCalls() []struct {
return calls
}
// InstallBin calls InstallBinFunc.
func (mock *ExtensionManagerMock) InstallBin(client *http.Client, interfaceMoqParam ghrepo.Interface) error {
if mock.InstallBinFunc == nil {
panic("ExtensionManagerMock.InstallBinFunc: method is nil but ExtensionManager.InstallBin was just called")
}
callInfo := struct {
Client *http.Client
InterfaceMoqParam ghrepo.Interface
}{
Client: client,
InterfaceMoqParam: interfaceMoqParam,
}
mock.lockInstallBin.Lock()
mock.calls.InstallBin = append(mock.calls.InstallBin, callInfo)
mock.lockInstallBin.Unlock()
return mock.InstallBinFunc(client, interfaceMoqParam)
}
// InstallBinCalls gets all the calls that were made to InstallBin.
// Check the length with:
// len(mockedExtensionManager.InstallBinCalls())
func (mock *ExtensionManagerMock) InstallBinCalls() []struct {
Client *http.Client
InterfaceMoqParam ghrepo.Interface
} {
var calls []struct {
Client *http.Client
InterfaceMoqParam ghrepo.Interface
}
mock.lockInstallBin.RLock()
calls = mock.calls.InstallBin
mock.lockInstallBin.RUnlock()
return calls
}
// InstallGit calls InstallGitFunc.
func (mock *ExtensionManagerMock) InstallGit(s string, writer1 io.Writer, writer2 io.Writer) error {
if mock.InstallGitFunc == nil {
panic("ExtensionManagerMock.InstallGitFunc: method is nil but ExtensionManager.InstallGit was just called")
}
callInfo := struct {
S string
Writer1 io.Writer
Writer2 io.Writer
}{
S: s,
Writer1: writer1,
Writer2: writer2,
}
mock.lockInstallGit.Lock()
mock.calls.InstallGit = append(mock.calls.InstallGit, callInfo)
mock.lockInstallGit.Unlock()
return mock.InstallGitFunc(s, writer1, writer2)
}
// InstallGitCalls gets all the calls that were made to InstallGit.
// Check the length with:
// len(mockedExtensionManager.InstallGitCalls())
func (mock *ExtensionManagerMock) InstallGitCalls() []struct {
S string
Writer1 io.Writer
Writer2 io.Writer
} {
var calls []struct {
S string
Writer1 io.Writer
Writer2 io.Writer
}
mock.lockInstallGit.RLock()
calls = mock.calls.InstallGit
mock.lockInstallGit.RUnlock()
return calls
}
// InstallLocal calls InstallLocalFunc.
func (mock *ExtensionManagerMock) InstallLocal(dir string) error {
if mock.InstallLocalFunc == nil {