implemented shell_exec
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user