40 lines
822 B
Go
40 lines
822 B
Go
package utils
|
|
|
|
import (
|
|
"codeberg.org/Pata1704/system_setup_tool/internal/shell"
|
|
"os/exec"
|
|
"testing"
|
|
)
|
|
|
|
func TestMax(t *testing.T) {
|
|
tests := []struct {
|
|
a, b, want int
|
|
}{
|
|
{1, 2, 2},
|
|
{5, 3, 5},
|
|
{0, 0, 0},
|
|
{-1, -5, -1},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
got := max(tt.a, tt.b)
|
|
if got != tt.want {
|
|
t.Errorf("max(%d, %d) = %d; want %d", tt.a, tt.b, got, tt.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestExecuteShellCommand(t *testing.T) {
|
|
// Mock execCommand
|
|
oldExecCommand := shell.ExecCommand
|
|
defer func() { shell.ExecCommand = oldExecCommand }()
|
|
|
|
shell.ExecCommand = func(command string, args ...string) *exec.Cmd {
|
|
return exec.Command("echo", "mocked command")
|
|
}
|
|
|
|
err := shell.ExecuteShellCommand("test command", "TEST_ENV=value")
|
|
if err != nil {
|
|
t.Errorf("executeShellCommand() error = %v; want nil", err)
|
|
}
|
|
}
|