MCPcopy
hub / github.com/cli/cli / TestManager_Install_binary

Function TestManager_Install_binary

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

Source from the content-addressed store, hash-verified

1111}
1112
1113func TestManager_Install_binary(t *testing.T) {
1114 fakeExtensionName := "gh-bin-ext"
1115 repo := ghrepo.NewWithHost("owner", fakeExtensionName, "example.com")
1116
1117 reg := httpmock.Registry{}
1118 defer reg.Verify(t)
1119
1120 reg.Register(
1121 httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/latest"),
1122 httpmock.JSONResponse(
1123 release{
1124 Assets: []releaseAsset{
1125 {
1126 Name: "gh-bin-ext-windows-amd64.exe",
1127 APIURL: "https://example.com/release/cool",
1128 },
1129 },
1130 }))
1131 reg.Register(
1132 httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/latest"),
1133 httpmock.JSONResponse(
1134 release{
1135 Tag: "v1.0.1",
1136 Assets: []releaseAsset{
1137 {
1138 Name: "gh-bin-ext-windows-amd64.exe",
1139 APIURL: "https://example.com/release/cool",
1140 },
1141 },
1142 }))
1143 reg.Register(
1144 httpmock.REST("GET", "release/cool"),
1145 httpmock.StringResponse("FAKE BINARY"))
1146
1147 ios, _, stdout, stderr := iostreams.Test()
1148 dataDir := t.TempDir()
1149 updateDir := t.TempDir()
1150
1151 // Create a temporary directory to simulate the local extension update state
1152 extensionUpdatePath := filepath.Join(updateDir, fakeExtensionName)
1153 require.NoError(t, stubExtensionUpdate(extensionUpdatePath))
1154
1155 m := newTestManager(dataDir, updateDir, &http.Client{Transport: &reg}, nil, ios)
1156
1157 err := m.Install(repo, "")
1158 assert.NoError(t, err)
1159
1160 manifest, err := os.ReadFile(filepath.Join(dataDir, "extensions/gh-bin-ext", manifestName))
1161 assert.NoError(t, err)
1162
1163 var bm binManifest
1164 err = yaml.Unmarshal(manifest, &bm)
1165 assert.NoError(t, err)
1166
1167 assert.Equal(t, binManifest{
1168 Name: fakeExtensionName,
1169 Owner: "owner",
1170 Host: "example.com",

Callers

nothing calls this directly

Calls 13

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

Tested by

no test coverage detected