From 0e2861a507cc079bed0f5883bd98f38f9cacee92 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Mon, 20 Sep 2021 17:05:19 -0500 Subject: [PATCH] WIP refactoring --- pkg/cmd/extension/manager.go | 8 +-- pkg/extensions/extension.go | 2 - pkg/extensions/manager_mock.go | 104 --------------------------------- 3 files changed, 4 insertions(+), 110 deletions(-) diff --git a/pkg/cmd/extension/manager.go b/pkg/cmd/extension/manager.go index 75cb4cfd9..db6ec76ba 100644 --- a/pkg/cmd/extension/manager.go +++ b/pkg/cmd/extension/manager.go @@ -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 diff --git a/pkg/extensions/extension.go b/pkg/extensions/extension.go index 99087fe04..16a3c7494 100644 --- a/pkg/extensions/extension.go +++ b/pkg/extensions/extension.go @@ -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 diff --git a/pkg/extensions/manager_mock.go b/pkg/extensions/manager_mock.go index b8d18dc6d..ce7a71ce8 100644 --- a/pkg/extensions/manager_mock.go +++ b/pkg/extensions/manager_mock.go @@ -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 {