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

Function TestManager_Install_binary

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

Source from the content-addressed store, hash-verified

1187}
1188
1189func TestManager_Install_binary(t *testing.T) {
1190 fakeExtensionName := "gh-bin-ext"
1191 repo := ghrepo.NewWithHost("owner", fakeExtensionName, "example.com")
1192
1193 reg := httpmock.Registry{}
1194 defer reg.Verify(t)
1195
1196 reg.Register(
1197 httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/latest"),
1198 httpmock.JSONResponse(
1199 release{
1200 Assets: []releaseAsset{
1201 {
1202 Name: "gh-bin-ext-windows-amd64.exe",
1203 APIURL: "https://example.com/release/cool",
1204 },
1205 },
1206 }))
1207 reg.Register(
1208 httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/latest"),
1209 httpmock.JSONResponse(
1210 release{
1211 Tag: "v1.0.1",
1212 Assets: []releaseAsset{
1213 {
1214 Name: "gh-bin-ext-windows-amd64.exe",
1215 APIURL: "https://example.com/release/cool",
1216 },
1217 },
1218 }))
1219 reg.Register(
1220 httpmock.REST("GET", "release/cool"),
1221 httpmock.StringResponse("FAKE BINARY"))
1222
1223 ios, _, stdout, stderr := iostreams.Test()
1224 dataDir := t.TempDir()
1225 updateDir := t.TempDir()
1226
1227 // Create a temporary directory to simulate the local extension update state
1228 extensionUpdatePath := filepath.Join(updateDir, fakeExtensionName)
1229 require.NoError(t, stubExtensionUpdate(extensionUpdatePath))
1230
1231 m := newTestManager(dataDir, updateDir, &http.Client{Transport: &reg}, nil, ios)
1232
1233 err := m.Install(repo, "")
1234 assert.NoError(t, err)
1235
1236 manifest, err := os.ReadFile(filepath.Join(dataDir, "extensions/gh-bin-ext", manifestName))
1237 assert.NoError(t, err)
1238
1239 var bm binManifest
1240 err = yaml.Unmarshal(manifest, &bm)
1241 assert.NoError(t, err)
1242
1243 assert.Equal(t, binManifest{
1244 Name: fakeExtensionName,
1245 Owner: "owner",
1246 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