forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubernetes#54938 from nikhita/kubectl-explain-trai…
…ling-period Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. kubectl explain: ignore trailing period Fixes kubernetes#54891 Ignores trailing period for kubectl explain i.e. `kubectl explain ingress.spec.rules.http.paths.` is valid and defaults to `kubectl explain ingress.spec.rules.http.paths`. **Release note**: ```release-note NONE ```
- Loading branch information
Showing
5 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package explain | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"k8s.io/apimachinery/pkg/api/meta" | ||
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing" | ||
) | ||
|
||
func TestSplitAndParseResourceRequest(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
inresource string | ||
|
||
expectedInResource string | ||
expectedFieldsPath []string | ||
expectedErr bool | ||
}{ | ||
{ | ||
name: "no trailing period", | ||
inresource: "field1.field2.field3", | ||
|
||
expectedInResource: "field1", | ||
expectedFieldsPath: []string{"field2", "field3"}, | ||
}, | ||
{ | ||
name: "trailing period with correct fieldsPath", | ||
inresource: "field1.field2.field3.", | ||
|
||
expectedInResource: "field1", | ||
expectedFieldsPath: []string{"field2", "field3"}, | ||
}, | ||
{ | ||
name: "trailing period with incorrect fieldsPath", | ||
inresource: "field1.field2.field3.", | ||
|
||
expectedInResource: "field1", | ||
expectedFieldsPath: []string{"field2", "field3", ""}, | ||
expectedErr: true, | ||
}, | ||
} | ||
|
||
mapper := getMapper() | ||
for _, test := range tests { | ||
gotInResource, gotFieldsPath, err := SplitAndParseResourceRequest(test.inresource, mapper) | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
|
||
if !reflect.DeepEqual(test.expectedInResource, gotInResource) && !test.expectedErr { | ||
t.Errorf("%s: expected inresource: %s, got: %s", test.name, test.expectedInResource, gotInResource) | ||
} | ||
|
||
if !reflect.DeepEqual(test.expectedFieldsPath, gotFieldsPath) && !test.expectedErr { | ||
t.Errorf("%s: expected fieldsPath: %s, got: %s", test.name, test.expectedFieldsPath, gotFieldsPath) | ||
} | ||
} | ||
} | ||
|
||
func getMapper() meta.RESTMapper { | ||
f, _, _, _ := cmdtesting.NewTestFactory() | ||
mapper, _ := f.Object() | ||
return mapper | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters