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

Function TestManager_Install_local

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

Source from the content-addressed store, hash-verified

828}
829
830func TestManager_Install_local(t *testing.T) {
831 dataDir := t.TempDir()
832 updateDir := t.TempDir()
833 ios, _, stdout, stderr := iostreams.Test()
834 m := newTestManager(dataDir, updateDir, nil, nil, ios)
835 fakeExtensionName := "gh-local-ext"
836
837 // Create a temporary directory to simulate the local extension repo
838 extensionLocalPath := filepath.Join(dataDir, fakeExtensionName)
839 require.NoError(t, os.MkdirAll(extensionLocalPath, 0755))
840
841 // Create a fake executable in the local extension directory
842 fakeExtensionExecutablePath := filepath.Join(extensionLocalPath, fakeExtensionName)
843 require.NoError(t, stubExtension(fakeExtensionExecutablePath))
844
845 // Create a temporary directory to simulate the local extension update state
846 extensionUpdatePath := filepath.Join(updateDir, fakeExtensionName)
847 require.NoError(t, stubExtensionUpdate(extensionUpdatePath))
848
849 err := m.InstallLocal(extensionLocalPath)
850 require.NoError(t, err)
851
852 // This is the path to a file:
853 // on windows this is a file whose contents is a string describing the path to the local extension dir.
854 // on other platforms this file is a real symlink to the local extension dir.
855 extensionLinkFile := filepath.Join(dataDir, "extensions", fakeExtensionName)
856
857 if runtime.GOOS == "windows" {
858 // We don't create true symlinks on Windows, so check if we made a
859 // file with the correct contents to produce the symlink-like behavior
860 b, err := os.ReadFile(extensionLinkFile)
861 require.NoError(t, err)
862 assert.Equal(t, extensionLocalPath, string(b))
863 } else {
864 // Verify the created symlink points to the correct directory
865 linkTarget, err := os.Readlink(extensionLinkFile)
866 require.NoError(t, err)
867 assert.Equal(t, extensionLocalPath, linkTarget)
868 }
869 assert.Equal(t, "", stdout.String())
870 assert.Equal(t, "", stderr.String())
871 require.NoDirExistsf(t, extensionUpdatePath, "update directory should be removed")
872}
873
874func TestManager_Install_local_no_executable_found(t *testing.T) {
875 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.65

Tested by

no test coverage detected