(t *testing.T)
| 145 | } |
| 146 | |
| 147 | func TestGenerateKubectlAgentName(t *testing.T) { |
| 148 | testCases := []struct { |
| 149 | name string |
| 150 | username string |
| 151 | prefix string |
| 152 | }{ |
| 153 | { |
| 154 | name: "sanitizes username", |
| 155 | username: "Alice/Dev", |
| 156 | prefix: common.KubectlTerminalPodName + "-alice-dev-", |
| 157 | }, |
| 158 | { |
| 159 | name: "falls back to user", |
| 160 | username: "!!!", |
| 161 | prefix: common.KubectlTerminalPodName + "-user-", |
| 162 | }, |
| 163 | { |
| 164 | name: "truncates long username", |
| 165 | username: strings.Repeat("a", 80), |
| 166 | prefix: common.KubectlTerminalPodName + "-", |
| 167 | }, |
| 168 | } |
| 169 | |
| 170 | for _, tc := range testCases { |
| 171 | t.Run(tc.name, func(t *testing.T) { |
| 172 | got := GenerateKubectlAgentName(tc.username) |
| 173 | if !strings.HasPrefix(got, tc.prefix) { |
| 174 | t.Fatalf("GenerateKubectlAgentName(%q) = %q, want prefix %q", tc.username, got, tc.prefix) |
| 175 | } |
| 176 | if len(got) > 63 { |
| 177 | t.Fatalf("GenerateKubectlAgentName(%q) = %q, want length <= 63", tc.username, got) |
| 178 | } |
| 179 | if errs := validation.IsDNS1123Subdomain(got); len(errs) > 0 { |
| 180 | t.Fatalf("GenerateKubectlAgentName(%q) = %q, invalid DNS subdomain: %v", tc.username, got, errs) |
| 181 | } |
| 182 | }) |
| 183 | } |
| 184 | } |
nothing calls this directly
no test coverage detected