manual changes to patch subresource
This commit is contained in:
@@ -134,6 +134,8 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
|
||||
"NewRootUpdateSubresourceAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewRootUpdateSubresourceAction"}),
|
||||
"NewRootPatchAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewRootPatchAction"}),
|
||||
"NewPatchAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewPatchAction"}),
|
||||
"NewRootPatchSubresourceAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewRootPatchSubresourceAction"}),
|
||||
"NewPatchSubresourceAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewPatchSubresourceAction"}),
|
||||
}
|
||||
|
||||
noMethods := extractBoolTagOrDie("noMethods", t.SecondClosestCommentLines) == true
|
||||
@@ -301,10 +303,10 @@ func (c *Fake$.type|publicPlural$) Watch(opts $.apiListOptions|raw$) ($.watchInt
|
||||
|
||||
var patchTemplate = `
|
||||
// Patch applies the patch and returns the patched $.type|private$.
|
||||
func (c *Fake$.type|publicPlural$) Patch(name string, pt $.PatchType|raw$, data []byte) (result *$.type|raw$, err error) {
|
||||
func (c *Fake$.type|publicPlural$) Patch(name string, pt $.PatchType|raw$, data []byte, subresources ...string) (result *$.type|raw$, err error) {
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewPatchAction|raw$($.type|allLowercasePlural$Resource, c.ns, name, data), &$.type|raw${})
|
||||
$else$Invokes($.NewRootPatchAction|raw$($.type|allLowercasePlural$Resource, name, data), &$.type|raw${})$end$
|
||||
$if .namespaced$Invokes($.NewPatchSubresourceAction|raw$($.type|allLowercasePlural$Resource, c.ns, name, data, subresources... ), &$.type|raw${})
|
||||
$else$Invokes($.NewRootPatchSubresourceAction|raw$($.type|allLowercasePlural$Resource, name, data, subresources...), &$.type|raw${})$end$
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -161,7 +161,7 @@ var interfaceTemplate3 = `
|
||||
Get(name string) (*$.type|raw$, error)
|
||||
List(opts $.apiListOptions|raw$) (*$.type|raw$List, error)
|
||||
Watch(opts $.apiListOptions|raw$) ($.watchInterface|raw$, error)
|
||||
Patch(name string, pt $.PatchType|raw$, data []byte) (result *$.type|raw$, err error)`
|
||||
Patch(name string, pt $.PatchType|raw$, data []byte, subresources ...string) (result *$.type|raw$, err error)`
|
||||
|
||||
var interfaceTemplate4 = `
|
||||
$.type|public$Expansion
|
||||
@@ -315,11 +315,12 @@ func (c *$.type|privatePlural$) Watch(opts $.apiListOptions|raw$) ($.watchInterf
|
||||
|
||||
var patchTemplate = `
|
||||
// Patch applies the patch and returns the patched $.type|private$.
|
||||
func (c *$.type|privatePlural$) Patch(name string, pt $.PatchType|raw$, data []byte) (result *$.type|raw$, err error) {
|
||||
func (c *$.type|privatePlural$) Patch(name string, pt $.PatchType|raw$, data []byte, subresources ...string) (result *$.type|raw$, err error) {
|
||||
result = &$.type|raw${}
|
||||
err = c.client.Patch(pt).
|
||||
$if .namespaced$Namespace(c.ns).$end$
|
||||
Resource("$.type|allLowercasePlural$").
|
||||
SubResource(subresources...).
|
||||
Name(name).
|
||||
Body(data).
|
||||
Do().
|
||||
|
@@ -23,6 +23,7 @@ import (
|
||||
core "k8s.io/kubernetes/pkg/client/testing/core"
|
||||
labels "k8s.io/kubernetes/pkg/labels"
|
||||
watch "k8s.io/kubernetes/pkg/watch"
|
||||
"path"
|
||||
)
|
||||
|
||||
// FakeTestTypes implements TestTypeInterface
|
||||
@@ -116,9 +117,9 @@ func (c *FakeTestTypes) Watch(opts api.ListOptions) (watch.Interface, error) {
|
||||
}
|
||||
|
||||
// Patch applies the patch and returns the patched testType.
|
||||
func (c *FakeTestTypes) Patch(name string, pt api.PatchType, data []byte) (result *testgroup_k8s_io.TestType, err error) {
|
||||
func (c *FakeTestTypes) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *testgroup_k8s_io.TestType, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(core.NewPatchAction(testtypesResource, c.ns, name, data), &testgroup_k8s_io.TestType{})
|
||||
Invokes(core.NewPatchSubresourceAction(testtypesResource, c.ns, name, data, path.Join(subresources...)), &testgroup_k8s_io.TestType{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
|
@@ -267,3 +267,25 @@ func TestPatchTestType(t *testing.T) {
|
||||
receivedTestType, err := c.Setup(t).TestTypes(ns).Patch(requestTestType.Name, api.StrategicMergePatchType, []byte{})
|
||||
c.simpleClient.Validate(t, receivedTestType, err)
|
||||
}
|
||||
|
||||
func TestPatchSubresourcesTestType(t *testing.T) {
|
||||
ns := api.NamespaceDefault
|
||||
requestTestType := &testgroup.TestType{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
ResourceVersion: "1",
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
}
|
||||
c := DecoratedSimpleClient{
|
||||
simpleClient: simple.Client{
|
||||
Request: simple.Request{Method: "PATCH", Path: testHelper.ResourcePath("testtypes", ns, "foo/status"), Query: simple.BuildQueryValues(nil)},
|
||||
Response: simple.Response{StatusCode: http.StatusOK, Body: requestTestType},
|
||||
},
|
||||
}
|
||||
receivedTestType, err := c.Setup(t).TestTypes(ns).Patch(requestTestType.Name, api.StrategicMergePatchType, []byte{}, "status")
|
||||
c.simpleClient.Validate(t, receivedTestType, err)
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ type TestTypeInterface interface {
|
||||
Get(name string) (*testgroup_k8s_io.TestType, error)
|
||||
List(opts api.ListOptions) (*testgroup_k8s_io.TestTypeList, error)
|
||||
Watch(opts api.ListOptions) (watch.Interface, error)
|
||||
Patch(name string, pt api.PatchType, data []byte) (result *testgroup_k8s_io.TestType, err error)
|
||||
Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *testgroup_k8s_io.TestType, err error)
|
||||
TestTypeExpansion
|
||||
}
|
||||
|
||||
@@ -151,11 +151,12 @@ func (c *testTypes) Watch(opts api.ListOptions) (watch.Interface, error) {
|
||||
}
|
||||
|
||||
// Patch applies the patch and returns the patched testType.
|
||||
func (c *testTypes) Patch(name string, pt api.PatchType, data []byte) (result *testgroup_k8s_io.TestType, err error) {
|
||||
func (c *testTypes) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *testgroup_k8s_io.TestType, err error) {
|
||||
result = &testgroup_k8s_io.TestType{}
|
||||
err = c.client.Patch(pt).
|
||||
Namespace(c.ns).
|
||||
Resource("testtypes").
|
||||
SubResource(subresources...).
|
||||
Name(name).
|
||||
Body(data).
|
||||
Do().
|
||||
|
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package core
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
@@ -139,11 +140,25 @@ func NewPatchAction(resource unversioned.GroupVersionResource, namespace string,
|
||||
return action
|
||||
}
|
||||
|
||||
func NewPatchSubresourceAction(resource unversioned.GroupVersionResource, subresource string) PatchActionImpl {
|
||||
func NewRootPatchSubresourceAction(resource unversioned.GroupVersionResource, name string, patch []byte, subresources ...string) PatchActionImpl {
|
||||
action := PatchActionImpl{}
|
||||
action.Verb = "patch"
|
||||
action.Resource = resource
|
||||
action.Subresource = subresource
|
||||
action.Subresource = path.Join(subresources...)
|
||||
action.Name = name
|
||||
action.Patch = patch
|
||||
|
||||
return action
|
||||
}
|
||||
|
||||
func NewPatchSubresourceAction(resource unversioned.GroupVersionResource, namespace, name string, patch []byte, subresources ...string) PatchActionImpl {
|
||||
action := PatchActionImpl{}
|
||||
action.Verb = "patch"
|
||||
action.Resource = resource
|
||||
action.Subresource = path.Join(subresources...)
|
||||
action.Namespace = namespace
|
||||
action.Name = name
|
||||
action.Patch = patch
|
||||
|
||||
return action
|
||||
}
|
||||
|
@@ -186,7 +186,7 @@ func (m *FakeNodeHandler) Watch(opts api.ListOptions) (watch.Interface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *FakeNodeHandler) Patch(name string, pt api.PatchType, data []byte) (*api.Node, error) {
|
||||
func (m *FakeNodeHandler) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (*api.Node, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user