(t *testing.T)
| 2295 | } |
| 2296 | |
| 2297 | func TestApplySetParentValidation(t *testing.T) { |
| 2298 | for name, test := range map[string]struct { |
| 2299 | applysetFlag string |
| 2300 | namespaceFlag string |
| 2301 | setup func(*testing.T, *cmdtesting.TestFactory) |
| 2302 | expectParentKind string |
| 2303 | expectBlankParentNs bool |
| 2304 | expectErr string |
| 2305 | }{ |
| 2306 | "parent type must be valid": { |
| 2307 | applysetFlag: "doesnotexist/thename", |
| 2308 | expectErr: "invalid parent reference \"doesnotexist/thename\": no matches for /, Resource=doesnotexist", |
| 2309 | }, |
| 2310 | "parent name must be present": { |
| 2311 | applysetFlag: "secret/", |
| 2312 | expectErr: "invalid parent reference \"secret/\": name cannot be blank", |
| 2313 | }, |
| 2314 | "configmap parents are valid": { |
| 2315 | applysetFlag: "configmap/thename", |
| 2316 | namespaceFlag: "mynamespace", |
| 2317 | expectParentKind: "ConfigMap", |
| 2318 | }, |
| 2319 | "secret parents are valid": { |
| 2320 | applysetFlag: "secret/thename", |
| 2321 | namespaceFlag: "mynamespace", |
| 2322 | expectParentKind: "Secret", |
| 2323 | }, |
| 2324 | "plural resource works": { |
| 2325 | applysetFlag: "secrets/thename", |
| 2326 | namespaceFlag: "mynamespace", |
| 2327 | expectParentKind: "Secret", |
| 2328 | }, |
| 2329 | "other namespaced builtin parents types are correctly parsed but invalid": { |
| 2330 | applysetFlag: "deployments.apps/thename", |
| 2331 | expectParentKind: "Deployment", |
| 2332 | expectErr: "[namespace is required to use namespace-scoped ApplySet, resource \"apps/v1, Resource=deployments\" is not permitted as an ApplySet parent]", |
| 2333 | }, |
| 2334 | "non-namespaced builtin types are correctly parsed but invalid": { |
| 2335 | applysetFlag: "namespaces/thename", |
| 2336 | expectParentKind: "Namespace", |
| 2337 | namespaceFlag: "somenamespace", |
| 2338 | expectBlankParentNs: true, |
| 2339 | expectErr: "resource \"/v1, Resource=namespaces\" is not permitted as an ApplySet parent", |
| 2340 | }, |
| 2341 | "parent namespace should use the value of the namespace flag": { |
| 2342 | applysetFlag: "mysecret", |
| 2343 | namespaceFlag: "mynamespace", |
| 2344 | expectParentKind: "Secret", |
| 2345 | }, |
| 2346 | "parent namespace should not use the default namespace from ClientConfig": { |
| 2347 | applysetFlag: "mysecret", |
| 2348 | setup: func(t *testing.T, f *cmdtesting.TestFactory) { |
| 2349 | // by default, the value "default" is used for the namespace |
| 2350 | // make sure this assumption still holds |
| 2351 | ns, overridden, err := f.ToRawKubeConfigLoader().Namespace() |
| 2352 | require.NoError(t, err) |
| 2353 | require.Falsef(t, overridden, "namespace unexpectedly overridden") |
| 2354 | require.Equal(t, "default", ns) |
nothing calls this directly
no test coverage detected
searching dependent graphs…