MCPcopy
hub / github.com/kubernetes/kubectl / TestApplySetParentValidation

Function TestApplySetParentValidation

pkg/cmd/apply/apply_test.go:2297–2419  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2295}
2296
2297func 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)

Callers

nothing calls this directly

Calls 10

WithClientConfigMethod · 0.95
AddFlagsMethod · 0.95
CleanupMethod · 0.95
WithNamespaceMethod · 0.95
ToOptionsMethod · 0.95
NewApplyFlagsFunction · 0.85
ToRawKubeConfigLoaderMethod · 0.45
RunMethod · 0.45
ValidateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…