MCPcopy
hub / github.com/kite-org/kite / TestGenerateKubectlAgentName

Function TestGenerateKubectlAgentName

pkg/utils/utils_test.go:147–184  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

145}
146
147func 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}

Callers

nothing calls this directly

Calls 2

GenerateKubectlAgentNameFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected