Simplify 'kubectl edit' logic

edit: make editFn operate on arguments regardless of mode

edit: simplify short-circuiting logic when re-editing a file containing an error

edit: factor out visitor building

edit: use resource builder to get results from edited file
This commit is contained in:
Jordan Liggitt
2017-02-12 15:06:17 -05:00
parent f86db18297
commit 5b805bc18a
9 changed files with 110 additions and 107 deletions

View File

@@ -221,6 +221,20 @@ func TestEdit(t *testing.T) {
Client: fake.CreateHTTPClient(reqResp),
}, nil
}
tf.UnstructuredClientForMappingFunc = func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
versionedAPIPath := ""
if mapping.GroupVersionKind.Group == "" {
versionedAPIPath = "/api/" + mapping.GroupVersionKind.Version
} else {
versionedAPIPath = "/apis/" + mapping.GroupVersionKind.Group + "/" + mapping.GroupVersionKind.Version
}
return &fake.RESTClient{
APIRegistry: api.Registry,
VersionedAPIPath: versionedAPIPath,
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(reqResp),
}, nil
}
if len(testcase.Namespace) > 0 {
tf.Namespace = testcase.Namespace