7c902cab3a
Release / release (push) Successful in 50s
- **Shortcuts**: Add hostname normalization with domain stripping and hyphen folding. Include alias generation for cached hosts. - **Shell Hook**: Automate 24h cache refresh trigger with shell startup hook. Add install/uninstall commands for bash, zsh, and fish. - **Wizard**: Extend setup wizard to configure shortcuts (domains, hyphen stripping) and default SSH port. - **Cache**: Add `GetByShortcut` for resolving hosts via normalized shortcuts. Implement `NeedsRefresh` / `SetRefreshed` logic for refresh timestamps. - **Tests**: Comprehensive unit tests for shortcuts, hook installation, cache refresh, and alias generation. - **Docs**: Update README with shortcuts, shell hook, and default SSH port configuration.
81 lines
2.0 KiB
Go
81 lines
2.0 KiB
Go
package shortcuts_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.zb-server.de/Sebi/ssh-netbox-wrapper/internal/config"
|
|
"git.zb-server.de/Sebi/ssh-netbox-wrapper/internal/shortcuts"
|
|
)
|
|
|
|
func TestNormalize(t *testing.T) {
|
|
cfg := config.ShortcutsConfig{
|
|
Domains: []string{".example.com", ".example.de"},
|
|
StripHyphens: true,
|
|
}
|
|
|
|
cases := []struct {
|
|
input string
|
|
want string
|
|
}{
|
|
{"fsn1-web01.example.com", "fsn1web01"},
|
|
{"fsn1-web01.example.de", "fsn1web01"},
|
|
{"FSN1-WEB01.EXAMPLE.COM", "fsn1web01"},
|
|
{"fsn1-web01", "fsn1web01"},
|
|
{"web01.example.com", "web01"},
|
|
{"web01.other.com", "web01.other.com"}, // unknown domain not stripped
|
|
}
|
|
|
|
for _, c := range cases {
|
|
got := shortcuts.Normalize(c.input, cfg)
|
|
if got != c.want {
|
|
t.Errorf("Normalize(%q) = %q, want %q", c.input, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestNormalizeNoHyphenStrip(t *testing.T) {
|
|
cfg := config.ShortcutsConfig{
|
|
Domains: []string{".example.com"},
|
|
StripHyphens: false,
|
|
}
|
|
|
|
got := shortcuts.Normalize("fsn1-web01.example.com", cfg)
|
|
want := "fsn1-web01"
|
|
if got != want {
|
|
t.Errorf("Normalize = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestAliasName_WithDomainAndHyphens(t *testing.T) {
|
|
cfg := config.ShortcutsConfig{
|
|
Domains: []string{".example.com"},
|
|
StripHyphens: true,
|
|
}
|
|
got := shortcuts.AliasName("fsn1-web01.example.com", cfg)
|
|
want := "fsn1web01"
|
|
if got != want {
|
|
t.Errorf("AliasName = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestAliasName_DotReplacement(t *testing.T) {
|
|
cfg := config.ShortcutsConfig{
|
|
Domains: []string{".example.com"},
|
|
}
|
|
// "web01.other.com" — domain not stripped, remaining dots → underscores
|
|
got := shortcuts.AliasName("web01.other.com", cfg)
|
|
want := "web01_other_com"
|
|
if got != want {
|
|
t.Errorf("AliasName = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestAliasName_NoConfig(t *testing.T) {
|
|
cfg := config.ShortcutsConfig{}
|
|
got := shortcuts.AliasName("web01.example.com", cfg)
|
|
want := "web01_example_com"
|
|
if got != want {
|
|
t.Errorf("AliasName = %q, want %q", got, want)
|
|
}
|
|
}
|