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) } }