Merge pull request #12146 from deads2k/tweak-testclient

make testclient more precise
pull/6/head
Alex Mohr 2015-08-04 14:49:11 -07:00
commit b90663924b
33 changed files with 1004 additions and 401 deletions

View File

@ -0,0 +1,279 @@
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
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 testclient
import (
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
)
func NewRootGetAction(resource, name string) GetActionImpl {
action := GetActionImpl{}
action.Verb = "get"
action.Resource = resource
action.Name = name
return action
}
func NewGetAction(resource, namespace, name string) GetActionImpl {
action := GetActionImpl{}
action.Verb = "get"
action.Resource = resource
action.Namespace = namespace
action.Name = name
return action
}
func NewRootListAction(resource string, label labels.Selector, field fields.Selector) ListActionImpl {
action := ListActionImpl{}
action.Verb = "list"
action.Resource = resource
action.ListRestrictions = ListRestrictions{label, field}
return action
}
func NewListAction(resource, namespace string, label labels.Selector, field fields.Selector) ListActionImpl {
action := ListActionImpl{}
action.Verb = "list"
action.Resource = resource
action.Namespace = namespace
action.ListRestrictions = ListRestrictions{label, field}
return action
}
func NewRootCreateAction(resource string, object runtime.Object) CreateActionImpl {
action := CreateActionImpl{}
action.Verb = "create"
action.Resource = resource
action.Object = object
return action
}
func NewCreateAction(resource, namespace string, object runtime.Object) CreateActionImpl {
action := CreateActionImpl{}
action.Verb = "create"
action.Resource = resource
action.Namespace = namespace
action.Object = object
return action
}
func NewRootUpdateAction(resource string, object runtime.Object) UpdateActionImpl {
action := UpdateActionImpl{}
action.Verb = "update"
action.Resource = resource
action.Object = object
return action
}
func NewUpdateAction(resource, namespace string, object runtime.Object) UpdateActionImpl {
action := UpdateActionImpl{}
action.Verb = "update"
action.Resource = resource
action.Namespace = namespace
action.Object = object
return action
}
func NewRootDeleteAction(resource, name string) DeleteActionImpl {
action := DeleteActionImpl{}
action.Verb = "delete"
action.Resource = resource
action.Name = name
return action
}
func NewDeleteAction(resource, namespace, name string) DeleteActionImpl {
action := DeleteActionImpl{}
action.Verb = "delete"
action.Resource = resource
action.Namespace = namespace
action.Name = name
return action
}
func NewRootWatchAction(resource string, label labels.Selector, field fields.Selector, resourceVersion string) WatchActionImpl {
action := WatchActionImpl{}
action.Verb = "watch"
action.Resource = resource
action.WatchRestrictions = WatchRestrictions{label, field, resourceVersion}
return action
}
func NewWatchAction(resource, namespace string, label labels.Selector, field fields.Selector, resourceVersion string) WatchActionImpl {
action := WatchActionImpl{}
action.Verb = "watch"
action.Resource = resource
action.Namespace = namespace
action.WatchRestrictions = WatchRestrictions{label, field, resourceVersion}
return action
}
type ListRestrictions struct {
Labels labels.Selector
Fields fields.Selector
}
type WatchRestrictions struct {
Labels labels.Selector
Fields fields.Selector
ResourceVersion string
}
type Action interface {
GetNamespace() string
GetVerb() string
GetResource() string
GetSubresource() string
Matches(verb, resource string) bool
}
type GenericAction interface {
Action
GetValue() interface{}
}
type GetAction interface {
Action
GetName() string
}
type ListAction interface {
Action
GetListRestrictions() ListRestrictions
}
type CreateAction interface {
Action
GetObject() runtime.Object
}
type UpdateAction interface {
Action
GetObject() runtime.Object
}
type DeleteAction interface {
Action
GetName() string
}
type WatchAction interface {
Action
GetWatchRestrictions() WatchRestrictions
}
type ActionImpl struct {
Namespace string
Verb string
Resource string
Subresource string
}
func (a ActionImpl) GetNamespace() string {
return a.Namespace
}
func (a ActionImpl) GetVerb() string {
return a.Verb
}
func (a ActionImpl) GetResource() string {
return a.Resource
}
func (a ActionImpl) GetSubresource() string {
return a.Subresource
}
func (a ActionImpl) Matches(verb, resource string) bool {
return strings.ToLower(verb) == strings.ToLower(a.Verb) &&
strings.ToLower(resource) == strings.ToLower(a.Resource)
}
type GenericActionImpl struct {
ActionImpl
Value interface{}
}
func (a GenericActionImpl) GetValue() interface{} {
return a.Value
}
type GetActionImpl struct {
ActionImpl
Name string
}
func (a GetActionImpl) GetName() string {
return a.Name
}
type ListActionImpl struct {
ActionImpl
ListRestrictions ListRestrictions
}
func (a ListActionImpl) GetListRestrictions() ListRestrictions {
return a.ListRestrictions
}
type CreateActionImpl struct {
ActionImpl
Object runtime.Object
}
func (a CreateActionImpl) GetObject() runtime.Object {
return a.Object
}
type UpdateActionImpl struct {
ActionImpl
Object runtime.Object
}
func (a UpdateActionImpl) GetObject() runtime.Object {
return a.Object
}
type DeleteActionImpl struct {
ActionImpl
Name string
}
func (a DeleteActionImpl) GetName() string {
return a.Name
}
type WatchActionImpl struct {
ActionImpl
WatchRestrictions WatchRestrictions
}
func (a WatchActionImpl) GetWatchRestrictions() WatchRestrictions {
return a.WatchRestrictions
}

View File

@ -27,21 +27,20 @@ type FakeComponentStatuses struct {
Fake *Fake
}
func (c *FakeComponentStatuses) List(label labels.Selector, field fields.Selector) (result *api.ComponentStatusList, err error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "list-componentstatuses"}, &api.ComponentStatusList{})
return obj.(*api.ComponentStatusList), err
}
func (c *FakeComponentStatuses) Get(name string) (*api.ComponentStatus, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "get-componentstatus", Value: name}, &api.ComponentStatus{})
// c.Actions = append(c.Actions, FakeAction{Action: "get-componentstatuses", Value: nil})
// testStatus := &api.ComponentStatus{
// Name: "test",
// Health: "ok",
// HealthCode: int(probe.Success),
// Message: "ok",
// Error: "",
// }
// return &api.ComponentStatusList{Items: []api.ComponentStatus{*testStatus}}, nil
obj, err := c.Fake.Invokes(NewRootGetAction("componentstatuses", name), &api.ComponentStatus{})
if obj == nil {
return nil, err
}
return obj.(*api.ComponentStatus), err
}
func (c *FakeComponentStatuses) List(label labels.Selector, field fields.Selector) (result *api.ComponentStatusList, err error) {
obj, err := c.Fake.Invokes(NewRootListAction("componentstatuses", label, field), &api.ComponentStatusList{})
if obj == nil {
return nil, err
}
return obj.(*api.ComponentStatusList), err
}

View File

@ -30,32 +30,48 @@ type FakeEndpoints struct {
Namespace string
}
func (c *FakeEndpoints) Create(endpoints *api.Endpoints) (*api.Endpoints, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "create-endpoints"}, &api.Endpoints{})
func (c *FakeEndpoints) Get(name string) (*api.Endpoints, error) {
obj, err := c.Fake.Invokes(NewGetAction("endpoints", c.Namespace, name), &api.Endpoints{})
if obj == nil {
return nil, err
}
return obj.(*api.Endpoints), err
}
func (c *FakeEndpoints) List(selector labels.Selector) (*api.EndpointsList, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "list-endpoints"}, &api.EndpointsList{})
func (c *FakeEndpoints) List(label labels.Selector) (*api.EndpointsList, error) {
obj, err := c.Fake.Invokes(NewListAction("endpoints", c.Namespace, label, nil), &api.EndpointsList{})
if obj == nil {
return nil, err
}
return obj.(*api.EndpointsList), err
}
func (c *FakeEndpoints) Get(name string) (*api.Endpoints, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "get-endpoints", Value: name}, &api.Endpoints{})
func (c *FakeEndpoints) Create(endpoints *api.Endpoints) (*api.Endpoints, error) {
obj, err := c.Fake.Invokes(NewCreateAction("endpoints", c.Namespace, endpoints), endpoints)
if obj == nil {
return nil, err
}
return obj.(*api.Endpoints), err
}
func (c *FakeEndpoints) Update(endpoints *api.Endpoints) (*api.Endpoints, error) {
obj, err := c.Fake.Invokes(NewUpdateAction("endpoints", c.Namespace, endpoints), endpoints)
if obj == nil {
return nil, err
}
return obj.(*api.Endpoints), err
}
func (c *FakeEndpoints) Delete(name string) error {
_, err := c.Fake.Invokes(FakeAction{Action: "delete-endpoints", Value: name}, &api.Endpoints{})
_, err := c.Fake.Invokes(NewDeleteAction("endpoints", c.Namespace, name), &api.Endpoints{})
return err
}
func (c *FakeEndpoints) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Invokes(FakeAction{Action: "watch-endpoints", Value: resourceVersion}, nil)
c.Fake.Invokes(NewWatchAction("endpoints", c.Namespace, label, field, resourceVersion), nil)
return c.Fake.Watch, c.Fake.Err()
}
func (c *FakeEndpoints) Update(endpoints *api.Endpoints) (*api.Endpoints, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-endpoints", Value: endpoints.Name}, &api.Endpoints{})
return obj.(*api.Endpoints), err
}

View File

@ -30,48 +30,72 @@ type FakeEvents struct {
Fake *Fake
}
// Create makes a new event. Returns the copy of the event the server returns, or an error.
func (c *FakeEvents) Create(event *api.Event) (*api.Event, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "get-event", Value: event.Name}, &api.Event{})
return obj.(*api.Event), err
}
// Get returns the given event, or an error.
func (c *FakeEvents) Get(name string) (*api.Event, error) {
obj, err := c.Fake.Invokes(NewRootGetAction("events", name), &api.Event{})
if obj == nil {
return nil, err
}
// Update replaces an existing event. Returns the copy of the event the server returns, or an error.
func (c *FakeEvents) Update(event *api.Event) (*api.Event, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-event", Value: event.Name}, &api.Event{})
return obj.(*api.Event), err
}
// List returns a list of events matching the selectors.
func (c *FakeEvents) List(label labels.Selector, field fields.Selector) (*api.EventList, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "list-events"}, &api.EventList{})
obj, err := c.Fake.Invokes(NewRootListAction("events", label, field), &api.EventList{})
if obj == nil {
return nil, err
}
return obj.(*api.EventList), err
}
// Get returns the given event, or an error.
func (c *FakeEvents) Get(id string) (*api.Event, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "get-endpoints", Value: id}, &api.Event{})
// Create makes a new event. Returns the copy of the event the server returns, or an error.
func (c *FakeEvents) Create(event *api.Event) (*api.Event, error) {
obj, err := c.Fake.Invokes(NewRootCreateAction("events", event), event)
if obj == nil {
return nil, err
}
return obj.(*api.Event), err
}
// Update replaces an existing event. Returns the copy of the event the server returns, or an error.
func (c *FakeEvents) Update(event *api.Event) (*api.Event, error) {
obj, err := c.Fake.Invokes(NewRootUpdateAction("events", event), event)
if obj == nil {
return nil, err
}
return obj.(*api.Event), err
}
func (c *FakeEvents) Delete(name string) error {
_, err := c.Fake.Invokes(NewRootDeleteAction("events", name), &api.Event{})
return err
}
// Watch starts watching for events matching the given selectors.
func (c *FakeEvents) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Invokes(FakeAction{Action: "watch-events", Value: resourceVersion}, nil)
c.Fake.Invokes(NewRootWatchAction("events", label, field, resourceVersion), nil)
return c.Fake.Watch, c.Fake.Err()
}
// Search returns a list of events matching the specified object.
func (c *FakeEvents) Search(objOrRef runtime.Object) (*api.EventList, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "search-events"}, &api.EventList{})
obj, err := c.Fake.Invokes(NewRootListAction("events", nil, nil), &api.EventList{})
if obj == nil {
return nil, err
}
return obj.(*api.EventList), err
}
func (c *FakeEvents) Delete(name string) error {
_, err := c.Fake.Invokes(FakeAction{Action: "delete-event", Value: name}, &api.Event{})
return err
}
func (c *FakeEvents) GetFieldSelector(involvedObjectName, involvedObjectNamespace, involvedObjectKind, involvedObjectUID *string) fields.Selector {
c.Fake.Invokes(FakeAction{Action: "get-field-selector"}, nil)
action := GenericActionImpl{}
action.Verb = "get-field-selector"
action.Resource = "events"
c.Fake.Invokes(action, nil)
return fields.Everything()
}

View File

@ -30,32 +30,48 @@ type FakeLimitRanges struct {
Namespace string
}
func (c *FakeLimitRanges) List(selector labels.Selector) (*api.LimitRangeList, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "list-limitRanges"}, &api.LimitRangeList{})
return obj.(*api.LimitRangeList), err
}
func (c *FakeLimitRanges) Get(name string) (*api.LimitRange, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "get-limitRange", Value: name}, &api.LimitRange{})
obj, err := c.Fake.Invokes(NewGetAction("limitranges", c.Namespace, name), &api.LimitRange{})
if obj == nil {
return nil, err
}
return obj.(*api.LimitRange), err
}
func (c *FakeLimitRanges) Delete(name string) error {
_, err := c.Fake.Invokes(FakeAction{Action: "delete-limitRange", Value: name}, &api.LimitRange{})
return err
func (c *FakeLimitRanges) List(label labels.Selector) (*api.LimitRangeList, error) {
obj, err := c.Fake.Invokes(NewListAction("limitranges", c.Namespace, label, nil), &api.LimitRangeList{})
if obj == nil {
return nil, err
}
return obj.(*api.LimitRangeList), err
}
func (c *FakeLimitRanges) Create(limitRange *api.LimitRange) (*api.LimitRange, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "create-limitRange"}, &api.LimitRange{})
obj, err := c.Fake.Invokes(NewCreateAction("limitranges", c.Namespace, limitRange), limitRange)
if obj == nil {
return nil, err
}
return obj.(*api.LimitRange), err
}
func (c *FakeLimitRanges) Update(limitRange *api.LimitRange) (*api.LimitRange, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-limitRange", Value: limitRange.Name}, &api.LimitRange{})
obj, err := c.Fake.Invokes(NewUpdateAction("limitranges", c.Namespace, limitRange), limitRange)
if obj == nil {
return nil, err
}
return obj.(*api.LimitRange), err
}
func (c *FakeLimitRanges) Delete(name string) error {
_, err := c.Fake.Invokes(NewDeleteAction("limitranges", c.Namespace, name), &api.LimitRange{})
return err
}
func (c *FakeLimitRanges) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Invokes(FakeAction{Action: "watch-limitRange", Value: resourceVersion}, nil)
c.Fake.Invokes(NewWatchAction("limitranges", c.Namespace, label, field, resourceVersion), nil)
return c.Fake.Watch, nil
}

View File

@ -29,42 +29,78 @@ type FakeNamespaces struct {
Fake *Fake
}
func (c *FakeNamespaces) List(labels labels.Selector, field fields.Selector) (*api.NamespaceList, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "list-namespaces"}, &api.NamespaceList{})
func (c *FakeNamespaces) Get(name string) (*api.Namespace, error) {
obj, err := c.Fake.Invokes(NewRootGetAction("namespaces", name), &api.Namespace{})
if obj == nil {
return nil, err
}
return obj.(*api.Namespace), err
}
func (c *FakeNamespaces) List(label labels.Selector, field fields.Selector) (*api.NamespaceList, error) {
obj, err := c.Fake.Invokes(NewRootListAction("namespaces", label, field), &api.NamespaceList{})
if obj == nil {
return nil, err
}
return obj.(*api.NamespaceList), err
}
func (c *FakeNamespaces) Get(name string) (*api.Namespace, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "get-namespace", Value: name}, &api.Namespace{})
func (c *FakeNamespaces) Create(namespace *api.Namespace) (*api.Namespace, error) {
obj, err := c.Fake.Invokes(NewRootCreateAction("namespaces", namespace), namespace)
if obj == nil {
return nil, err
}
return obj.(*api.Namespace), c.Fake.Err()
}
func (c *FakeNamespaces) Update(namespace *api.Namespace) (*api.Namespace, error) {
obj, err := c.Fake.Invokes(NewRootUpdateAction("namespaces", namespace), namespace)
if obj == nil {
return nil, err
}
return obj.(*api.Namespace), err
}
func (c *FakeNamespaces) Delete(name string) error {
_, err := c.Fake.Invokes(FakeAction{Action: "delete-namespace", Value: name}, &api.Namespace{})
_, err := c.Fake.Invokes(NewRootDeleteAction("namespaces", name), &api.Namespace{})
return err
}
func (c *FakeNamespaces) Create(namespace *api.Namespace) (*api.Namespace, error) {
c.Fake.Invokes(FakeAction{Action: "create-namespace"}, nil)
return &api.Namespace{}, c.Fake.Err()
}
func (c *FakeNamespaces) Update(namespace *api.Namespace) (*api.Namespace, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-namespace", Value: namespace}, &api.Namespace{})
return obj.(*api.Namespace), err
}
func (c *FakeNamespaces) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Invokes(FakeAction{Action: "watch-namespaces", Value: resourceVersion}, nil)
c.Fake.Invokes(NewRootWatchAction("namespaces", label, field, resourceVersion), nil)
return c.Fake.Watch, nil
}
func (c *FakeNamespaces) Finalize(namespace *api.Namespace) (*api.Namespace, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "finalize-namespace", Value: namespace}, &api.Namespace{})
action := CreateActionImpl{}
action.Verb = "create"
action.Resource = "namespaces"
action.Subresource = "finalize"
action.Object = namespace
obj, err := c.Fake.Invokes(action, namespace)
if obj == nil {
return nil, err
}
return obj.(*api.Namespace), err
}
func (c *FakeNamespaces) Status(namespace *api.Namespace) (*api.Namespace, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "status-namespace", Value: namespace}, &api.Namespace{})
action := CreateActionImpl{}
action.Verb = "create"
action.Resource = "namespaces"
action.Subresource = "status"
action.Object = namespace
obj, err := c.Fake.Invokes(action, namespace)
if obj == nil {
return nil, err
}
return obj.(*api.Namespace), err
}

View File

@ -30,36 +30,62 @@ type FakeNodes struct {
}
func (c *FakeNodes) Get(name string) (*api.Node, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "get-node", Value: name}, &api.Node{})
obj, err := c.Fake.Invokes(NewRootGetAction("nodes", name), &api.Node{})
if obj == nil {
return nil, err
}
return obj.(*api.Node), err
}
func (c *FakeNodes) List(label labels.Selector, field fields.Selector) (*api.NodeList, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "list-nodes"}, &api.NodeList{})
obj, err := c.Fake.Invokes(NewRootListAction("nodes", label, field), &api.NodeList{})
if obj == nil {
return nil, err
}
return obj.(*api.NodeList), err
}
func (c *FakeNodes) Create(minion *api.Node) (*api.Node, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "create-node", Value: minion}, &api.Node{})
obj, err := c.Fake.Invokes(NewRootCreateAction("nodes", minion), minion)
if obj == nil {
return nil, err
}
return obj.(*api.Node), err
}
func (c *FakeNodes) Update(minion *api.Node) (*api.Node, error) {
obj, err := c.Fake.Invokes(NewRootUpdateAction("nodes", minion), minion)
if obj == nil {
return nil, err
}
return obj.(*api.Node), err
}
func (c *FakeNodes) Delete(name string) error {
_, err := c.Fake.Invokes(FakeAction{Action: "delete-node", Value: name}, &api.Node{})
_, err := c.Fake.Invokes(NewRootDeleteAction("nodes", name), &api.Node{})
return err
}
func (c *FakeNodes) Update(minion *api.Node) (*api.Node, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-node", Value: minion}, &api.Node{})
return obj.(*api.Node), err
func (c *FakeNodes) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Invokes(NewRootWatchAction("nodes", label, field, resourceVersion), nil)
return c.Fake.Watch, c.Fake.Err()
}
func (c *FakeNodes) UpdateStatus(minion *api.Node) (*api.Node, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-status-node", Value: minion}, &api.Node{})
action := CreateActionImpl{}
action.Verb = "update"
action.Resource = "nodes"
action.Subresource = "status"
action.Object = minion
obj, err := c.Fake.Invokes(action, minion)
if obj == nil {
return nil, err
}
return obj.(*api.Node), err
}
func (c *FakeNodes) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Invokes(FakeAction{Action: "watch-nodes", Value: resourceVersion}, nil)
return c.Fake.Watch, c.Fake.Err()
}

View File

@ -28,37 +28,63 @@ type FakePersistentVolumeClaims struct {
Namespace string
}
func (c *FakePersistentVolumeClaims) List(label labels.Selector, field fields.Selector) (*api.PersistentVolumeClaimList, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "list-persistentVolumeClaims"}, &api.PersistentVolumeClaimList{})
return obj.(*api.PersistentVolumeClaimList), err
}
func (c *FakePersistentVolumeClaims) Get(name string) (*api.PersistentVolumeClaim, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "get-persistentVolumeClaims", Value: name}, &api.PersistentVolumeClaim{})
obj, err := c.Fake.Invokes(NewGetAction("persistentvolumeclaims", c.Namespace, name), &api.PersistentVolumeClaim{})
if obj == nil {
return nil, err
}
return obj.(*api.PersistentVolumeClaim), err
}
func (c *FakePersistentVolumeClaims) Delete(name string) error {
_, err := c.Fake.Invokes(FakeAction{Action: "delete-persistentVolumeClaims", Value: name}, &api.PersistentVolumeClaim{})
return err
func (c *FakePersistentVolumeClaims) List(label labels.Selector, field fields.Selector) (*api.PersistentVolumeClaimList, error) {
obj, err := c.Fake.Invokes(NewListAction("persistentvolumeclaims", c.Namespace, label, field), &api.PersistentVolumeClaimList{})
if obj == nil {
return nil, err
}
return obj.(*api.PersistentVolumeClaimList), err
}
func (c *FakePersistentVolumeClaims) Create(claim *api.PersistentVolumeClaim) (*api.PersistentVolumeClaim, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "create-persistentVolumeClaims"}, &api.PersistentVolumeClaim{})
obj, err := c.Fake.Invokes(NewCreateAction("persistentvolumeclaims", c.Namespace, claim), claim)
if obj == nil {
return nil, err
}
return obj.(*api.PersistentVolumeClaim), err
}
func (c *FakePersistentVolumeClaims) Update(claim *api.PersistentVolumeClaim) (*api.PersistentVolumeClaim, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-persistentVolumeClaims", Value: claim.Name}, &api.PersistentVolumeClaim{})
obj, err := c.Fake.Invokes(NewUpdateAction("persistentvolumeclaims", c.Namespace, claim), claim)
if obj == nil {
return nil, err
}
return obj.(*api.PersistentVolumeClaim), err
}
func (c *FakePersistentVolumeClaims) UpdateStatus(claim *api.PersistentVolumeClaim) (*api.PersistentVolumeClaim, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-status-persistentVolumeClaims", Value: claim}, &api.PersistentVolumeClaim{})
return obj.(*api.PersistentVolumeClaim), err
func (c *FakePersistentVolumeClaims) Delete(name string) error {
_, err := c.Fake.Invokes(NewDeleteAction("persistentvolumeclaims", c.Namespace, name), &api.PersistentVolumeClaim{})
return err
}
func (c *FakePersistentVolumeClaims) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Invokes(FakeAction{Action: "watch-persistentVolumeClaims", Value: resourceVersion}, nil)
c.Fake.Invokes(NewWatchAction("persistentvolumeclaims", c.Namespace, label, field, resourceVersion), nil)
return c.Fake.Watch, c.Fake.Err()
}
func (c *FakePersistentVolumeClaims) UpdateStatus(claim *api.PersistentVolumeClaim) (*api.PersistentVolumeClaim, error) {
action := UpdateActionImpl{}
action.Verb = "update"
action.Resource = "persistentvolumeclaims"
action.Subresource = "status"
action.Object = claim
obj, err := c.Fake.Invokes(action, claim)
if obj == nil {
return nil, err
}
return obj.(*api.PersistentVolumeClaim), err
}

View File

@ -24,41 +24,66 @@ import (
)
type FakePersistentVolumes struct {
Fake *Fake
Namespace string
}
func (c *FakePersistentVolumes) List(label labels.Selector, field fields.Selector) (*api.PersistentVolumeList, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "list-persistentVolumes"}, &api.PersistentVolumeList{})
return obj.(*api.PersistentVolumeList), err
Fake *Fake
}
func (c *FakePersistentVolumes) Get(name string) (*api.PersistentVolume, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "get-persistentVolumes", Value: name}, &api.PersistentVolume{})
obj, err := c.Fake.Invokes(NewRootGetAction("persistentvolumes", name), &api.PersistentVolume{})
if obj == nil {
return nil, err
}
return obj.(*api.PersistentVolume), err
}
func (c *FakePersistentVolumes) Delete(name string) error {
_, err := c.Fake.Invokes(FakeAction{Action: "delete-persistentVolumes", Value: name}, &api.PersistentVolume{})
return err
func (c *FakePersistentVolumes) List(label labels.Selector, field fields.Selector) (*api.PersistentVolumeList, error) {
obj, err := c.Fake.Invokes(NewRootListAction("persistentvolumes", label, field), &api.PersistentVolumeList{})
if obj == nil {
return nil, err
}
return obj.(*api.PersistentVolumeList), err
}
func (c *FakePersistentVolumes) Create(pv *api.PersistentVolume) (*api.PersistentVolume, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "create-persistentVolumes"}, &api.PersistentVolume{})
obj, err := c.Fake.Invokes(NewRootCreateAction("persistentvolumes", pv), pv)
if obj == nil {
return nil, err
}
return obj.(*api.PersistentVolume), err
}
func (c *FakePersistentVolumes) Update(pv *api.PersistentVolume) (*api.PersistentVolume, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-persistentVolumes", Value: pv.Name}, &api.PersistentVolume{})
obj, err := c.Fake.Invokes(NewRootUpdateAction("persistentvolumes", pv), pv)
if obj == nil {
return nil, err
}
return obj.(*api.PersistentVolume), err
}
func (c *FakePersistentVolumes) UpdateStatus(pv *api.PersistentVolume) (*api.PersistentVolume, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-status-persistentVolumes", Value: pv}, &api.PersistentVolume{})
return obj.(*api.PersistentVolume), err
func (c *FakePersistentVolumes) Delete(name string) error {
_, err := c.Fake.Invokes(NewRootDeleteAction("persistentvolumes", name), &api.PersistentVolume{})
return err
}
func (c *FakePersistentVolumes) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Invokes(FakeAction{Action: "watch-persistentVolumes", Value: resourceVersion}, nil)
c.Fake.Invokes(NewRootWatchAction("persistentvolumes", label, field, resourceVersion), nil)
return c.Fake.Watch, c.Fake.Err()
}
func (c *FakePersistentVolumes) UpdateStatus(pv *api.PersistentVolume) (*api.PersistentVolume, error) {
action := UpdateActionImpl{}
action.Verb = "update"
action.Resource = "persistentvolumes"
action.Subresource = "status"
action.Object = pv
obj, err := c.Fake.Invokes(action, pv)
if obj == nil {
return nil, err
}
return obj.(*api.PersistentVolume), err
}

View File

@ -30,32 +30,48 @@ type FakePodTemplates struct {
Namespace string
}
func (c *FakePodTemplates) List(label labels.Selector, field fields.Selector) (*api.PodTemplateList, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "list-podTemplates"}, &api.PodTemplateList{})
return obj.(*api.PodTemplateList), err
}
func (c *FakePodTemplates) Get(name string) (*api.PodTemplate, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "get-podTemplate", Value: name}, &api.PodTemplate{})
obj, err := c.Fake.Invokes(NewGetAction("podtemplates", c.Namespace, name), &api.PodTemplate{})
if obj == nil {
return nil, err
}
return obj.(*api.PodTemplate), err
}
func (c *FakePodTemplates) Delete(name string, options *api.DeleteOptions) error {
_, err := c.Fake.Invokes(FakeAction{Action: "delete-podTemplate", Value: name}, &api.PodTemplate{})
return err
func (c *FakePodTemplates) List(label labels.Selector, field fields.Selector) (*api.PodTemplateList, error) {
obj, err := c.Fake.Invokes(NewListAction("podtemplates", c.Namespace, label, field), &api.PodTemplateList{})
if obj == nil {
return nil, err
}
return obj.(*api.PodTemplateList), err
}
func (c *FakePodTemplates) Create(pod *api.PodTemplate) (*api.PodTemplate, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "create-podTemplate"}, &api.PodTemplate{})
obj, err := c.Fake.Invokes(NewCreateAction("podtemplates", c.Namespace, pod), pod)
if obj == nil {
return nil, err
}
return obj.(*api.PodTemplate), err
}
func (c *FakePodTemplates) Update(pod *api.PodTemplate) (*api.PodTemplate, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-podTemplate", Value: pod.Name}, &api.PodTemplate{})
obj, err := c.Fake.Invokes(NewUpdateAction("podtemplates", c.Namespace, pod), pod)
if obj == nil {
return nil, err
}
return obj.(*api.PodTemplate), err
}
func (c *FakePodTemplates) Delete(name string, options *api.DeleteOptions) error {
_, err := c.Fake.Invokes(NewDeleteAction("podtemplates", c.Namespace, name), &api.PodTemplate{})
return err
}
func (c *FakePodTemplates) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Invokes(FakeAction{Action: "watch-podTemplates", Value: resourceVersion}, nil)
c.Fake.Invokes(NewWatchAction("podtemplates", c.Namespace, label, field, resourceVersion), nil)
return c.Fake.Watch, c.Fake.Err()
}

View File

@ -30,42 +30,74 @@ type FakePods struct {
Namespace string
}
func (c *FakePods) List(label labels.Selector, field fields.Selector) (*api.PodList, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "list-pods"}, &api.PodList{})
return obj.(*api.PodList), err
}
func (c *FakePods) Get(name string) (*api.Pod, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "get-pod", Value: name}, &api.Pod{})
obj, err := c.Fake.Invokes(NewGetAction("pods", c.Namespace, name), &api.Pod{})
if obj == nil {
return nil, err
}
return obj.(*api.Pod), err
}
func (c *FakePods) Delete(name string, options *api.DeleteOptions) error {
_, err := c.Fake.Invokes(FakeAction{Action: "delete-pod", Value: name}, &api.Pod{})
return err
func (c *FakePods) List(label labels.Selector, field fields.Selector) (*api.PodList, error) {
obj, err := c.Fake.Invokes(NewListAction("pods", c.Namespace, label, field), &api.PodList{})
if obj == nil {
return nil, err
}
return obj.(*api.PodList), err
}
func (c *FakePods) Create(pod *api.Pod) (*api.Pod, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "create-pod"}, &api.Pod{})
obj, err := c.Fake.Invokes(NewCreateAction("pods", c.Namespace, pod), pod)
if obj == nil {
return nil, err
}
return obj.(*api.Pod), err
}
func (c *FakePods) Update(pod *api.Pod) (*api.Pod, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-pod", Value: pod.Name}, &api.Pod{})
obj, err := c.Fake.Invokes(NewUpdateAction("pods", c.Namespace, pod), pod)
if obj == nil {
return nil, err
}
return obj.(*api.Pod), err
}
func (c *FakePods) Delete(name string, options *api.DeleteOptions) error {
_, err := c.Fake.Invokes(NewDeleteAction("pods", c.Namespace, name), &api.Pod{})
return err
}
func (c *FakePods) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Invokes(FakeAction{Action: "watch-pods", Value: resourceVersion}, nil)
c.Fake.Invokes(NewWatchAction("pods", c.Namespace, label, field, resourceVersion), nil)
return c.Fake.Watch, c.Fake.Err()
}
func (c *FakePods) Bind(bind *api.Binding) error {
c.Fake.Invokes(FakeAction{Action: "bind-pod", Value: bind.Name}, nil)
return nil
func (c *FakePods) Bind(binding *api.Binding) error {
action := CreateActionImpl{}
action.Verb = "create"
action.Resource = "pods"
action.Subresource = "bindings"
action.Object = binding
_, err := c.Fake.Invokes(action, binding)
return err
}
func (c *FakePods) UpdateStatus(pod *api.Pod) (*api.Pod, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-status-pod", Value: pod.Name}, &api.Pod{})
action := UpdateActionImpl{}
action.Verb = "update"
action.Resource = "pods"
action.Subresource = "status"
action.Object = pod
obj, err := c.Fake.Invokes(action, pod)
if obj == nil {
return nil, err
}
return obj.(*api.Pod), err
}

View File

@ -30,41 +30,48 @@ type FakeReplicationControllers struct {
Namespace string
}
const (
GetControllerAction = "get-replicationController"
UpdateControllerAction = "update-replicationController"
WatchControllerAction = "watch-replicationController"
DeleteControllerAction = "delete-replicationController"
ListControllerAction = "list-replicationController"
CreateControllerAction = "create-replicationController"
)
func (c *FakeReplicationControllers) List(selector labels.Selector) (*api.ReplicationControllerList, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: ListControllerAction}, &api.ReplicationControllerList{})
return obj.(*api.ReplicationControllerList), err
}
func (c *FakeReplicationControllers) Get(name string) (*api.ReplicationController, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: GetControllerAction, Value: name}, &api.ReplicationController{})
obj, err := c.Fake.Invokes(NewGetAction("replicationcontrollers", c.Namespace, name), &api.ReplicationController{})
if obj == nil {
return nil, err
}
return obj.(*api.ReplicationController), err
}
func (c *FakeReplicationControllers) List(label labels.Selector) (*api.ReplicationControllerList, error) {
obj, err := c.Fake.Invokes(NewListAction("replicationcontrollers", c.Namespace, label, nil), &api.ReplicationControllerList{})
if obj == nil {
return nil, err
}
return obj.(*api.ReplicationControllerList), err
}
func (c *FakeReplicationControllers) Create(controller *api.ReplicationController) (*api.ReplicationController, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: CreateControllerAction, Value: controller}, &api.ReplicationController{})
obj, err := c.Fake.Invokes(NewCreateAction("replicationcontrollers", c.Namespace, controller), controller)
if obj == nil {
return nil, err
}
return obj.(*api.ReplicationController), err
}
func (c *FakeReplicationControllers) Update(controller *api.ReplicationController) (*api.ReplicationController, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: UpdateControllerAction, Value: controller}, &api.ReplicationController{})
obj, err := c.Fake.Invokes(NewUpdateAction("replicationcontrollers", c.Namespace, controller), controller)
if obj == nil {
return nil, err
}
return obj.(*api.ReplicationController), err
}
func (c *FakeReplicationControllers) Delete(name string) error {
_, err := c.Fake.Invokes(FakeAction{Action: DeleteControllerAction, Value: name}, &api.ReplicationController{})
_, err := c.Fake.Invokes(NewDeleteAction("replicationcontrollers", c.Namespace, name), &api.ReplicationController{})
return err
}
func (c *FakeReplicationControllers) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Invokes(FakeAction{Action: WatchControllerAction, Value: resourceVersion}, nil)
c.Fake.Invokes(NewWatchAction("replicationcontrollers", c.Namespace, label, field, resourceVersion), nil)
return c.Fake.Watch, nil
}

View File

@ -30,37 +30,63 @@ type FakeResourceQuotas struct {
Namespace string
}
func (c *FakeResourceQuotas) List(selector labels.Selector) (*api.ResourceQuotaList, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "list-resourceQuotas"}, &api.ResourceQuotaList{})
return obj.(*api.ResourceQuotaList), err
}
func (c *FakeResourceQuotas) Get(name string) (*api.ResourceQuota, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "get-resourceQuota", Value: name}, &api.ResourceQuota{})
obj, err := c.Fake.Invokes(NewGetAction("resourcequotas", c.Namespace, name), &api.ResourceQuota{})
if obj == nil {
return nil, err
}
return obj.(*api.ResourceQuota), err
}
func (c *FakeResourceQuotas) Delete(name string) error {
_, err := c.Fake.Invokes(FakeAction{Action: "delete-resourceQuota", Value: name}, &api.ResourceQuota{})
return err
func (c *FakeResourceQuotas) List(label labels.Selector) (*api.ResourceQuotaList, error) {
obj, err := c.Fake.Invokes(NewListAction("resourcequotas", c.Namespace, label, nil), &api.ResourceQuotaList{})
if obj == nil {
return nil, err
}
return obj.(*api.ResourceQuotaList), err
}
func (c *FakeResourceQuotas) Create(resourceQuota *api.ResourceQuota) (*api.ResourceQuota, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "create-resourceQuota", Value: resourceQuota}, &api.ResourceQuota{})
obj, err := c.Fake.Invokes(NewCreateAction("resourcequotas", c.Namespace, resourceQuota), resourceQuota)
if obj == nil {
return nil, err
}
return obj.(*api.ResourceQuota), err
}
func (c *FakeResourceQuotas) Update(resourceQuota *api.ResourceQuota) (*api.ResourceQuota, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-resourceQuota", Value: resourceQuota}, &api.ResourceQuota{})
obj, err := c.Fake.Invokes(NewUpdateAction("resourcequotas", c.Namespace, resourceQuota), resourceQuota)
if obj == nil {
return nil, err
}
return obj.(*api.ResourceQuota), err
}
func (c *FakeResourceQuotas) UpdateStatus(resourceQuota *api.ResourceQuota) (*api.ResourceQuota, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-status-resourceQuota", Value: resourceQuota}, &api.ResourceQuota{})
return obj.(*api.ResourceQuota), err
func (c *FakeResourceQuotas) Delete(name string) error {
_, err := c.Fake.Invokes(NewDeleteAction("resourcequotas", c.Namespace, name), &api.ResourceQuota{})
return err
}
func (c *FakeResourceQuotas) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Invokes(FakeAction{Action: "watch-resourceQuota", Value: resourceVersion}, nil)
c.Fake.Invokes(NewWatchAction("resourcequotas", c.Namespace, label, field, resourceVersion), nil)
return c.Fake.Watch, nil
}
func (c *FakeResourceQuotas) UpdateStatus(resourceQuota *api.ResourceQuota) (*api.ResourceQuota, error) {
action := UpdateActionImpl{}
action.Verb = "update"
action.Resource = "resourcequotas"
action.Subresource = "status"
action.Object = resourceQuota
obj, err := c.Fake.Invokes(action, resourceQuota)
if obj == nil {
return nil, err
}
return obj.(*api.ResourceQuota), err
}

View File

@ -30,32 +30,48 @@ type FakeSecrets struct {
Namespace string
}
func (c *FakeSecrets) List(labels labels.Selector, field fields.Selector) (*api.SecretList, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "list-secrets"}, &api.SecretList{})
return obj.(*api.SecretList), err
}
func (c *FakeSecrets) Get(name string) (*api.Secret, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "get-secret", Value: name}, &api.Secret{})
obj, err := c.Fake.Invokes(NewGetAction("secrets", c.Namespace, name), &api.Secret{})
if obj == nil {
return nil, err
}
return obj.(*api.Secret), err
}
func (c *FakeSecrets) List(label labels.Selector, field fields.Selector) (*api.SecretList, error) {
obj, err := c.Fake.Invokes(NewListAction("secrets", c.Namespace, label, field), &api.SecretList{})
if obj == nil {
return nil, err
}
return obj.(*api.SecretList), err
}
func (c *FakeSecrets) Create(secret *api.Secret) (*api.Secret, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "create-secret", Value: secret}, &api.Secret{})
obj, err := c.Fake.Invokes(NewCreateAction("secrets", c.Namespace, secret), secret)
if obj == nil {
return nil, err
}
return obj.(*api.Secret), err
}
func (c *FakeSecrets) Update(secret *api.Secret) (*api.Secret, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-secret", Value: secret}, &api.Secret{})
obj, err := c.Fake.Invokes(NewUpdateAction("secrets", c.Namespace, secret), secret)
if obj == nil {
return nil, err
}
return obj.(*api.Secret), err
}
func (c *FakeSecrets) Delete(name string) error {
_, err := c.Fake.Invokes(FakeAction{Action: "delete-secret", Value: name}, &api.Secret{})
_, err := c.Fake.Invokes(NewDeleteAction("secrets", c.Namespace, name), &api.Secret{})
return err
}
func (c *FakeSecrets) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Invokes(FakeAction{Action: "watch-secrets", Value: resourceVersion}, nil)
c.Fake.Invokes(NewWatchAction("secrets", c.Namespace, label, field, resourceVersion), nil)
return c.Fake.Watch, c.Fake.Err()
}

View File

@ -30,32 +30,48 @@ type FakeServiceAccounts struct {
Namespace string
}
func (c *FakeServiceAccounts) List(labels labels.Selector, field fields.Selector) (*api.ServiceAccountList, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "list-serviceaccounts"}, &api.ServiceAccountList{})
return obj.(*api.ServiceAccountList), err
}
func (c *FakeServiceAccounts) Get(name string) (*api.ServiceAccount, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "get-serviceaccount", Value: name}, &api.ServiceAccount{})
obj, err := c.Fake.Invokes(NewGetAction("serviceaccounts", c.Namespace, name), &api.ServiceAccount{})
if obj == nil {
return nil, err
}
return obj.(*api.ServiceAccount), err
}
func (c *FakeServiceAccounts) List(label labels.Selector, field fields.Selector) (*api.ServiceAccountList, error) {
obj, err := c.Fake.Invokes(NewListAction("serviceaccounts", c.Namespace, label, field), &api.ServiceAccountList{})
if obj == nil {
return nil, err
}
return obj.(*api.ServiceAccountList), err
}
func (c *FakeServiceAccounts) Create(serviceAccount *api.ServiceAccount) (*api.ServiceAccount, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "create-serviceaccount", Value: serviceAccount}, &api.ServiceAccount{})
obj, err := c.Fake.Invokes(NewCreateAction("serviceaccounts", c.Namespace, serviceAccount), serviceAccount)
if obj == nil {
return nil, err
}
return obj.(*api.ServiceAccount), err
}
func (c *FakeServiceAccounts) Update(serviceAccount *api.ServiceAccount) (*api.ServiceAccount, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-serviceaccount", Value: serviceAccount}, &api.ServiceAccount{})
obj, err := c.Fake.Invokes(NewUpdateAction("serviceaccounts", c.Namespace, serviceAccount), serviceAccount)
if obj == nil {
return nil, err
}
return obj.(*api.ServiceAccount), err
}
func (c *FakeServiceAccounts) Delete(name string) error {
_, err := c.Fake.Invokes(FakeAction{Action: "delete-serviceaccount", Value: name}, &api.ServiceAccount{})
_, err := c.Fake.Invokes(NewDeleteAction("serviceaccounts", c.Namespace, name), &api.ServiceAccount{})
return err
}
func (c *FakeServiceAccounts) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Invokes(FakeAction{Action: "watch-serviceAccounts", Value: resourceVersion}, nil)
c.Fake.Invokes(NewWatchAction("serviceaccounts", c.Namespace, label, field, resourceVersion), nil)
return c.Fake.Watch, c.Fake.Err()
}

View File

@ -30,32 +30,48 @@ type FakeServices struct {
Namespace string
}
func (c *FakeServices) List(selector labels.Selector) (*api.ServiceList, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "list-services"}, &api.ServiceList{})
return obj.(*api.ServiceList), err
}
func (c *FakeServices) Get(name string) (*api.Service, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "get-service", Value: name}, &api.Service{})
obj, err := c.Fake.Invokes(NewGetAction("services", c.Namespace, name), &api.Service{})
if obj == nil {
return nil, err
}
return obj.(*api.Service), err
}
func (c *FakeServices) List(label labels.Selector) (*api.ServiceList, error) {
obj, err := c.Fake.Invokes(NewListAction("services", c.Namespace, label, nil), &api.ServiceList{})
if obj == nil {
return nil, err
}
return obj.(*api.ServiceList), err
}
func (c *FakeServices) Create(service *api.Service) (*api.Service, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "create-service", Value: service}, &api.Service{})
obj, err := c.Fake.Invokes(NewCreateAction("services", c.Namespace, service), service)
if obj == nil {
return nil, err
}
return obj.(*api.Service), err
}
func (c *FakeServices) Update(service *api.Service) (*api.Service, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "update-service", Value: service}, &api.Service{})
obj, err := c.Fake.Invokes(NewUpdateAction("services", c.Namespace, service), service)
if obj == nil {
return nil, err
}
return obj.(*api.Service), err
}
func (c *FakeServices) Delete(name string) error {
_, err := c.Fake.Invokes(FakeAction{Action: "delete-service", Value: name}, &api.Service{})
_, err := c.Fake.Invokes(NewDeleteAction("services", c.Namespace, name), &api.Service{})
return err
}
func (c *FakeServices) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Invokes(FakeAction{Action: "watch-services", Value: resourceVersion}, nil)
return c.Fake.Watch, c.Fake.Err()
c.Fake.Invokes(NewWatchAction("services", c.Namespace, label, field, resourceVersion), nil)
return c.Fake.Watch, nil
}

View File

@ -47,34 +47,36 @@ type ObjectRetriever interface {
// ObjectRetriever interface to satisfy retrieval of lists or retrieval of single items.
// TODO: add support for sub resources
func ObjectReaction(o ObjectRetriever, mapper meta.RESTMapper) ReactionFunc {
return func(action FakeAction) (runtime.Object, error) {
segments := strings.Split(action.Action, "-")
var verb, resource string
switch len(segments) {
case 3:
verb, _, resource = segments[0], segments[1], segments[2]
case 2:
verb, resource = segments[0], segments[1]
default:
return nil, fmt.Errorf("unrecognized action, need two or three segments <verb>-<resource> or <verb>-<subresource>-<resource>: %s", action.Action)
}
_, kind, err := mapper.VersionAndKindForResource(resource)
return func(action Action) (runtime.Object, error) {
_, kind, err := mapper.VersionAndKindForResource(action.GetResource())
if err != nil {
return nil, fmt.Errorf("unrecognized action %s: %v", resource, err)
return nil, fmt.Errorf("unrecognized action %s: %v", action.GetResource(), err)
}
// TODO: have mapper return a Kind for a subresource?
switch verb {
case "list", "search":
switch castAction := action.(type) {
case ListAction:
return o.Kind(kind+"List", "")
case "get", "create", "update", "delete":
// TODO: handle sub resources
if s, ok := action.Value.(string); ok && action.Value != nil {
return o.Kind(kind, s)
case GetAction:
return o.Kind(kind, castAction.GetName())
case DeleteAction:
return o.Kind(kind, castAction.GetName())
case CreateAction:
meta, err := api.ObjectMetaFor(castAction.GetObject())
if err != nil {
return nil, err
}
return o.Kind(kind, "unknown")
return o.Kind(kind, meta.Name)
case UpdateAction:
meta, err := api.ObjectMetaFor(castAction.GetObject())
if err != nil {
return nil, err
}
return o.Kind(kind, meta.Name)
default:
return nil, fmt.Errorf("no reaction implemented for %s", action.Action)
return nil, fmt.Errorf("no reaction implemented for %s", action)
}
return nil, nil
}
}

View File

@ -39,19 +39,14 @@ func NewSimpleFake(objects ...runtime.Object) *Fake {
return &Fake{ReactFn: ObjectReaction(o, latest.RESTMapper)}
}
type FakeAction struct {
Action string
Value interface{}
}
// ReactionFunc is a function that returns an object or error for a given Action
type ReactionFunc func(FakeAction) (runtime.Object, error)
type ReactionFunc func(Action) (runtime.Object, error)
// Fake implements client.Interface. Meant to be embedded into a struct to get a default
// implementation. This makes faking out just the method you want to test easier.
type Fake struct {
sync.RWMutex
actions []FakeAction
actions []Action // these may be castable to other types, but "Action" is the minimum
err error
Watch watch.Interface
@ -61,9 +56,9 @@ type Fake struct {
ReactFn ReactionFunc
}
// Invokes records the provided FakeAction and then invokes the ReactFn (if provided).
// obj is expected to be of the same type a normal call would return.
func (c *Fake) Invokes(action FakeAction, obj runtime.Object) (runtime.Object, error) {
// Invokes records the provided Action and then invokes the ReactFn (if provided).
// defaultReturnObj is expected to be of the same type a normal call would return.
func (c *Fake) Invokes(action Action, defaultReturnObj runtime.Object) (runtime.Object, error) {
c.Lock()
defer c.Unlock()
@ -71,7 +66,7 @@ func (c *Fake) Invokes(action FakeAction, obj runtime.Object) (runtime.Object, e
if c.ReactFn != nil {
return c.ReactFn(action)
}
return obj, c.err
return defaultReturnObj, c.err
}
// ClearActions clears the history of actions called on the fake client
@ -79,14 +74,14 @@ func (c *Fake) ClearActions() {
c.Lock()
c.Unlock()
c.actions = make([]FakeAction, 0)
c.actions = make([]Action, 0)
}
// Actions returns a chronologically ordered slice fake actions called on the fake client
func (c *Fake) Actions() []FakeAction {
func (c *Fake) Actions() []Action {
c.RLock()
defer c.RUnlock()
fa := make([]FakeAction, len(c.actions))
fa := make([]Action, len(c.actions))
copy(fa, c.actions)
return fa
}
@ -164,13 +159,21 @@ func (c *Fake) Namespaces() client.NamespaceInterface {
}
func (c *Fake) ServerVersion() (*version.Info, error) {
c.Invokes(FakeAction{Action: "get-version", Value: nil}, nil)
action := ActionImpl{}
action.Verb = "get"
action.Resource = "version"
c.Invokes(action, nil)
versionInfo := version.Get()
return &versionInfo, nil
}
func (c *Fake) ServerAPIVersions() (*api.APIVersions, error) {
c.Invokes(FakeAction{Action: "get-apiversions", Value: nil}, nil)
action := ActionImpl{}
action.Verb = "get"
action.Resource = "apiversions"
c.Invokes(action, nil)
return &api.APIVersions{Versions: registered.RegisteredVersions}, nil
}

View File

@ -17,6 +17,7 @@ limitations under the License.
package namespacecontroller
import (
"strings"
"testing"
"time"
@ -56,10 +57,10 @@ func TestFinalize(t *testing.T) {
if len(actions) != 1 {
t.Errorf("Expected 1 mock client action, but got %v", len(actions))
}
if actions[0].Action != "finalize-namespace" {
t.Errorf("Expected finalize-namespace action %v", actions[0].Action)
if !actions[0].Matches("create", "namespaces") || actions[0].GetSubresource() != "finalize" {
t.Errorf("Expected finalize-namespace action %v", actions[0])
}
finalizers := actions[0].Value.(*api.Namespace).Spec.Finalizers
finalizers := actions[0].(testclient.CreateAction).GetObject().(*api.Namespace).Spec.Finalizers
if len(finalizers) != 1 {
t.Errorf("There should be a single finalizer remaining")
}
@ -90,18 +91,19 @@ func TestSyncNamespaceThatIsTerminating(t *testing.T) {
}
// TODO: Reuse the constants for all these strings from testclient
expectedActionSet := util.NewStringSet(
testclient.ListControllerAction,
"list-services",
"list-pods",
"list-resourceQuotas",
"list-secrets",
"list-limitRanges",
"list-events",
"finalize-namespace",
"delete-namespace")
strings.Join([]string{"list", "replicationcontrollers", ""}, "-"),
strings.Join([]string{"list", "services", ""}, "-"),
strings.Join([]string{"list", "pods", ""}, "-"),
strings.Join([]string{"list", "resourcequotas", ""}, "-"),
strings.Join([]string{"list", "secrets", ""}, "-"),
strings.Join([]string{"list", "limitranges", ""}, "-"),
strings.Join([]string{"list", "events", ""}, "-"),
strings.Join([]string{"create", "namespaces", "finalize"}, "-"),
strings.Join([]string{"delete", "namespaces", ""}, "-"),
)
actionSet := util.NewStringSet()
for _, action := range mockClient.Actions() {
actionSet.Insert(action.Action)
actionSet.Insert(strings.Join([]string{action.GetVerb(), action.GetResource(), action.GetSubresource()}, "-"))
}
if !actionSet.HasAll(expectedActionSet.List()...) {
t.Errorf("Expected actions: %v, but got: %v", expectedActionSet, actionSet)
@ -126,12 +128,8 @@ func TestSyncNamespaceThatIsActive(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error when synching namespace %v", err)
}
actionSet := util.NewStringSet()
for _, action := range mockClient.Actions() {
actionSet.Insert(action.Action)
}
if len(actionSet) != 0 {
t.Errorf("Expected no action from controller, but got: %v", actionSet)
if len(mockClient.Actions()) != 0 {
t.Errorf("Expected no action from controller, but got: %v", mockClient.Actions())
}
}

View File

@ -343,7 +343,7 @@ func TestMonitorNodeStatusEvictPods(t *testing.T) {
podEvictor.TryEvict(func(nodeName string) { nodeController.deletePods(nodeName) })
podEvicted := false
for _, action := range item.fakeNodeHandler.Actions() {
if action.Action == "delete-pod" {
if action.GetVerb() == "delete" && action.GetResource() == "pods" {
podEvicted = true
}
}

View File

@ -682,8 +682,8 @@ func TestControllerUpdateRequeue(t *testing.T) {
func TestControllerUpdateStatusWithFailure(t *testing.T) {
rc := newReplicationController(1)
fakeClient := &testclient.Fake{
ReactFn: func(f testclient.FakeAction) (runtime.Object, error) {
if f.Action == testclient.GetControllerAction {
ReactFn: func(action testclient.Action) (runtime.Object, error) {
if action.GetVerb() == "get" && action.GetResource() == "replicationcontrollers" {
return rc, nil
}
return &api.ReplicationController{}, fmt.Errorf("Fake error")
@ -694,18 +694,23 @@ func TestControllerUpdateStatusWithFailure(t *testing.T) {
updateReplicaCount(fakeRCClient, *rc, numReplicas)
updates, gets := 0, 0
for _, a := range fakeClient.Actions() {
switch a.Action {
case testclient.GetControllerAction:
if a.GetResource() != "replicationcontrollers" {
t.Errorf("Unexpected action %+v", a)
continue
}
switch action := a.(type) {
case testclient.GetAction:
gets++
// Make sure the get is for the right rc even though the update failed.
if s, ok := a.Value.(string); !ok || s != rc.Name {
t.Errorf("Expected get for rc %v, got %+v instead", rc.Name, s)
if action.GetName() != rc.Name {
t.Errorf("Expected get for rc %v, got %+v instead", rc.Name, action.GetName())
}
case testclient.UpdateControllerAction:
case testclient.UpdateAction:
updates++
// Confirm that the update has the right status.Replicas even though the Get
// returned an rc with replicas=1.
if c, ok := a.Value.(*api.ReplicationController); !ok {
if c, ok := action.GetObject().(*api.ReplicationController); !ok {
t.Errorf("Expected an rc as the argument to update, got %T", c)
} else if c.Status.Replicas != numReplicas {
t.Errorf("Expected update for rc to contain replicas %v, got %v instead",

View File

@ -158,7 +158,7 @@ func TestSyncResourceQuota(t *testing.T) {
t.Fatalf("Unexpected error %v", err)
}
usage := kubeClient.Actions()[1].Value.(*api.ResourceQuota)
usage := kubeClient.Actions()[1].(testclient.UpdateAction).GetObject().(*api.ResourceQuota)
// ensure hard and used limits are what we expected
for k, v := range expectedUsage.Status.Hard {
@ -216,7 +216,7 @@ func TestSyncResourceQuotaSpecChange(t *testing.T) {
t.Fatalf("Unexpected error %v", err)
}
usage := kubeClient.Actions()[1].Value.(*api.ResourceQuota)
usage := kubeClient.Actions()[1].(testclient.UpdateAction).GetObject().(*api.ResourceQuota)
// ensure hard and used limits are what we expected
for k, v := range expectedUsage.Status.Hard {
@ -264,7 +264,7 @@ func TestSyncResourceQuotaNoChange(t *testing.T) {
}
actions := kubeClient.Actions()
if len(actions) != 1 && actions[0].Action != "list-pods" {
if len(actions) != 1 && !actions[0].Matches("list", "pods") {
t.Errorf("SyncResourceQuota made an unexpected client action when state was not dirty: %v", kubeClient.Actions)
}
}

View File

@ -165,7 +165,7 @@ func TestReconcile(t *testing.T) {
}
var finalRoutes []*cloudprovider.Route
var err error
timeoutChan := time.After(50 * time.Millisecond)
timeoutChan := time.After(200 * time.Millisecond)
tick := time.NewTicker(10 * time.Millisecond)
defer tick.Stop()
poll:

View File

@ -119,7 +119,7 @@ func TestCreateExternalLoadBalancer(t *testing.T) {
}
actionFound := false
for _, action := range actions {
if action.Action == "update-service" {
if action.GetVerb() == "update" && action.GetResource() == "services" {
actionFound = true
}
}

View File

@ -199,11 +199,11 @@ func TestServiceAccountCreation(t *testing.T) {
}
for i, expectedName := range tc.ExpectCreatedServiceAccounts {
action := actions[i]
if action.Action != "create-serviceaccount" {
t.Errorf("%s: Unexpected action %s", k, action.Action)
if !action.Matches("create", "serviceaccounts") {
t.Errorf("%s: Unexpected action %s", k, action)
break
}
createdAccount := action.Value.(*api.ServiceAccount)
createdAccount := action.(testclient.CreateAction).GetObject().(*api.ServiceAccount)
if createdAccount.Name != expectedName {
t.Errorf("%s: Expected %s to be created, got %s", k, expectedName, createdAccount.Name)
}

View File

@ -172,16 +172,16 @@ func TestTokenCreation(t *testing.T) {
UpdatedSecret *api.Secret
DeletedSecret *api.Secret
ExpectedActions []testclient.FakeAction
ExpectedActions []testclient.Action
}{
"new serviceaccount with no secrets": {
ClientObjects: []runtime.Object{serviceAccount(emptySecretReferences()), createdTokenSecret()},
AddedServiceAccount: serviceAccount(emptySecretReferences()),
ExpectedActions: []testclient.FakeAction{
{Action: "create-secret", Value: createdTokenSecret()},
{Action: "get-serviceaccount", Value: "default"},
{Action: "update-serviceaccount", Value: serviceAccount(addTokenSecretReference(emptySecretReferences()))},
ExpectedActions: []testclient.Action{
testclient.NewCreateAction("secrets", api.NamespaceDefault, createdTokenSecret()),
testclient.NewGetAction("serviceaccounts", api.NamespaceDefault, "default"),
testclient.NewUpdateAction("serviceaccounts", api.NamespaceDefault, serviceAccount(addTokenSecretReference(emptySecretReferences()))),
},
},
"new serviceaccount with no secrets with unsynced secret store": {
@ -190,20 +190,20 @@ func TestTokenCreation(t *testing.T) {
SecretsSyncPending: true,
AddedServiceAccount: serviceAccount(emptySecretReferences()),
ExpectedActions: []testclient.FakeAction{
{Action: "create-secret", Value: createdTokenSecret()},
{Action: "get-serviceaccount", Value: "default"},
{Action: "update-serviceaccount", Value: serviceAccount(addTokenSecretReference(emptySecretReferences()))},
ExpectedActions: []testclient.Action{
testclient.NewCreateAction("secrets", api.NamespaceDefault, createdTokenSecret()),
testclient.NewGetAction("serviceaccounts", api.NamespaceDefault, "default"),
testclient.NewUpdateAction("serviceaccounts", api.NamespaceDefault, serviceAccount(addTokenSecretReference(emptySecretReferences()))),
},
},
"new serviceaccount with missing secrets": {
ClientObjects: []runtime.Object{serviceAccount(missingSecretReferences()), createdTokenSecret()},
AddedServiceAccount: serviceAccount(missingSecretReferences()),
ExpectedActions: []testclient.FakeAction{
{Action: "create-secret", Value: createdTokenSecret()},
{Action: "get-serviceaccount", Value: "default"},
{Action: "update-serviceaccount", Value: serviceAccount(addTokenSecretReference(missingSecretReferences()))},
ExpectedActions: []testclient.Action{
testclient.NewCreateAction("secrets", api.NamespaceDefault, createdTokenSecret()),
testclient.NewGetAction("serviceaccounts", api.NamespaceDefault, "default"),
testclient.NewUpdateAction("serviceaccounts", api.NamespaceDefault, serviceAccount(addTokenSecretReference(missingSecretReferences()))),
},
},
"new serviceaccount with missing secrets with unsynced secret store": {
@ -212,16 +212,16 @@ func TestTokenCreation(t *testing.T) {
SecretsSyncPending: true,
AddedServiceAccount: serviceAccount(missingSecretReferences()),
ExpectedActions: []testclient.FakeAction{},
ExpectedActions: []testclient.Action{},
},
"new serviceaccount with non-token secrets": {
ClientObjects: []runtime.Object{serviceAccount(regularSecretReferences()), createdTokenSecret(), opaqueSecret()},
AddedServiceAccount: serviceAccount(regularSecretReferences()),
ExpectedActions: []testclient.FakeAction{
{Action: "create-secret", Value: createdTokenSecret()},
{Action: "get-serviceaccount", Value: "default"},
{Action: "update-serviceaccount", Value: serviceAccount(addTokenSecretReference(regularSecretReferences()))},
ExpectedActions: []testclient.Action{
testclient.NewCreateAction("secrets", api.NamespaceDefault, createdTokenSecret()),
testclient.NewGetAction("serviceaccounts", api.NamespaceDefault, "default"),
testclient.NewUpdateAction("serviceaccounts", api.NamespaceDefault, serviceAccount(addTokenSecretReference(regularSecretReferences()))),
},
},
"new serviceaccount with token secrets": {
@ -229,17 +229,17 @@ func TestTokenCreation(t *testing.T) {
ExistingSecrets: []*api.Secret{serviceAccountTokenSecret()},
AddedServiceAccount: serviceAccount(tokenSecretReferences()),
ExpectedActions: []testclient.FakeAction{},
ExpectedActions: []testclient.Action{},
},
"updated serviceaccount with no secrets": {
ClientObjects: []runtime.Object{serviceAccount(emptySecretReferences()), createdTokenSecret()},
UpdatedServiceAccount: serviceAccount(emptySecretReferences()),
ExpectedActions: []testclient.FakeAction{
{Action: "create-secret", Value: createdTokenSecret()},
{Action: "get-serviceaccount", Value: "default"},
{Action: "update-serviceaccount", Value: serviceAccount(addTokenSecretReference(emptySecretReferences()))},
ExpectedActions: []testclient.Action{
testclient.NewCreateAction("secrets", api.NamespaceDefault, createdTokenSecret()),
testclient.NewGetAction("serviceaccounts", api.NamespaceDefault, "default"),
testclient.NewUpdateAction("serviceaccounts", api.NamespaceDefault, serviceAccount(addTokenSecretReference(emptySecretReferences()))),
},
},
"updated serviceaccount with no secrets with unsynced secret store": {
@ -248,20 +248,20 @@ func TestTokenCreation(t *testing.T) {
SecretsSyncPending: true,
UpdatedServiceAccount: serviceAccount(emptySecretReferences()),
ExpectedActions: []testclient.FakeAction{
{Action: "create-secret", Value: createdTokenSecret()},
{Action: "get-serviceaccount", Value: "default"},
{Action: "update-serviceaccount", Value: serviceAccount(addTokenSecretReference(emptySecretReferences()))},
ExpectedActions: []testclient.Action{
testclient.NewCreateAction("secrets", api.NamespaceDefault, createdTokenSecret()),
testclient.NewGetAction("serviceaccounts", api.NamespaceDefault, "default"),
testclient.NewUpdateAction("serviceaccounts", api.NamespaceDefault, serviceAccount(addTokenSecretReference(emptySecretReferences()))),
},
},
"updated serviceaccount with missing secrets": {
ClientObjects: []runtime.Object{serviceAccount(missingSecretReferences()), createdTokenSecret()},
UpdatedServiceAccount: serviceAccount(missingSecretReferences()),
ExpectedActions: []testclient.FakeAction{
{Action: "create-secret", Value: createdTokenSecret()},
{Action: "get-serviceaccount", Value: "default"},
{Action: "update-serviceaccount", Value: serviceAccount(addTokenSecretReference(missingSecretReferences()))},
ExpectedActions: []testclient.Action{
testclient.NewCreateAction("secrets", api.NamespaceDefault, createdTokenSecret()),
testclient.NewGetAction("serviceaccounts", api.NamespaceDefault, "default"),
testclient.NewUpdateAction("serviceaccounts", api.NamespaceDefault, serviceAccount(addTokenSecretReference(missingSecretReferences()))),
},
},
"updated serviceaccount with missing secrets with unsynced secret store": {
@ -270,46 +270,46 @@ func TestTokenCreation(t *testing.T) {
SecretsSyncPending: true,
UpdatedServiceAccount: serviceAccount(missingSecretReferences()),
ExpectedActions: []testclient.FakeAction{},
ExpectedActions: []testclient.Action{},
},
"updated serviceaccount with non-token secrets": {
ClientObjects: []runtime.Object{serviceAccount(regularSecretReferences()), createdTokenSecret(), opaqueSecret()},
UpdatedServiceAccount: serviceAccount(regularSecretReferences()),
ExpectedActions: []testclient.FakeAction{
{Action: "create-secret", Value: createdTokenSecret()},
{Action: "get-serviceaccount", Value: "default"},
{Action: "update-serviceaccount", Value: serviceAccount(addTokenSecretReference(regularSecretReferences()))},
ExpectedActions: []testclient.Action{
testclient.NewCreateAction("secrets", api.NamespaceDefault, createdTokenSecret()),
testclient.NewGetAction("serviceaccounts", api.NamespaceDefault, "default"),
testclient.NewUpdateAction("serviceaccounts", api.NamespaceDefault, serviceAccount(addTokenSecretReference(regularSecretReferences()))),
},
},
"updated serviceaccount with token secrets": {
ExistingSecrets: []*api.Secret{serviceAccountTokenSecret()},
UpdatedServiceAccount: serviceAccount(tokenSecretReferences()),
ExpectedActions: []testclient.FakeAction{},
ExpectedActions: []testclient.Action{},
},
"deleted serviceaccount with no secrets": {
DeletedServiceAccount: serviceAccount(emptySecretReferences()),
ExpectedActions: []testclient.FakeAction{},
ExpectedActions: []testclient.Action{},
},
"deleted serviceaccount with missing secrets": {
DeletedServiceAccount: serviceAccount(missingSecretReferences()),
ExpectedActions: []testclient.FakeAction{},
ExpectedActions: []testclient.Action{},
},
"deleted serviceaccount with non-token secrets": {
ClientObjects: []runtime.Object{opaqueSecret()},
DeletedServiceAccount: serviceAccount(regularSecretReferences()),
ExpectedActions: []testclient.FakeAction{},
ExpectedActions: []testclient.Action{},
},
"deleted serviceaccount with token secrets": {
ClientObjects: []runtime.Object{serviceAccountTokenSecret()},
ExistingSecrets: []*api.Secret{serviceAccountTokenSecret()},
DeletedServiceAccount: serviceAccount(tokenSecretReferences()),
ExpectedActions: []testclient.FakeAction{
{Action: "delete-secret", Value: "token-secret-1"},
ExpectedActions: []testclient.Action{
testclient.NewDeleteAction("secrets", api.NamespaceDefault, "token-secret-1"),
},
},
@ -317,24 +317,24 @@ func TestTokenCreation(t *testing.T) {
ClientObjects: []runtime.Object{serviceAccountTokenSecret()},
AddedSecret: serviceAccountTokenSecret(),
ExpectedActions: []testclient.FakeAction{
{Action: "get-serviceaccount", Value: "default"},
{Action: "delete-secret", Value: "token-secret-1"},
ExpectedActions: []testclient.Action{
testclient.NewGetAction("serviceaccounts", api.NamespaceDefault, "default"),
testclient.NewDeleteAction("secrets", api.NamespaceDefault, "token-secret-1"),
},
},
"added secret with serviceaccount": {
ExistingServiceAccount: serviceAccount(tokenSecretReferences()),
AddedSecret: serviceAccountTokenSecret(),
ExpectedActions: []testclient.FakeAction{},
ExpectedActions: []testclient.Action{},
},
"added token secret without token data": {
ClientObjects: []runtime.Object{serviceAccountTokenSecretWithoutTokenData()},
ExistingServiceAccount: serviceAccount(tokenSecretReferences()),
AddedSecret: serviceAccountTokenSecretWithoutTokenData(),
ExpectedActions: []testclient.FakeAction{
{Action: "update-secret", Value: serviceAccountTokenSecret()},
ExpectedActions: []testclient.Action{
testclient.NewUpdateAction("secrets", api.NamespaceDefault, serviceAccountTokenSecret()),
},
},
"added token secret without ca data": {
@ -342,8 +342,8 @@ func TestTokenCreation(t *testing.T) {
ExistingServiceAccount: serviceAccount(tokenSecretReferences()),
AddedSecret: serviceAccountTokenSecretWithoutCAData(),
ExpectedActions: []testclient.FakeAction{
{Action: "update-secret", Value: serviceAccountTokenSecret()},
ExpectedActions: []testclient.Action{
testclient.NewUpdateAction("secrets", api.NamespaceDefault, serviceAccountTokenSecret()),
},
},
"added token secret with mismatched ca data": {
@ -351,8 +351,8 @@ func TestTokenCreation(t *testing.T) {
ExistingServiceAccount: serviceAccount(tokenSecretReferences()),
AddedSecret: serviceAccountTokenSecretWithCAData([]byte("mismatched")),
ExpectedActions: []testclient.FakeAction{
{Action: "update-secret", Value: serviceAccountTokenSecret()},
ExpectedActions: []testclient.Action{
testclient.NewUpdateAction("secrets", api.NamespaceDefault, serviceAccountTokenSecret()),
},
},
@ -360,24 +360,24 @@ func TestTokenCreation(t *testing.T) {
ClientObjects: []runtime.Object{serviceAccountTokenSecret()},
UpdatedSecret: serviceAccountTokenSecret(),
ExpectedActions: []testclient.FakeAction{
{Action: "get-serviceaccount", Value: "default"},
{Action: "delete-secret", Value: "token-secret-1"},
ExpectedActions: []testclient.Action{
testclient.NewGetAction("serviceaccounts", api.NamespaceDefault, "default"),
testclient.NewDeleteAction("secrets", api.NamespaceDefault, "token-secret-1"),
},
},
"updated secret with serviceaccount": {
ExistingServiceAccount: serviceAccount(tokenSecretReferences()),
UpdatedSecret: serviceAccountTokenSecret(),
ExpectedActions: []testclient.FakeAction{},
ExpectedActions: []testclient.Action{},
},
"updated token secret without token data": {
ClientObjects: []runtime.Object{serviceAccountTokenSecretWithoutTokenData()},
ExistingServiceAccount: serviceAccount(tokenSecretReferences()),
UpdatedSecret: serviceAccountTokenSecretWithoutTokenData(),
ExpectedActions: []testclient.FakeAction{
{Action: "update-secret", Value: serviceAccountTokenSecret()},
ExpectedActions: []testclient.Action{
testclient.NewUpdateAction("secrets", api.NamespaceDefault, serviceAccountTokenSecret()),
},
},
"updated token secret without ca data": {
@ -385,8 +385,8 @@ func TestTokenCreation(t *testing.T) {
ExistingServiceAccount: serviceAccount(tokenSecretReferences()),
UpdatedSecret: serviceAccountTokenSecretWithoutCAData(),
ExpectedActions: []testclient.FakeAction{
{Action: "update-secret", Value: serviceAccountTokenSecret()},
ExpectedActions: []testclient.Action{
testclient.NewUpdateAction("secrets", api.NamespaceDefault, serviceAccountTokenSecret()),
},
},
"updated token secret with mismatched ca data": {
@ -394,30 +394,30 @@ func TestTokenCreation(t *testing.T) {
ExistingServiceAccount: serviceAccount(tokenSecretReferences()),
UpdatedSecret: serviceAccountTokenSecretWithCAData([]byte("mismatched")),
ExpectedActions: []testclient.FakeAction{
{Action: "update-secret", Value: serviceAccountTokenSecret()},
ExpectedActions: []testclient.Action{
testclient.NewUpdateAction("secrets", api.NamespaceDefault, serviceAccountTokenSecret()),
},
},
"deleted secret without serviceaccount": {
DeletedSecret: serviceAccountTokenSecret(),
ExpectedActions: []testclient.FakeAction{},
ExpectedActions: []testclient.Action{},
},
"deleted secret with serviceaccount with reference": {
ClientObjects: []runtime.Object{serviceAccount(tokenSecretReferences())},
ExistingServiceAccount: serviceAccount(tokenSecretReferences()),
DeletedSecret: serviceAccountTokenSecret(),
ExpectedActions: []testclient.FakeAction{
{Action: "get-serviceaccount", Value: "default"},
{Action: "update-serviceaccount", Value: serviceAccount(emptySecretReferences())},
ExpectedActions: []testclient.Action{
testclient.NewGetAction("serviceaccounts", api.NamespaceDefault, "default"),
testclient.NewUpdateAction("serviceaccounts", api.NamespaceDefault, serviceAccount(emptySecretReferences())),
},
},
"deleted secret with serviceaccount without reference": {
ExistingServiceAccount: serviceAccount(emptySecretReferences()),
DeletedSecret: serviceAccountTokenSecret(),
ExpectedActions: []testclient.FakeAction{},
ExpectedActions: []testclient.Action{},
},
}
@ -470,12 +470,8 @@ func TestTokenCreation(t *testing.T) {
}
expectedAction := tc.ExpectedActions[i]
if expectedAction.Action != action.Action {
t.Errorf("%s: Expected %s, got %s", k, expectedAction.Action, action.Action)
continue
}
if !reflect.DeepEqual(expectedAction.Value, action.Value) {
t.Errorf("%s: Expected\n\t%#v\ngot\n\t%#v", k, expectedAction.Value, action.Value)
if !reflect.DeepEqual(expectedAction, action) {
t.Errorf("%s: Expected\n\t%#v\ngot\n\t%#v", k, expectedAction, action)
continue
}
}

View File

@ -70,7 +70,7 @@ type fakeRc struct {
}
func (c *fakeRc) Get(name string) (*api.ReplicationController, error) {
action := testclient.FakeAction{Action: "get-controller", Value: name}
action := testclient.NewGetAction("replicationcontrollers", "", name)
if len(c.responses) == 0 {
return nil, fmt.Errorf("Unexpected Action: %s", action)
}
@ -81,12 +81,12 @@ func (c *fakeRc) Get(name string) (*api.ReplicationController, error) {
}
func (c *fakeRc) Create(controller *api.ReplicationController) (*api.ReplicationController, error) {
c.Fake.Invokes(testclient.FakeAction{Action: "create-controller", Value: controller.ObjectMeta.Name}, nil)
c.Fake.Invokes(testclient.NewCreateAction("replicationcontrollers", controller.Namespace, controller), nil)
return controller, nil
}
func (c *fakeRc) Update(controller *api.ReplicationController) (*api.ReplicationController, error) {
c.Fake.Invokes(testclient.FakeAction{Action: "update-controller", Value: controller.ObjectMeta.Name}, nil)
c.Fake.Invokes(testclient.NewUpdateAction("replicationcontrollers", controller.Namespace, controller), nil)
return controller, nil
}

View File

@ -77,10 +77,10 @@ func TestReplicationControllerScale(t *testing.T) {
if len(actions) != 2 {
t.Errorf("unexpected actions: %v, expected 2 actions (get, update)", actions)
}
if actions[0].Action != "get-replicationController" || actions[0].Value != name {
if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "replicationcontrollers" || action.GetName() != name {
t.Errorf("unexpected action: %v, expected get-replicationController %s", actions[0], name)
}
if actions[1].Action != "update-replicationController" || actions[1].Value.(*api.ReplicationController).Spec.Replicas != int(count) {
if action, ok := actions[1].(testclient.UpdateAction); !ok || action.GetResource() != "replicationcontrollers" || action.GetObject().(*api.ReplicationController).Spec.Replicas != int(count) {
t.Errorf("unexpected action %v, expected update-replicationController with replicas = %d", actions[1], count)
}
}
@ -101,7 +101,7 @@ func TestReplicationControllerScaleFailsPreconditions(t *testing.T) {
if len(actions) != 1 {
t.Errorf("unexpected actions: %v, expected 2 actions (get, update)", actions)
}
if actions[0].Action != "get-replicationController" || actions[0].Value != name {
if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "replicationcontrollers" || action.GetName() != name {
t.Errorf("unexpected action: %v, expected get-replicationController %s", actions[0], name)
}
}

View File

@ -51,9 +51,13 @@ func TestReplicationControllerStop(t *testing.T) {
if len(actions) != 7 {
t.Errorf("unexpected actions: %v, expected 6 actions (get, list, get, update, get, get, delete)", fake.Actions)
}
for i, action := range []string{"get", "list", "get", "update", "get", "get", "delete"} {
if actions[i].Action != action+"-replicationController" {
t.Errorf("unexpected action: %+v, expected %s-replicationController", actions[i], action)
for i, verb := range []string{"get", "list", "get", "update", "get", "get", "delete"} {
if actions[i].GetResource() != "replicationcontrollers" {
t.Errorf("unexpected action: %+v, expected %s-replicationController", actions[i], verb)
continue
}
if actions[i].GetVerb() != verb {
t.Errorf("unexpected action: %+v, expected %s-replicationController", actions[i], verb)
}
}
}
@ -99,7 +103,7 @@ func TestSimpleStop(t *testing.T) {
tests := []struct {
fake *reaperFake
kind string
actions []string
actions []testclient.Action
expectError bool
test string
}{
@ -107,8 +111,11 @@ func TestSimpleStop(t *testing.T) {
fake: &reaperFake{
Fake: &testclient.Fake{},
},
kind: "Pod",
actions: []string{"get-pod", "delete-pod"},
kind: "Pod",
actions: []testclient.Action{
testclient.NewGetAction("pods", api.NamespaceDefault, "foo"),
testclient.NewDeleteAction("pods", api.NamespaceDefault, "foo"),
},
expectError: false,
test: "stop pod succeeds",
},
@ -116,8 +123,11 @@ func TestSimpleStop(t *testing.T) {
fake: &reaperFake{
Fake: &testclient.Fake{},
},
kind: "Service",
actions: []string{"get-service", "delete-service"},
kind: "Service",
actions: []testclient.Action{
testclient.NewGetAction("services", api.NamespaceDefault, "foo"),
testclient.NewDeleteAction("services", api.NamespaceDefault, "foo"),
},
expectError: false,
test: "stop service succeeds",
},
@ -127,7 +137,7 @@ func TestSimpleStop(t *testing.T) {
noSuchPod: true,
},
kind: "Pod",
actions: []string{},
actions: []testclient.Action{},
expectError: true,
test: "stop pod fails, no pod",
},
@ -136,8 +146,10 @@ func TestSimpleStop(t *testing.T) {
Fake: &testclient.Fake{},
noDeleteService: true,
},
kind: "Service",
actions: []string{"get-service"},
kind: "Service",
actions: []testclient.Action{
testclient.NewGetAction("services", api.NamespaceDefault, "foo"),
},
expectError: true,
test: "stop service fails, can't delete",
},
@ -166,8 +178,8 @@ func TestSimpleStop(t *testing.T) {
}
for i, action := range actions {
testAction := test.actions[i]
if action.Action != testAction {
t.Errorf("unexpected action: %v; expected %v (%s)", action, testAction, test.test)
if action != testAction {
t.Errorf("unexpected action: %#v; expected %v (%s)", action, testAction, test.test)
}
}
}

View File

@ -2323,10 +2323,13 @@ func TestUpdateNewNodeStatus(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}
actions := kubeClient.Actions()
if len(actions) != 2 || actions[1].Action != "update-status-node" {
if len(actions) != 2 {
t.Fatalf("unexpected actions: %v", actions)
}
updatedNode, ok := actions[1].Value.(*api.Node)
if !actions[1].Matches("update", "nodes") || actions[1].GetSubresource() != "status" {
t.Fatalf("unexpected actions: %v", actions)
}
updatedNode, ok := actions[1].(testclient.UpdateAction).GetObject().(*api.Node)
if !ok {
t.Errorf("unexpected object type")
}
@ -2424,7 +2427,11 @@ func TestUpdateExistingNodeStatus(t *testing.T) {
if len(actions) != 2 {
t.Errorf("unexpected actions: %v", actions)
}
updatedNode, ok := actions[1].Value.(*api.Node)
updateAction, ok := actions[1].(testclient.UpdateAction)
if !ok {
t.Errorf("unexpected action type. expected UpdateAction, got %#v", actions[1])
}
updatedNode, ok := updateAction.GetObject().(*api.Node)
if !ok {
t.Errorf("unexpected object type")
}
@ -2509,12 +2516,15 @@ func TestUpdateNodeStatusWithoutContainerRuntime(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}
actions := kubeClient.Actions()
if len(actions) != 2 || actions[1].Action != "update-status-node" {
if len(actions) != 2 {
t.Fatalf("unexpected actions: %v", actions)
}
updatedNode, ok := actions[1].Value.(*api.Node)
if !actions[1].Matches("update", "nodes") || actions[1].GetSubresource() != "status" {
t.Fatalf("unexpected actions: %v", actions)
}
updatedNode, ok := actions[1].(testclient.UpdateAction).GetObject().(*api.Node)
if !ok {
t.Errorf("unexpected object type")
t.Errorf("unexpected action type. expected UpdateAction, got %#v", actions[1])
}
if updatedNode.Status.Conditions[0].LastHeartbeatTime.IsZero() {
@ -2926,13 +2936,8 @@ func TestRegisterExistingNodeWithApiserver(t *testing.T) {
testKubelet := newTestKubelet(t)
kubelet := testKubelet.kubelet
kubeClient := testKubelet.fakeKubeClient
kubeClient.ReactFn = func(action testclient.FakeAction) (runtime.Object, error) {
segments := strings.Split(action.Action, "-")
if len(segments) < 2 {
return nil, fmt.Errorf("unrecognized action, need two or three segments <verb>-<resource> or <verb>-<subresource>-<resource>: %s", action.Action)
}
verb := segments[0]
switch verb {
kubeClient.ReactFn = func(action testclient.Action) (runtime.Object, error) {
switch action.GetVerb() {
case "create":
// Return an error on create.
return &api.Node{}, &apierrors.StatusError{
@ -2945,7 +2950,7 @@ func TestRegisterExistingNodeWithApiserver(t *testing.T) {
Spec: api.NodeSpec{ExternalID: testKubeletHostname},
}, nil
default:
return nil, fmt.Errorf("no reaction implemented for %s", action.Action)
return nil, fmt.Errorf("no reaction implemented for %s", action)
}
}
machineInfo := &cadvisorApi.MachineInfo{

View File

@ -52,14 +52,16 @@ func getRandomPodStatus() api.PodStatus {
}
}
func verifyActions(t *testing.T, kubeClient client.Interface, expectedActions []string) {
func verifyActions(t *testing.T, kubeClient client.Interface, expectedActions []testclient.Action) {
actions := kubeClient.(*testclient.Fake).Actions()
if len(actions) != len(expectedActions) {
t.Errorf("unexpected actions, got: %s expected: %s", actions, expectedActions)
return
}
for i := 0; i < len(actions); i++ {
if actions[i].Action != expectedActions[i] {
e := expectedActions[i]
a := actions[i]
if !a.Matches(e.GetVerb(), e.GetResource()) || a.GetSubresource() != e.GetSubresource() {
t.Errorf("unexpected actions, got: %s expected: %s", actions, expectedActions)
}
}
@ -158,7 +160,11 @@ func TestSyncBatch(t *testing.T) {
if err != nil {
t.Errorf("unexpected syncing error: %v", err)
}
verifyActions(t, syncer.kubeClient, []string{"get-pod", "update-status-pod"})
verifyActions(t, syncer.kubeClient, []testclient.Action{
testclient.GetActionImpl{ActionImpl: testclient.ActionImpl{Verb: "get", Resource: "pods"}},
testclient.UpdateActionImpl{ActionImpl: testclient.ActionImpl{Verb: "update", Resource: "pods", Subresource: "status"}},
},
)
}
// shuffle returns a new shuffled list of container statuses.

View File

@ -37,8 +37,8 @@ func TestAdmissionDeny(t *testing.T) {
func testAdmission(t *testing.T, pod *api.Pod, shouldAccept bool) {
mockClient := &testclient.Fake{
ReactFn: func(action testclient.FakeAction) (runtime.Object, error) {
if action.Action == "get-pod" && action.Value.(string) == pod.Name {
ReactFn: func(action testclient.Action) (runtime.Object, error) {
if action.Matches("get", "pods") && action.(testclient.GetAction).GetName() == pod.Name {
return pod, nil
}
t.Errorf("Unexpected API call: %#v", action)

View File

@ -49,7 +49,7 @@ func TestAdmission(t *testing.T) {
if len(actions) != 1 {
t.Errorf("Expected a create-namespace request")
}
if actions[0].Action != "create-namespace" {
if !actions[0].Matches("create", "namespaces") {
t.Errorf("Expected a create-namespace request to be made via the client")
}
}