MCPcopy
hub / github.com/cli/cli / TestManager_UpgradeExtensions

Function TestManager_UpgradeExtensions

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

Source from the content-addressed store, hash-verified

241}
242
243func TestManager_UpgradeExtensions(t *testing.T) {
244 dataDir := t.TempDir()
245 updateDir := t.TempDir()
246 dirOne := filepath.Join(dataDir, "extensions", "gh-hello")
247 dirTwo := filepath.Join(dataDir, "extensions", "gh-two")
248 assert.NoError(t, stubExtension(filepath.Join(dataDir, "extensions", "gh-hello", "gh-hello")))
249 assert.NoError(t, stubExtension(filepath.Join(dataDir, "extensions", "gh-two", "gh-two")))
250 assert.NoError(t, stubLocalExtension(dataDir, filepath.Join(dataDir, "extensions", "gh-local", "gh-local")))
251 ios, _, stdout, stderr := iostreams.Test()
252 gc, gcOne, gcTwo := &mockGitClient{}, &mockGitClient{}, &mockGitClient{}
253 gc.On("ForRepo", dirOne).Return(gcOne).Times(3)
254 gc.On("ForRepo", dirTwo).Return(gcTwo).Times(3)
255 gcOne.On("Remotes").Return(nil, nil).Once()
256 gcTwo.On("Remotes").Return(nil, nil).Once()
257 gcOne.On("Pull", "", "").Return(nil).Once()
258 gcTwo.On("Pull", "", "").Return(nil).Once()
259
260 m := newTestManager(dataDir, updateDir, nil, gc, ios)
261 exts, err := m.list(false)
262 assert.NoError(t, err)
263 assert.Equal(t, 3, len(exts))
264 for i := 0; i < 3; i++ {
265 exts[i].currentVersion = "old version"
266 exts[i].latestVersion = "new version"
267 }
268 err = m.upgradeExtensions(exts, false)
269 assert.NoError(t, err)
270 assert.Equal(t, heredoc.Doc(
271 `
272 [hello]: upgraded from old vers to new vers
273 [local]: local extensions can not be upgraded
274 [ two]: upgraded from old vers to new vers
275 `,
276 ), stdout.String())
277 assert.Equal(t, "", stderr.String())
278 gc.AssertExpectations(t)
279 gcOne.AssertExpectations(t)
280 gcTwo.AssertExpectations(t)
281}
282
283func TestManager_UpgradeExtensions_DryRun(t *testing.T) {
284 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.45

Tested by

no test coverage detected