45 lines
1 KiB
Go
45 lines
1 KiB
Go
package packagemanager
|
|
|
|
import (
|
|
"os/exec"
|
|
"system_setup_tool/internal/shell"
|
|
"testing"
|
|
)
|
|
|
|
func TestPipxManager_Name(t *testing.T) {
|
|
pm := &PipxManager{}
|
|
if name := pm.Name(); name != "Pipx" {
|
|
t.Errorf("Expected name to be 'Pipx', got %s", name)
|
|
}
|
|
}
|
|
|
|
func TestPipxManager_InstallManager(t *testing.T) {
|
|
pm := &PipxManager{}
|
|
|
|
// Mock exec.LookPath
|
|
shell.ExecLookPath = func(file string) (string, error) {
|
|
if file == "pipx" {
|
|
return "/usr/bin/pipx", nil
|
|
}
|
|
return "", exec.ErrNotFound
|
|
}
|
|
defer func() { shell.ExecLookPath = exec.LookPath }()
|
|
|
|
if err := pm.InstallManager(); err != nil {
|
|
t.Errorf("Expected no error, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestPipxManager_InstallPackage(t *testing.T) {
|
|
pm := &PipxManager{}
|
|
|
|
// Mock exec.Command
|
|
shell.ExecCommand = func(name string, arg ...string) *exec.Cmd {
|
|
return exec.Command("echo", "mocked pipx install")
|
|
}
|
|
defer func() { shell.ExecCommand = exec.Command }()
|
|
|
|
if err := pm.InstallPackage("test-package"); err != nil {
|
|
t.Errorf("Expected no error, got %v", err)
|
|
}
|
|
}
|