MCPcopy
hub / github.com/cli/cli / TestManager_Install_git

Function TestManager_Install_git

pkg/cmd/extension/manager_test.go:823–868  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

821}
822
823func TestManager_Install_git(t *testing.T) {
824 dataDir := t.TempDir()
825 updateDir := t.TempDir()
826
827 reg := httpmock.Registry{}
828 defer reg.Verify(t)
829 client := http.Client{Transport: &reg}
830
831 ios, _, stdout, stderr := iostreams.Test()
832
833 fakeExtensionName := "gh-some-ext"
834 extensionDir := filepath.Join(dataDir, "extensions", fakeExtensionName)
835 gc := &mockGitClient{}
836 gc.On("Clone", "https://github.com/owner/gh-some-ext.git", []string{extensionDir}).Return("", nil).Once()
837
838 // Create a temporary directory to simulate the local extension update state
839 extensionUpdatePath := filepath.Join(updateDir, fakeExtensionName)
840 require.NoError(t, stubExtensionUpdate(extensionUpdatePath))
841
842 m := newTestManager(dataDir, updateDir, &client, gc, ios)
843
844 reg.Register(
845 httpmock.REST("GET", "repos/owner/gh-some-ext/releases/latest"),
846 httpmock.JSONResponse(
847 release{
848 Assets: []releaseAsset{
849 {
850 Name: "not-a-binary",
851 APIURL: "https://example.com/release/cool",
852 },
853 },
854 }))
855 reg.Register(
856 httpmock.REST("GET", "repos/owner/gh-some-ext/contents/gh-some-ext"),
857 httpmock.StringResponse("script"))
858
859 repo := ghrepo.New("owner", fakeExtensionName)
860
861 err := m.Install(repo, "")
862 assert.NoError(t, err)
863 assert.Equal(t, "", stdout.String())
864 assert.Equal(t, "", stderr.String())
865 gc.AssertExpectations(t)
866
867 assert.NoDirExistsf(t, extensionUpdatePath, "update directory should be removed")
868}
869
870func TestManager_Install_not_installable(t *testing.T) {
871 dataDir := t.TempDir()

Callers

nothing calls this directly

Calls 13

VerifyMethod · 0.95
RegisterMethod · 0.95
TestFunction · 0.92
RESTFunction · 0.92
JSONResponseFunction · 0.92
StringResponseFunction · 0.92
NewFunction · 0.92
stubExtensionUpdateFunction · 0.85
newTestManagerFunction · 0.85
JoinMethod · 0.80
EqualMethod · 0.80
InstallMethod · 0.65

Tested by

no test coverage detected