v1
Test / test (push) Successful in 3m36s
Release / release (push) Successful in 7m31s

This commit is contained in:
Sebastian Unterschütz committed 2026-11-17 19:00:44 +01:00
commit 8d4915543e
132 files changed
+20628

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
package config
import "testing"
func TestValidateCommands(t *testing.T) {
for _, tc := range []struct {
name string
command HostCommand
valid bool
}{
{"mtr", HostCommand{AliasPrefix: "m", Args: []string{"mtr", "{address}"}}, true},
{"ping", HostCommand{Args: []string{"ping", "-c", "3", "{host}"}}, true},
{"inspect", HostCommand{Args: []string{"echo", "{target}"}}, true},
{"", HostCommand{Args: []string{"echo", "{host}"}}, false},
{"bad name", HostCommand{Args: []string{"echo", "{host}"}}, false},
{"netssh", HostCommand{Args: []string{"echo", "{host}"}}, false},
{"bad", HostCommand{AliasPrefix: "m;", Args: []string{"mtr", "{address}"}}, false},
{"bad", HostCommand{}, false},
{"bad", HostCommand{Args: []string{"", "{host}"}}, false},
{"bad", HostCommand{Args: []string{"{host}", "{address}"}}, false},
{"bad", HostCommand{Args: []string{"mtr", "{adress}"}}, false},
{"bad", HostCommand{Args: []string{"mtr"}}, false},
{"bad", HostCommand{Args: []string{"mtr", "{host}\x00"}}, false},
} {
cfg := Config{Commands: map[string]HostCommand{tc.name: tc.command}}
if err := cfg.ValidateCommands(); (err == nil) != tc.valid {
t.Errorf("%+v: %v", tc, err)
}
}
cfg := Config{Commands: map[string]HostCommand{
"mtr": {AliasPrefix: "m", Args: []string{"mtr", "{address}"}},
"ping": {AliasPrefix: "m", Args: []string{"ping", "{address}"}},
}}
if cfg.ValidateCommands() == nil {
t.Fatal("duplicate prefixes accepted")
}
}