package cli import ( "testing" ) func TestResolveAlias(t *testing.T) { // Set up test environment variables t.Setenv("HOMELAB_DEPLOY_ALIAS_TEST", "deploy.test.all") t.Setenv("HOMELAB_DEPLOY_ALIAS_PROD", "deploy.prod.all") t.Setenv("HOMELAB_DEPLOY_ALIAS_PROD_DNS", "deploy.prod.role.dns") tests := []struct { name string input string want string }{ { name: "full subject unchanged", input: "deploy.prod.ns1", want: "deploy.prod.ns1", }, { name: "subject with multiple dots", input: "deploy.test.role.web", want: "deploy.test.role.web", }, { name: "lowercase alias", input: "test", want: "deploy.test.all", }, { name: "uppercase alias", input: "TEST", want: "deploy.test.all", }, { name: "mixed case alias", input: "TeSt", want: "deploy.test.all", }, { name: "alias with hyphen", input: "prod-dns", want: "deploy.prod.role.dns", }, { name: "alias with hyphen uppercase", input: "PROD-DNS", want: "deploy.prod.role.dns", }, { name: "unknown alias returns as-is", input: "unknown", want: "unknown", }, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { got := ResolveAlias(tc.input) if got != tc.want { t.Errorf("ResolveAlias(%q) = %q, want %q", tc.input, got, tc.want) } }) } } func TestIsAlias(t *testing.T) { tests := []struct { input string want bool }{ {"test", true}, {"prod-dns", true}, {"PROD", true}, {"deploy.test.all", false}, {"deploy.prod.ns1", false}, {"a.b", false}, } for _, tc := range tests { t.Run(tc.input, func(t *testing.T) { got := IsAlias(tc.input) if got != tc.want { t.Errorf("IsAlias(%q) = %v, want %v", tc.input, got, tc.want) } }) } } func TestGetAliasEnvVar(t *testing.T) { tests := []struct { alias string want string }{ {"test", "HOMELAB_DEPLOY_ALIAS_TEST"}, {"prod", "HOMELAB_DEPLOY_ALIAS_PROD"}, {"prod-dns", "HOMELAB_DEPLOY_ALIAS_PROD_DNS"}, {"my-long-alias", "HOMELAB_DEPLOY_ALIAS_MY_LONG_ALIAS"}, } for _, tc := range tests { t.Run(tc.alias, func(t *testing.T) { got := GetAliasEnvVar(tc.alias) if got != tc.want { t.Errorf("GetAliasEnvVar(%q) = %q, want %q", tc.alias, got, tc.want) } }) } }