MCPcopy
hub / github.com/cli/cli / TestManager_Install_local

Function TestManager_Install_local

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

Source from the content-addressed store, hash-verified

752}
753
754func TestManager_Install_local(t *testing.T) {
755 dataDir := t.TempDir()
756 updateDir := t.TempDir()
757 ios, _, stdout, stderr := iostreams.Test()
758 m := newTestManager(dataDir, updateDir, nil, nil, ios)
759 fakeExtensionName := "gh-local-ext"
760
761 // Create a temporary directory to simulate the local extension repo
762 extensionLocalPath := filepath.Join(dataDir, fakeExtensionName)
763 require.NoError(t, os.MkdirAll(extensionLocalPath, 0755))
764
765 // Create a fake executable in the local extension directory
766 fakeExtensionExecutablePath := filepath.Join(extensionLocalPath, fakeExtensionName)
767 require.NoError(t, stubExtension(fakeExtensionExecutablePath))
768
769 // Create a temporary directory to simulate the local extension update state
770 extensionUpdatePath := filepath.Join(updateDir, fakeExtensionName)
771 require.NoError(t, stubExtensionUpdate(extensionUpdatePath))
772
773 err := m.InstallLocal(extensionLocalPath)
774 require.NoError(t, err)
775
776 // This is the path to a file:
777 // on windows this is a file whose contents is a string describing the path to the local extension dir.
778 // on other platforms this file is a real symlink to the local extension dir.
779 extensionLinkFile := filepath.Join(dataDir, "extensions", fakeExtensionName)
780
781 if runtime.GOOS == "windows" {
782 // We don't create true symlinks on Windows, so check if we made a
783 // file with the correct contents to produce the symlink-like behavior
784 b, err := os.ReadFile(extensionLinkFile)
785 require.NoError(t, err)
786 assert.Equal(t, extensionLocalPath, string(b))
787 } else {
788 // Verify the created symlink points to the correct directory
789 linkTarget, err := os.Readlink(extensionLinkFile)
790 require.NoError(t, err)
791 assert.Equal(t, extensionLocalPath, linkTarget)
792 }
793 assert.Equal(t, "", stdout.String())
794 assert.Equal(t, "", stderr.String())
795 require.NoDirExistsf(t, extensionUpdatePath, "update directory should be removed")
796}
797
798func TestManager_Install_local_no_executable_found(t *testing.T) {
799 dataDir := t.TempDir()

Callers

nothing calls this directly

Calls 8

TestFunction · 0.92
newTestManagerFunction · 0.85
stubExtensionFunction · 0.85
stubExtensionUpdateFunction · 0.85
JoinMethod · 0.80
EqualMethod · 0.80
InstallLocalMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected