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

Function TestManager_Install_git_pinned

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

Source from the content-addressed store, hash-verified

977}
978
979func TestManager_Install_git_pinned(t *testing.T) {
980 dataDir := t.TempDir()
981 updateDir := t.TempDir()
982
983 reg := httpmock.Registry{}
984 defer reg.Verify(t)
985 client := http.Client{Transport: &reg}
986
987 ios, _, stdout, stderr := iostreams.Test()
988
989 extensionDir := filepath.Join(dataDir, "extensions", "gh-cool-ext")
990 gc, gcOne := &mockGitClient{}, &mockGitClient{}
991 gc.On("ForRepo", extensionDir).Return(gcOne).Once()
992 gc.On("Clone", "https://github.com/owner/gh-cool-ext.git", []string{extensionDir}).Return("", nil).Once()
993 gcOne.On("CheckoutBranch", "abcd1234").Return(nil).Once()
994
995 m := newTestManager(dataDir, updateDir, &client, gc, ios)
996
997 reg.Register(
998 httpmock.REST("GET", "repos/owner/gh-cool-ext/releases/latest"),
999 httpmock.JSONResponse(
1000 release{
1001 Assets: []releaseAsset{
1002 {
1003 Name: "not-a-binary",
1004 APIURL: "https://example.com/release/cool",
1005 },
1006 },
1007 }))
1008 reg.Register(
1009 httpmock.REST("GET", "repos/owner/gh-cool-ext/commits/some-ref"),
1010 httpmock.StringResponse("abcd1234"))
1011 reg.Register(
1012 httpmock.REST("GET", "repos/owner/gh-cool-ext/contents/gh-cool-ext"),
1013 httpmock.JSONResponse(map[string]string{"type": "file"}))
1014
1015 _ = os.MkdirAll(filepath.Join(m.installDir(), "gh-cool-ext"), 0700)
1016 repo := ghrepo.New("owner", "gh-cool-ext")
1017 err := m.Install(repo, "some-ref")
1018 assert.NoError(t, err)
1019 assert.Equal(t, "", stderr.String())
1020 assert.Equal(t, "", stdout.String())
1021 gc.AssertExpectations(t)
1022 gcOne.AssertExpectations(t)
1023}
1024
1025func TestManager_Install_binary_pinned(t *testing.T) {
1026 repo := ghrepo.NewWithHost("owner", "gh-bin-ext", "example.com")

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
newTestManagerFunction · 0.85
JoinMethod · 0.80
installDirMethod · 0.80
EqualMethod · 0.80
InstallMethod · 0.65

Tested by

no test coverage detected