MCPcopy
hub / github.com/cli/cli / TestManager_UpgradeExtensions_DryRun

Function TestManager_UpgradeExtensions_DryRun

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

Source from the content-addressed store, hash-verified

281}
282
283func TestManager_UpgradeExtensions_DryRun(t *testing.T) {
284 dataDir := t.TempDir()
285 updateDir := t.TempDir()
286 dirOne := filepath.Join(dataDir, "extensions", "gh-hello")
287 dirTwo := filepath.Join(dataDir, "extensions", "gh-two")
288 assert.NoError(t, stubExtension(filepath.Join(dataDir, "extensions", "gh-hello", "gh-hello")))
289 assert.NoError(t, stubExtension(filepath.Join(dataDir, "extensions", "gh-two", "gh-two")))
290 assert.NoError(t, stubLocalExtension(dataDir, filepath.Join(dataDir, "extensions", "gh-local", "gh-local")))
291 ios, _, stdout, stderr := iostreams.Test()
292 gc, gcOne, gcTwo := &mockGitClient{}, &mockGitClient{}, &mockGitClient{}
293 gc.On("ForRepo", dirOne).Return(gcOne).Twice()
294 gc.On("ForRepo", dirTwo).Return(gcTwo).Twice()
295 gcOne.On("Remotes").Return(nil, nil).Once()
296 gcTwo.On("Remotes").Return(nil, nil).Once()
297
298 m := newTestManager(dataDir, updateDir, nil, gc, ios)
299 m.EnableDryRunMode()
300 exts, err := m.list(false)
301 assert.NoError(t, err)
302 assert.Equal(t, 3, len(exts))
303 for i := 0; i < 3; i++ {
304 exts[i].currentVersion = fmt.Sprintf("%d", i)
305 exts[i].latestVersion = fmt.Sprintf("%d", i+1)
306 }
307 err = m.upgradeExtensions(exts, false)
308 assert.NoError(t, err)
309 assert.Equal(t, heredoc.Doc(
310 `
311 [hello]: would have upgraded from 0 to 1
312 [local]: local extensions can not be upgraded
313 [ two]: would have upgraded from 2 to 3
314 `,
315 ), stdout.String())
316 assert.Equal(t, "", stderr.String())
317 gc.AssertExpectations(t)
318 gcOne.AssertExpectations(t)
319 gcTwo.AssertExpectations(t)
320}
321
322func TestManager_UpgradeExtension_LocalExtension(t *testing.T) {
323 dataDir := t.TempDir()

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected