45 lines
1 KiB
Go
45 lines
1 KiB
Go
// homebrew_test.go
|
|
package main
|
|
|
|
import (
|
|
"os/exec"
|
|
"testing"
|
|
)
|
|
|
|
func TestHomebrewManager_Name(t *testing.T) {
|
|
hm := &HomebrewManager{}
|
|
if name := hm.Name(); name != "Homebrew" {
|
|
t.Errorf("Expected name to be 'Homebrew', got %s", name)
|
|
}
|
|
}
|
|
|
|
func TestHomebrewManager_InstallManager(t *testing.T) {
|
|
hm := &HomebrewManager{}
|
|
|
|
// Mock exec.LookPath and executeShellCommand
|
|
execLookPath = func(file string) (string, error) {
|
|
if file == "brew" {
|
|
return "/usr/local/bin/brew", nil
|
|
}
|
|
return "", exec.ErrNotFound
|
|
}
|
|
defer func() { execLookPath = exec.LookPath }()
|
|
|
|
if err := hm.InstallManager(); err != nil {
|
|
t.Errorf("Expected no error, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestHomebrewManager_InstallPackage(t *testing.T) {
|
|
hm := &HomebrewManager{}
|
|
|
|
// Mock exec.Command
|
|
execCommand = func(name string, arg ...string) *exec.Cmd {
|
|
return exec.Command("echo", "mocked brew install")
|
|
}
|
|
defer func() { execCommand = exec.Command }()
|
|
|
|
if err := hm.InstallPackage("test-package"); err != nil {
|
|
t.Errorf("Expected no error, got %v", err)
|
|
}
|
|
}
|