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

Function TestManager_Install_binary_pinned

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

Source from the content-addressed store, hash-verified

1023}
1024
1025func TestManager_Install_binary_pinned(t *testing.T) {
1026 repo := ghrepo.NewWithHost("owner", "gh-bin-ext", "example.com")
1027
1028 reg := httpmock.Registry{}
1029 defer reg.Verify(t)
1030
1031 reg.Register(
1032 httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/latest"),
1033 httpmock.JSONResponse(
1034 release{
1035 Assets: []releaseAsset{
1036 {
1037 Name: "gh-bin-ext-windows-amd64.exe",
1038 APIURL: "https://example.com/release/cool",
1039 },
1040 },
1041 }))
1042 reg.Register(
1043 httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/tags/v1.6.3-pre"),
1044 httpmock.JSONResponse(
1045 release{
1046 Tag: "v1.6.3-pre",
1047 Assets: []releaseAsset{
1048 {
1049 Name: "gh-bin-ext-windows-amd64.exe",
1050 APIURL: "https://example.com/release/cool",
1051 },
1052 },
1053 }))
1054 reg.Register(
1055 httpmock.REST("GET", "release/cool"),
1056 httpmock.StringResponse("FAKE BINARY"))
1057
1058 ios, _, stdout, stderr := iostreams.Test()
1059 dataDir := t.TempDir()
1060 updateDir := t.TempDir()
1061
1062 m := newTestManager(dataDir, updateDir, &http.Client{Transport: &reg}, nil, ios)
1063
1064 err := m.Install(repo, "v1.6.3-pre")
1065 assert.NoError(t, err)
1066
1067 manifest, err := os.ReadFile(filepath.Join(dataDir, "extensions/gh-bin-ext", manifestName))
1068 assert.NoError(t, err)
1069
1070 var bm binManifest
1071 err = yaml.Unmarshal(manifest, &bm)
1072 assert.NoError(t, err)
1073
1074 assert.Equal(t, binManifest{
1075 Name: "gh-bin-ext",
1076 Owner: "owner",
1077 Host: "example.com",
1078 Tag: "v1.6.3-pre",
1079 IsPinned: true,
1080 Path: filepath.Join(dataDir, "extensions/gh-bin-ext/gh-bin-ext.exe"),
1081 }, bm)
1082

Callers

nothing calls this directly

Calls 12

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

Tested by

no test coverage detected