fix(hook): honour NetBox attribute restrictions in command aliases
Generated command aliases checked commands.*.match against hosts without
their status, site, role, platform and tenant, so a restriction such as
match: {platform: junos} produced no aliases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c87c2623ec
commit
c408d529a0
2 files changed
+21
-1
No files matched your search
@@ -416,3 +416,22 @@ func TestCustomAliasShellArgumentQuoting(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommandAliasesHonourNetBoxAttributes(t *testing.T) {
|
||||
cfg := config.Config{Commands: map[string]config.HostCommand{
|
||||
"cli": {AliasPrefix: "c", Args: []string{"cli", "{address}"}, Match: config.SSHMatch{Platform: "junos"}},
|
||||
}}
|
||||
entries := []cache.Entry{
|
||||
{Name: "sw1", Kind: "device", Platform: &config.Ref{Name: "Junos", Slug: "junos"}},
|
||||
{Name: "web1", Kind: "vm", Platform: &config.Ref{Slug: "ubuntu"}},
|
||||
}
|
||||
var got []string
|
||||
for _, a := range hook.BuildAliasEntries(entries, cfg) {
|
||||
if a.Command == "cli" {
|
||||
got = append(got, a.Name)
|
||||
}
|
||||
}
|
||||
if len(got) != 1 || got[0] != "csw1" {
|
||||
t.Fatalf("command aliases %v", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user