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

Function TestManager_UpgradeExtensions_DryRun

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

Source from the content-addressed store, hash-verified

357}
358
359func TestManager_UpgradeExtensions_DryRun(t *testing.T) {
360 dataDir := t.TempDir()
361 updateDir := t.TempDir()
362 dirOne := filepath.Join(dataDir, "extensions", "gh-hello")
363 dirTwo := filepath.Join(dataDir, "extensions", "gh-two")
364 assert.NoError(t, stubExtension(filepath.Join(dataDir, "extensions", "gh-hello", "gh-hello")))
365 assert.NoError(t, stubExtension(filepath.Join(dataDir, "extensions", "gh-two", "gh-two")))
366 assert.NoError(t, stubLocalExtension(dataDir, filepath.Join(dataDir, "extensions", "gh-local", "gh-local")))
367 ios, _, stdout, stderr := iostreams.Test()
368 gc, gcOne, gcTwo := &mockGitClient{}, &mockGitClient{}, &mockGitClient{}
369 gc.On("ForRepo", dirOne).Return(gcOne).Twice()
370 gc.On("ForRepo", dirTwo).Return(gcTwo).Twice()
371 gcOne.On("Remotes").Return(nil, nil).Once()
372 gcTwo.On("Remotes").Return(nil, nil).Once()
373
374 m := newTestManager(dataDir, updateDir, nil, gc, ios)
375 m.EnableDryRunMode()
376 exts, err := m.list(false)
377 assert.NoError(t, err)
378 assert.Equal(t, 3, len(exts))
379 for i := 0; i < 3; i++ {
380 exts[i].currentVersion = fmt.Sprintf("%d", i)
381 exts[i].latestVersion = fmt.Sprintf("%d", i+1)
382 }
383 err = m.upgradeExtensions(exts, false)
384 assert.NoError(t, err)
385 assert.Equal(t, heredoc.Doc(
386 `
387 [hello]: would have upgraded from 0 to 1
388 [local]: local extensions can not be upgraded
389 [ two]: would have upgraded from 2 to 3
390 `,
391 ), stdout.String())
392 assert.Equal(t, "", stderr.String())
393 gc.AssertExpectations(t)
394 gcOne.AssertExpectations(t)
395 gcTwo.AssertExpectations(t)
396}
397
398func TestManager_UpgradeExtension_LocalExtension(t *testing.T) {
399 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.65

Tested by

no test coverage detected