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

Function TestManager_Install_amd64_when_supported

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

Source from the content-addressed store, hash-verified

1258}
1259
1260func TestManager_Install_amd64_when_supported(t *testing.T) {
1261 repo := ghrepo.NewWithHost("owner", "gh-bin-ext", "example.com")
1262
1263 reg := httpmock.Registry{}
1264 defer reg.Verify(t)
1265 client := http.Client{Transport: &reg}
1266
1267 reg.Register(
1268 httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/latest"),
1269 httpmock.JSONResponse(
1270 release{
1271 Assets: []releaseAsset{
1272 {
1273 Name: "gh-bin-ext-darwin-amd64",
1274 APIURL: "https://example.com/release/cool",
1275 },
1276 },
1277 }))
1278 reg.Register(
1279 httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/latest"),
1280 httpmock.JSONResponse(
1281 release{
1282 Tag: "v1.0.1",
1283 Assets: []releaseAsset{
1284 {
1285 Name: "gh-bin-ext-darwin-amd64",
1286 APIURL: "https://example.com/release/cool",
1287 },
1288 },
1289 }))
1290 reg.Register(
1291 httpmock.REST("GET", "release/cool"),
1292 httpmock.StringResponse("FAKE BINARY"))
1293
1294 ios, _, stdout, stderr := iostreams.Test()
1295 dataDir := t.TempDir()
1296 updateDir := t.TempDir()
1297
1298 m := newTestManager(dataDir, updateDir, &client, nil, ios)
1299 m.platform = func() (string, string) {
1300 return "darwin-arm64", ""
1301 }
1302
1303 originalHasRosetta := hasRosetta
1304 t.Cleanup(func() { hasRosetta = originalHasRosetta })
1305 hasRosetta = func() bool {
1306 return true
1307 }
1308
1309 err := m.Install(repo, "")
1310 assert.NoError(t, err)
1311
1312 manifest, err := os.ReadFile(filepath.Join(dataDir, "extensions/gh-bin-ext", manifestName))
1313 assert.NoError(t, err)
1314
1315 var bm binManifest
1316 err = yaml.Unmarshal(manifest, &bm)
1317 assert.NoError(t, err)

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