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

Function TestManager_UpgradeExtensions

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

Source from the content-addressed store, hash-verified

317}
318
319func TestManager_UpgradeExtensions(t *testing.T) {
320 dataDir := t.TempDir()
321 updateDir := t.TempDir()
322 dirOne := filepath.Join(dataDir, "extensions", "gh-hello")
323 dirTwo := filepath.Join(dataDir, "extensions", "gh-two")
324 assert.NoError(t, stubExtension(filepath.Join(dataDir, "extensions", "gh-hello", "gh-hello")))
325 assert.NoError(t, stubExtension(filepath.Join(dataDir, "extensions", "gh-two", "gh-two")))
326 assert.NoError(t, stubLocalExtension(dataDir, filepath.Join(dataDir, "extensions", "gh-local", "gh-local")))
327 ios, _, stdout, stderr := iostreams.Test()
328 gc, gcOne, gcTwo := &mockGitClient{}, &mockGitClient{}, &mockGitClient{}
329 gc.On("ForRepo", dirOne).Return(gcOne).Times(3)
330 gc.On("ForRepo", dirTwo).Return(gcTwo).Times(3)
331 gcOne.On("Remotes").Return(nil, nil).Once()
332 gcTwo.On("Remotes").Return(nil, nil).Once()
333 gcOne.On("Pull", "", "").Return(nil).Once()
334 gcTwo.On("Pull", "", "").Return(nil).Once()
335
336 m := newTestManager(dataDir, updateDir, nil, gc, ios)
337 exts, err := m.list(false)
338 assert.NoError(t, err)
339 assert.Equal(t, 3, len(exts))
340 for i := 0; i < 3; i++ {
341 exts[i].currentVersion = "old version"
342 exts[i].latestVersion = "new version"
343 }
344 err = m.upgradeExtensions(exts, false)
345 assert.NoError(t, err)
346 assert.Equal(t, heredoc.Doc(
347 `
348 [hello]: upgraded from old vers to new vers
349 [local]: local extensions can not be upgraded
350 [ two]: upgraded from old vers to new vers
351 `,
352 ), stdout.String())
353 assert.Equal(t, "", stderr.String())
354 gc.AssertExpectations(t)
355 gcOne.AssertExpectations(t)
356 gcTwo.AssertExpectations(t)
357}
358
359func TestManager_UpgradeExtensions_DryRun(t *testing.T) {
360 dataDir := t.TempDir()

Callers

nothing calls this directly

Calls 9

TestFunction · 0.92
stubExtensionFunction · 0.85
stubLocalExtensionFunction · 0.85
newTestManagerFunction · 0.85
JoinMethod · 0.80
listMethod · 0.80
EqualMethod · 0.80
upgradeExtensionsMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected