implemented shell_exec

This commit is contained in:
Luxferre
2026-03-21 17:11:17 +02:00
parent a2af89e61f
commit 6e2294cb48
6 changed files with 101 additions and 2 deletions
+17
View File
@@ -6,6 +6,23 @@ import (
"testing"
)
func TestShellExecHandler(t *testing.T) {
// Success
got, err := shellExecHandler(map[string]interface{}{"command": "echo hello"})
if err != nil { t.Fatal(err) }
if strings.TrimSpace(got) != "hello" { t.Errorf("expected hello, got %s", got) }
// Failure
got, err = shellExecHandler(map[string]interface{}{"command": "ls /nonexistent-file-path-that-should-not-exist"})
if err != nil { t.Fatal(err) }
if !strings.Contains(got, "Error:") { t.Errorf("expected error in output, got %s", got) }
// Empty
got, err = shellExecHandler(map[string]interface{}{"command": "true"})
if err != nil { t.Fatal(err) }
if got != "(empty output)" { t.Errorf("expected empty output, got %s", got) }
}
func TestHashLine(t *testing.T) {
line := "hello world"
h1 := hashLine(line)