MCPcopy Create free account
hub / github.com/cli/cli / TestManager_Install_git

Function TestManager_Install_git

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

Source from the content-addressed store, hash-verified

897}
898
899func TestManager_Install_git(t *testing.T) {
900 dataDir := t.TempDir()
901 updateDir := t.TempDir()
902
903 reg := httpmock.Registry{}
904 defer reg.Verify(t)
905 client := http.Client{Transport: &reg}
906
907 ios, _, stdout, stderr := iostreams.Test()
908
909 fakeExtensionName := "gh-some-ext"
910 extensionDir := filepath.Join(dataDir, "extensions", fakeExtensionName)
911 gc := &mockGitClient{}
912 gc.On("Clone", "https://github.com/owner/gh-some-ext.git", []string{extensionDir}).Return("", nil).Once()
913
914 // Create a temporary directory to simulate the local extension update state
915 extensionUpdatePath := filepath.Join(updateDir, fakeExtensionName)
916 require.NoError(t, stubExtensionUpdate(extensionUpdatePath))
917
918 m := newTestManager(dataDir, updateDir, &client, gc, ios)
919
920 reg.Register(
921 httpmock.REST("GET", "repos/owner/gh-some-ext/releases/latest"),
922 httpmock.JSONResponse(
923 release{
924 Assets: []releaseAsset{
925 {
926 Name: "not-a-binary",
927 APIURL: "https://example.com/release/cool",
928 },
929 },
930 }))
931 reg.Register(
932 httpmock.REST("GET", "repos/owner/gh-some-ext/contents/gh-some-ext"),
933 httpmock.JSONResponse(map[string]string{"type": "file"}))
934
935 repo := ghrepo.New("owner", fakeExtensionName)
936
937 err := m.Install(repo, "")
938 assert.NoError(t, err)
939 assert.Equal(t, "", stdout.String())
940 assert.Equal(t, "", stderr.String())
941 gc.AssertExpectations(t)
942
943 assert.NoDirExistsf(t, extensionUpdatePath, "update directory should be removed")
944}
945
946func TestManager_Install_not_installable(t *testing.T) {
947 dataDir := t.TempDir()

Callers

nothing calls this directly

Calls 12

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

Tested by

no test coverage detected