Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
618416ba
Commit
618416ba
authored
Jul 29, 2015
by
Mike Danese
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10783 from mikedanese/make-test-client-threadsafe
make testclient threadsafe by guarding internal state with accessors
parents
5dff0496
1b84fb7d
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
151 additions
and
99 deletions
+151
-99
fake_endpoints.go
pkg/client/testclient/fake_endpoints.go
+2
-2
fake_events.go
pkg/client/testclient/fake_events.go
+3
-3
fake_limit_ranges.go
pkg/client/testclient/fake_limit_ranges.go
+1
-1
fake_namespaces.go
pkg/client/testclient/fake_namespaces.go
+3
-3
fake_nodes.go
pkg/client/testclient/fake_nodes.go
+2
-2
fake_persistent_volume_claims.go
pkg/client/testclient/fake_persistent_volume_claims.go
+2
-2
fake_persistent_volumes.go
pkg/client/testclient/fake_persistent_volumes.go
+2
-2
fake_pod_templates.go
pkg/client/testclient/fake_pod_templates.go
+2
-2
fake_pods.go
pkg/client/testclient/fake_pods.go
+3
-3
fake_replication_controllers.go
pkg/client/testclient/fake_replication_controllers.go
+1
-1
fake_resource_quotas.go
pkg/client/testclient/fake_resource_quotas.go
+1
-1
fake_secrets.go
pkg/client/testclient/fake_secrets.go
+2
-2
fake_service_accounts.go
pkg/client/testclient/fake_service_accounts.go
+2
-2
fake_services.go
pkg/client/testclient/fake_services.go
+2
-2
testclient.go
pkg/client/testclient/testclient.go
+46
-7
nodecontroller_test.go
pkg/cloudprovider/nodecontroller/nodecontroller_test.go
+1
-1
servicecontroller_test.go
...cloudprovider/servicecontroller/servicecontroller_test.go
+7
-6
replication_controller_test.go
pkg/controller/replication/replication_controller_test.go
+1
-1
rolling_updater_test.go
pkg/kubectl/rolling_updater_test.go
+3
-3
scale_test.go
pkg/kubectl/scale_test.go
+12
-10
stop_test.go
pkg/kubectl/stop_test.go
+7
-5
kubelet_test.go
pkg/kubelet/kubelet_test.go
+14
-11
status_manager_test.go
pkg/kubelet/status_manager_test.go
+1
-1
namespace_controller_test.go
pkg/namespace/namespace_controller_test.go
+10
-9
resource_quota_controller_test.go
pkg/resourcequota/resource_quota_controller_test.go
+4
-3
serviceaccounts_controller_test.go
pkg/serviceaccount/serviceaccounts_controller_test.go
+4
-3
tokens_controller_test.go
pkg/serviceaccount/tokens_controller_test.go
+5
-4
admission_test.go
...n/pkg/admission/namespace/autoprovision/admission_test.go
+8
-7
No files found.
pkg/client/testclient/fake_endpoints.go
View file @
618416ba
...
...
@@ -51,8 +51,8 @@ func (c *FakeEndpoints) Delete(name string) error {
}
func
(
c
*
FakeEndpoints
)
Watch
(
label
labels
.
Selector
,
field
fields
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"watch-endpoints"
,
Value
:
resourceVersion
}
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
c
.
Fake
.
Invokes
(
FakeAction
{
Action
:
"watch-endpoints"
,
Value
:
resourceVersion
},
nil
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
()
}
func
(
c
*
FakeEndpoints
)
Update
(
endpoints
*
api
.
Endpoints
)
(
*
api
.
Endpoints
,
error
)
{
...
...
pkg/client/testclient/fake_events.go
View file @
618416ba
...
...
@@ -56,8 +56,8 @@ func (c *FakeEvents) Get(id string) (*api.Event, error) {
// 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
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"watch-events"
,
Value
:
resourceVersion
}
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
c
.
Fake
.
Invokes
(
FakeAction
{
Action
:
"watch-events"
,
Value
:
resourceVersion
},
nil
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
()
}
// Search returns a list of events matching the specified object.
...
...
@@ -72,6 +72,6 @@ func (c *FakeEvents) Delete(name string) error {
}
func
(
c
*
FakeEvents
)
GetFieldSelector
(
involvedObjectName
,
involvedObjectNamespace
,
involvedObjectKind
,
involvedObjectUID
*
string
)
fields
.
Selector
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"get-field-selector"
}
)
c
.
Fake
.
Invokes
(
FakeAction
{
Action
:
"get-field-selector"
},
nil
)
return
fields
.
Everything
()
}
pkg/client/testclient/fake_limit_ranges.go
View file @
618416ba
...
...
@@ -56,6 +56,6 @@ func (c *FakeLimitRanges) Update(limitRange *api.LimitRange) (*api.LimitRange, e
}
func
(
c
*
FakeLimitRanges
)
Watch
(
label
labels
.
Selector
,
field
fields
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"watch-limitRange"
,
Value
:
resourceVersion
}
)
c
.
Fake
.
Invokes
(
FakeAction
{
Action
:
"watch-limitRange"
,
Value
:
resourceVersion
},
nil
)
return
c
.
Fake
.
Watch
,
nil
}
pkg/client/testclient/fake_namespaces.go
View file @
618416ba
...
...
@@ -45,8 +45,8 @@ func (c *FakeNamespaces) Delete(name string) error {
}
func
(
c
*
FakeNamespaces
)
Create
(
namespace
*
api
.
Namespace
)
(
*
api
.
Namespace
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"create-namespace"
}
)
return
&
api
.
Namespace
{},
c
.
Fake
.
Err
c
.
Fake
.
Invokes
(
FakeAction
{
Action
:
"create-namespace"
},
nil
)
return
&
api
.
Namespace
{},
c
.
Fake
.
Err
()
}
func
(
c
*
FakeNamespaces
)
Update
(
namespace
*
api
.
Namespace
)
(
*
api
.
Namespace
,
error
)
{
...
...
@@ -55,7 +55,7 @@ func (c *FakeNamespaces) Update(namespace *api.Namespace) (*api.Namespace, error
}
func
(
c
*
FakeNamespaces
)
Watch
(
label
labels
.
Selector
,
field
fields
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"watch-namespaces"
,
Value
:
resourceVersion
}
)
c
.
Fake
.
Invokes
(
FakeAction
{
Action
:
"watch-namespaces"
,
Value
:
resourceVersion
},
nil
)
return
c
.
Fake
.
Watch
,
nil
}
...
...
pkg/client/testclient/fake_nodes.go
View file @
618416ba
...
...
@@ -60,6 +60,6 @@ func (c *FakeNodes) UpdateStatus(minion *api.Node) (*api.Node, error) {
}
func
(
c
*
FakeNodes
)
Watch
(
label
labels
.
Selector
,
field
fields
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"watch-nodes"
,
Value
:
resourceVersion
}
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
c
.
Fake
.
Invokes
(
FakeAction
{
Action
:
"watch-nodes"
,
Value
:
resourceVersion
},
nil
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
()
}
pkg/client/testclient/fake_persistent_volume_claims.go
View file @
618416ba
...
...
@@ -59,6 +59,6 @@ func (c *FakePersistentVolumeClaims) UpdateStatus(claim *api.PersistentVolumeCla
}
func
(
c
*
FakePersistentVolumeClaims
)
Watch
(
label
labels
.
Selector
,
field
fields
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"watch-persistentVolumeClaims"
,
Value
:
resourceVersion
}
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
c
.
Fake
.
Invokes
(
FakeAction
{
Action
:
"watch-persistentVolumeClaims"
,
Value
:
resourceVersion
},
nil
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
()
}
pkg/client/testclient/fake_persistent_volumes.go
View file @
618416ba
...
...
@@ -59,6 +59,6 @@ func (c *FakePersistentVolumes) UpdateStatus(pv *api.PersistentVolume) (*api.Per
}
func
(
c
*
FakePersistentVolumes
)
Watch
(
label
labels
.
Selector
,
field
fields
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"watch-persistentVolumes"
,
Value
:
resourceVersion
}
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
c
.
Fake
.
Invokes
(
FakeAction
{
Action
:
"watch-persistentVolumes"
,
Value
:
resourceVersion
},
nil
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
()
}
pkg/client/testclient/fake_pod_templates.go
View file @
618416ba
...
...
@@ -56,6 +56,6 @@ func (c *FakePodTemplates) Update(pod *api.PodTemplate) (*api.PodTemplate, error
}
func
(
c
*
FakePodTemplates
)
Watch
(
label
labels
.
Selector
,
field
fields
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"watch-podTemplates"
,
Value
:
resourceVersion
}
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
c
.
Fake
.
Invokes
(
FakeAction
{
Action
:
"watch-podTemplates"
,
Value
:
resourceVersion
},
nil
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
()
}
pkg/client/testclient/fake_pods.go
View file @
618416ba
...
...
@@ -56,12 +56,12 @@ func (c *FakePods) Update(pod *api.Pod) (*api.Pod, error) {
}
func
(
c
*
FakePods
)
Watch
(
label
labels
.
Selector
,
field
fields
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"watch-pods"
,
Value
:
resourceVersion
}
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
c
.
Fake
.
Invokes
(
FakeAction
{
Action
:
"watch-pods"
,
Value
:
resourceVersion
},
nil
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
()
}
func
(
c
*
FakePods
)
Bind
(
bind
*
api
.
Binding
)
error
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"bind-pod"
,
Value
:
bind
.
Name
}
)
c
.
Fake
.
Invokes
(
FakeAction
{
Action
:
"bind-pod"
,
Value
:
bind
.
Name
},
nil
)
return
nil
}
...
...
pkg/client/testclient/fake_replication_controllers.go
View file @
618416ba
...
...
@@ -65,6 +65,6 @@ func (c *FakeReplicationControllers) Delete(name string) error {
}
func
(
c
*
FakeReplicationControllers
)
Watch
(
label
labels
.
Selector
,
field
fields
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
WatchControllerAction
,
Value
:
resourceVersion
}
)
c
.
Fake
.
Invokes
(
FakeAction
{
Action
:
WatchControllerAction
,
Value
:
resourceVersion
},
nil
)
return
c
.
Fake
.
Watch
,
nil
}
pkg/client/testclient/fake_resource_quotas.go
View file @
618416ba
...
...
@@ -61,6 +61,6 @@ func (c *FakeResourceQuotas) UpdateStatus(resourceQuota *api.ResourceQuota) (*ap
}
func
(
c
*
FakeResourceQuotas
)
Watch
(
label
labels
.
Selector
,
field
fields
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"watch-resourceQuota"
,
Value
:
resourceVersion
}
)
c
.
Fake
.
Invokes
(
FakeAction
{
Action
:
"watch-resourceQuota"
,
Value
:
resourceVersion
},
nil
)
return
c
.
Fake
.
Watch
,
nil
}
pkg/client/testclient/fake_secrets.go
View file @
618416ba
...
...
@@ -56,6 +56,6 @@ func (c *FakeSecrets) Delete(name string) error {
}
func
(
c
*
FakeSecrets
)
Watch
(
label
labels
.
Selector
,
field
fields
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"watch-secrets"
,
Value
:
resourceVersion
}
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
c
.
Fake
.
Invokes
(
FakeAction
{
Action
:
"watch-secrets"
,
Value
:
resourceVersion
},
nil
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
()
}
pkg/client/testclient/fake_service_accounts.go
View file @
618416ba
...
...
@@ -56,6 +56,6 @@ func (c *FakeServiceAccounts) Delete(name string) error {
}
func
(
c
*
FakeServiceAccounts
)
Watch
(
label
labels
.
Selector
,
field
fields
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"watch-serviceAccounts"
,
Value
:
resourceVersion
}
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
c
.
Fake
.
Invokes
(
FakeAction
{
Action
:
"watch-serviceAccounts"
,
Value
:
resourceVersion
},
nil
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
()
}
pkg/client/testclient/fake_services.go
View file @
618416ba
...
...
@@ -56,6 +56,6 @@ func (c *FakeServices) Delete(name string) error {
}
func
(
c
*
FakeServices
)
Watch
(
label
labels
.
Selector
,
field
fields
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"watch-services"
,
Value
:
resourceVersion
}
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
c
.
Fake
.
Invokes
(
FakeAction
{
Action
:
"watch-services"
,
Value
:
resourceVersion
},
nil
)
return
c
.
Fake
.
Watch
,
c
.
Fake
.
Err
()
}
pkg/client/testclient/testclient.go
View file @
618416ba
...
...
@@ -17,6 +17,8 @@ limitations under the License.
package
testclient
import
(
"sync"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/registered"
...
...
@@ -48,10 +50,11 @@ type ReactionFunc func(FakeAction) (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
{
Actions
[]
FakeAction
Watch
watch
.
Interface
E
rr
error
sync
.
RWMutex
actions
[]
FakeAction
e
rr
error
Watch
watch
.
Interface
// ReactFn is an optional function that will be invoked with the provided action
// and return a response. It can implement scenario specific behavior. The type
// of object returned must match the expected type from the caller (even if nil).
...
...
@@ -61,11 +64,47 @@ type Fake struct {
// 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
)
{
c
.
Actions
=
append
(
c
.
Actions
,
action
)
c
.
Lock
()
defer
c
.
Unlock
()
c
.
actions
=
append
(
c
.
actions
,
action
)
if
c
.
ReactFn
!=
nil
{
return
c
.
ReactFn
(
action
)
}
return
obj
,
c
.
Err
return
obj
,
c
.
err
}
// ClearActions clears the history of actions called on the fake client
func
(
c
*
Fake
)
ClearActions
()
{
c
.
Lock
()
c
.
Unlock
()
c
.
actions
=
make
([]
FakeAction
,
0
)
}
// Actions returns a chronologically ordered slice fake actions called on the fake client
func
(
c
*
Fake
)
Actions
()
[]
FakeAction
{
c
.
RLock
()
defer
c
.
RUnlock
()
fa
:=
make
([]
FakeAction
,
len
(
c
.
actions
))
copy
(
fa
,
c
.
actions
)
return
fa
}
// SetErr sets the error to return for client calls
func
(
c
*
Fake
)
SetErr
(
err
error
)
{
c
.
Lock
()
defer
c
.
Unlock
()
c
.
err
=
err
}
// Err returns any a client error or nil
func
(
c
*
Fake
)
Err
()
error
{
c
.
RLock
()
c
.
RUnlock
()
return
c
.
err
}
func
(
c
*
Fake
)
LimitRanges
(
namespace
string
)
client
.
LimitRangeInterface
{
...
...
@@ -125,13 +164,13 @@ func (c *Fake) Namespaces() client.NamespaceInterface {
}
func
(
c
*
Fake
)
ServerVersion
()
(
*
version
.
Info
,
error
)
{
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"get-version"
,
Value
:
nil
}
)
c
.
Invokes
(
FakeAction
{
Action
:
"get-version"
,
Value
:
nil
},
nil
)
versionInfo
:=
version
.
Get
()
return
&
versionInfo
,
nil
}
func
(
c
*
Fake
)
ServerAPIVersions
()
(
*
api
.
APIVersions
,
error
)
{
c
.
Actions
=
append
(
c
.
Actions
,
FakeAction
{
Action
:
"get-apiversions"
,
Value
:
nil
}
)
c
.
Invokes
(
FakeAction
{
Action
:
"get-apiversions"
,
Value
:
nil
},
nil
)
return
&
api
.
APIVersions
{
Versions
:
registered
.
RegisteredVersions
},
nil
}
...
...
pkg/cloudprovider/nodecontroller/nodecontroller_test.go
View file @
618416ba
...
...
@@ -342,7 +342,7 @@ func TestMonitorNodeStatusEvictPods(t *testing.T) {
podEvictor
.
TryEvict
(
func
(
nodeName
string
)
{
nodeController
.
deletePods
(
nodeName
)
})
podEvicted
:=
false
for
_
,
action
:=
range
item
.
fakeNodeHandler
.
Actions
{
for
_
,
action
:=
range
item
.
fakeNodeHandler
.
Actions
()
{
if
action
.
Action
==
"delete-pod"
{
podEvicted
=
true
}
...
...
pkg/cloudprovider/servicecontroller/servicecontroller_test.go
View file @
618416ba
...
...
@@ -93,20 +93,21 @@ func TestCreateExternalLoadBalancer(t *testing.T) {
client
:=
&
testclient
.
Fake
{}
controller
:=
New
(
cloud
,
client
,
"test-cluster"
)
controller
.
init
()
cloud
.
Calls
=
nil
// ignore any cloud calls made in init()
client
.
Actions
=
nil
// ignore any client calls made in init()
cloud
.
Calls
=
nil
// ignore any cloud calls made in init()
client
.
ClearActions
()
// ignore any client calls made in init()
err
,
_
:=
controller
.
createLoadBalancerIfNeeded
(
types
.
NamespacedName
{
"foo"
,
"bar"
},
item
.
service
,
nil
)
if
!
item
.
expectErr
&&
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
else
if
item
.
expectErr
&&
err
==
nil
{
t
.
Errorf
(
"expected error creating %v, got nil"
,
item
.
service
)
}
actions
:=
client
.
Actions
()
if
!
item
.
expectCreateAttempt
{
if
len
(
cloud
.
Calls
)
>
0
{
t
.
Errorf
(
"unexpected cloud provider calls: %v"
,
cloud
.
Calls
)
}
if
len
(
client
.
A
ctions
)
>
0
{
t
.
Errorf
(
"unexpected client actions: %v"
,
client
.
A
ctions
)
if
len
(
a
ctions
)
>
0
{
t
.
Errorf
(
"unexpected client actions: %v"
,
a
ctions
)
}
}
else
{
if
len
(
cloud
.
Balancers
)
!=
1
{
...
...
@@ -117,13 +118,13 @@ func TestCreateExternalLoadBalancer(t *testing.T) {
t
.
Errorf
(
"created load balancer has incorrect parameters: %v"
,
cloud
.
Balancers
[
0
])
}
actionFound
:=
false
for
_
,
action
:=
range
client
.
A
ctions
{
for
_
,
action
:=
range
a
ctions
{
if
action
.
Action
==
"update-service"
{
actionFound
=
true
}
}
if
!
actionFound
{
t
.
Errorf
(
"expected updated service to be sent to client, got these actions instead: %v"
,
client
.
A
ctions
)
t
.
Errorf
(
"expected updated service to be sent to client, got these actions instead: %v"
,
a
ctions
)
}
}
}
...
...
pkg/controller/replication/replication_controller_test.go
View file @
618416ba
...
...
@@ -693,7 +693,7 @@ func TestControllerUpdateStatusWithFailure(t *testing.T) {
numReplicas
:=
10
updateReplicaCount
(
fakeRCClient
,
*
rc
,
numReplicas
)
updates
,
gets
:=
0
,
0
for
_
,
a
:=
range
fakeClient
.
Actions
{
for
_
,
a
:=
range
fakeClient
.
Actions
()
{
switch
a
.
Action
{
case
testclient
.
GetControllerAction
:
gets
++
...
...
pkg/kubectl/rolling_updater_test.go
View file @
618416ba
...
...
@@ -74,19 +74,19 @@ func (c *fakeRc) Get(name string) (*api.ReplicationController, error) {
if
len
(
c
.
responses
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"Unexpected Action: %s"
,
action
)
}
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
action
)
c
.
Fake
.
Invokes
(
action
,
nil
)
result
:=
c
.
responses
[
0
]
c
.
responses
=
c
.
responses
[
1
:
]
return
result
.
controller
,
result
.
err
}
func
(
c
*
fakeRc
)
Create
(
controller
*
api
.
ReplicationController
)
(
*
api
.
ReplicationController
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
testclient
.
FakeAction
{
Action
:
"create-controller"
,
Value
:
controller
.
ObjectMeta
.
Name
}
)
c
.
Fake
.
Invokes
(
testclient
.
FakeAction
{
Action
:
"create-controller"
,
Value
:
controller
.
ObjectMeta
.
Name
},
nil
)
return
controller
,
nil
}
func
(
c
*
fakeRc
)
Update
(
controller
*
api
.
ReplicationController
)
(
*
api
.
ReplicationController
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
testclient
.
FakeAction
{
Action
:
"update-controller"
,
Value
:
controller
.
ObjectMeta
.
Name
}
)
c
.
Fake
.
Invokes
(
testclient
.
FakeAction
{
Action
:
"update-controller"
,
Value
:
controller
.
ObjectMeta
.
Name
},
nil
)
return
controller
,
nil
}
...
...
pkg/kubectl/scale_test.go
View file @
618416ba
...
...
@@ -73,14 +73,15 @@ func TestReplicationControllerScale(t *testing.T) {
name
:=
"foo"
scaler
.
Scale
(
"default"
,
name
,
count
,
&
preconditions
,
nil
,
nil
)
if
len
(
fake
.
Actions
)
!=
2
{
t
.
Errorf
(
"unexpected actions: %v, expected 2 actions (get, update)"
,
fake
.
Actions
)
actions
:=
fake
.
Actions
()
if
len
(
actions
)
!=
2
{
t
.
Errorf
(
"unexpected actions: %v, expected 2 actions (get, update)"
,
actions
)
}
if
fake
.
Actions
[
0
]
.
Action
!=
"get-replicationController"
||
fake
.
A
ctions
[
0
]
.
Value
!=
name
{
t
.
Errorf
(
"unexpected action: %v, expected get-replicationController %s"
,
fake
.
A
ctions
[
0
],
name
)
if
actions
[
0
]
.
Action
!=
"get-replicationController"
||
a
ctions
[
0
]
.
Value
!=
name
{
t
.
Errorf
(
"unexpected action: %v, expected get-replicationController %s"
,
a
ctions
[
0
],
name
)
}
if
fake
.
Actions
[
1
]
.
Action
!=
"update-replicationController"
||
fake
.
A
ctions
[
1
]
.
Value
.
(
*
api
.
ReplicationController
)
.
Spec
.
Replicas
!=
int
(
count
)
{
t
.
Errorf
(
"unexpected action %v, expected update-replicationController with replicas = %d"
,
fake
.
A
ctions
[
1
],
count
)
if
actions
[
1
]
.
Action
!=
"update-replicationController"
||
a
ctions
[
1
]
.
Value
.
(
*
api
.
ReplicationController
)
.
Spec
.
Replicas
!=
int
(
count
)
{
t
.
Errorf
(
"unexpected action %v, expected update-replicationController with replicas = %d"
,
a
ctions
[
1
],
count
)
}
}
...
...
@@ -96,11 +97,12 @@ func TestReplicationControllerScaleFailsPreconditions(t *testing.T) {
name
:=
"foo"
scaler
.
Scale
(
"default"
,
name
,
count
,
&
preconditions
,
nil
,
nil
)
if
len
(
fake
.
Actions
)
!=
1
{
t
.
Errorf
(
"unexpected actions: %v, expected 2 actions (get, update)"
,
fake
.
Actions
)
actions
:=
fake
.
Actions
()
if
len
(
actions
)
!=
1
{
t
.
Errorf
(
"unexpected actions: %v, expected 2 actions (get, update)"
,
actions
)
}
if
fake
.
Actions
[
0
]
.
Action
!=
"get-replicationController"
||
fake
.
A
ctions
[
0
]
.
Value
!=
name
{
t
.
Errorf
(
"unexpected action: %v, expected get-replicationController %s"
,
fake
.
A
ctions
[
0
],
name
)
if
actions
[
0
]
.
Action
!=
"get-replicationController"
||
a
ctions
[
0
]
.
Value
!=
name
{
t
.
Errorf
(
"unexpected action: %v, expected get-replicationController %s"
,
a
ctions
[
0
],
name
)
}
}
...
...
pkg/kubectl/stop_test.go
View file @
618416ba
...
...
@@ -47,12 +47,13 @@ func TestReplicationControllerStop(t *testing.T) {
if
s
!=
expected
{
t
.
Errorf
(
"expected %s, got %s"
,
expected
,
s
)
}
if
len
(
fake
.
Actions
)
!=
7
{
actions
:=
fake
.
Actions
()
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
fake
.
A
ctions
[
i
]
.
Action
!=
action
+
"-replicationController"
{
t
.
Errorf
(
"unexpected action: %+v, expected %s-replicationController"
,
fake
.
A
ctions
[
i
],
action
)
if
a
ctions
[
i
]
.
Action
!=
action
+
"-replicationController"
{
t
.
Errorf
(
"unexpected action: %+v, expected %s-replicationController"
,
a
ctions
[
i
],
action
)
}
}
}
...
...
@@ -159,10 +160,11 @@ func TestSimpleStop(t *testing.T) {
t
.
Errorf
(
"unexpected return: %s (%s)"
,
s
,
test
.
test
)
}
}
if
len
(
test
.
actions
)
!=
len
(
fake
.
Actions
)
{
actions
:=
fake
.
Actions
()
if
len
(
test
.
actions
)
!=
len
(
actions
)
{
t
.
Errorf
(
"unexpected actions: %v; expected %v (%s)"
,
fake
.
Actions
,
test
.
actions
,
test
.
test
)
}
for
i
,
action
:=
range
fake
.
A
ctions
{
for
i
,
action
:=
range
a
ctions
{
testAction
:=
test
.
actions
[
i
]
if
action
.
Action
!=
testAction
{
t
.
Errorf
(
"unexpected action: %v; expected %v (%s)"
,
action
,
testAction
,
test
.
test
)
...
...
pkg/kubelet/kubelet_test.go
View file @
618416ba
...
...
@@ -2322,10 +2322,11 @@ func TestUpdateNewNodeStatus(t *testing.T) {
if
err
:=
kubelet
.
updateNodeStatus
();
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
if
len
(
kubeClient
.
Actions
)
!=
2
||
kubeClient
.
Actions
[
1
]
.
Action
!=
"update-status-node"
{
t
.
Fatalf
(
"unexpected actions: %v"
,
kubeClient
.
Actions
)
actions
:=
kubeClient
.
Actions
()
if
len
(
actions
)
!=
2
||
actions
[
1
]
.
Action
!=
"update-status-node"
{
t
.
Fatalf
(
"unexpected actions: %v"
,
actions
)
}
updatedNode
,
ok
:=
kubeClient
.
A
ctions
[
1
]
.
Value
.
(
*
api
.
Node
)
updatedNode
,
ok
:=
a
ctions
[
1
]
.
Value
.
(
*
api
.
Node
)
if
!
ok
{
t
.
Errorf
(
"unexpected object type"
)
}
...
...
@@ -2419,10 +2420,11 @@ func TestUpdateExistingNodeStatus(t *testing.T) {
if
err
:=
kubelet
.
updateNodeStatus
();
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
if
len
(
kubeClient
.
Actions
)
!=
2
{
t
.
Errorf
(
"unexpected actions: %v"
,
kubeClient
.
Actions
)
actions
:=
kubeClient
.
Actions
()
if
len
(
actions
)
!=
2
{
t
.
Errorf
(
"unexpected actions: %v"
,
actions
)
}
updatedNode
,
ok
:=
kubeClient
.
A
ctions
[
1
]
.
Value
.
(
*
api
.
Node
)
updatedNode
,
ok
:=
a
ctions
[
1
]
.
Value
.
(
*
api
.
Node
)
if
!
ok
{
t
.
Errorf
(
"unexpected object type"
)
}
...
...
@@ -2506,10 +2508,11 @@ func TestUpdateNodeStatusWithoutContainerRuntime(t *testing.T) {
if
err
:=
kubelet
.
updateNodeStatus
();
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
if
len
(
kubeClient
.
Actions
)
!=
2
||
kubeClient
.
Actions
[
1
]
.
Action
!=
"update-status-node"
{
t
.
Fatalf
(
"unexpected actions: %v"
,
kubeClient
.
Actions
)
actions
:=
kubeClient
.
Actions
()
if
len
(
actions
)
!=
2
||
actions
[
1
]
.
Action
!=
"update-status-node"
{
t
.
Fatalf
(
"unexpected actions: %v"
,
actions
)
}
updatedNode
,
ok
:=
kubeClient
.
A
ctions
[
1
]
.
Value
.
(
*
api
.
Node
)
updatedNode
,
ok
:=
a
ctions
[
1
]
.
Value
.
(
*
api
.
Node
)
if
!
ok
{
t
.
Errorf
(
"unexpected object type"
)
}
...
...
@@ -2536,8 +2539,8 @@ func TestUpdateNodeStatusError(t *testing.T) {
if
err
:=
kubelet
.
updateNodeStatus
();
err
==
nil
{
t
.
Errorf
(
"unexpected non error: %v"
,
err
)
}
if
len
(
testKubelet
.
fakeKubeClient
.
Actions
)
!=
nodeStatusUpdateRetry
{
t
.
Errorf
(
"unexpected actions: %v"
,
testKubelet
.
fakeKubeClient
.
Actions
)
if
len
(
testKubelet
.
fakeKubeClient
.
Actions
()
)
!=
nodeStatusUpdateRetry
{
t
.
Errorf
(
"unexpected actions: %v"
,
testKubelet
.
fakeKubeClient
.
Actions
()
)
}
}
...
...
pkg/kubelet/status_manager_test.go
View file @
618416ba
...
...
@@ -53,7 +53,7 @@ func getRandomPodStatus() api.PodStatus {
}
func
verifyActions
(
t
*
testing
.
T
,
kubeClient
client
.
Interface
,
expectedActions
[]
string
)
{
actions
:=
kubeClient
.
(
*
testclient
.
Fake
)
.
Actions
actions
:=
kubeClient
.
(
*
testclient
.
Fake
)
.
Actions
()
if
len
(
actions
)
!=
len
(
expectedActions
)
{
t
.
Errorf
(
"unexpected actions, got: %s expected: %s"
,
actions
,
expectedActions
)
return
...
...
pkg/namespace/namespace_controller_test.go
View file @
618416ba
...
...
@@ -53,13 +53,14 @@ func TestFinalize(t *testing.T) {
},
}
finalize
(
mockClient
,
testNamespace
)
if
len
(
mockClient
.
Actions
)
!=
1
{
t
.
Errorf
(
"Expected 1 mock client action, but got %v"
,
len
(
mockClient
.
Actions
))
actions
:=
mockClient
.
Actions
()
if
len
(
actions
)
!=
1
{
t
.
Errorf
(
"Expected 1 mock client action, but got %v"
,
len
(
actions
))
}
if
mockClient
.
A
ctions
[
0
]
.
Action
!=
"finalize-namespace"
{
t
.
Errorf
(
"Expected finalize-namespace action %v"
,
mockClient
.
A
ctions
[
0
]
.
Action
)
if
a
ctions
[
0
]
.
Action
!=
"finalize-namespace"
{
t
.
Errorf
(
"Expected finalize-namespace action %v"
,
a
ctions
[
0
]
.
Action
)
}
finalizers
:=
mockClient
.
A
ctions
[
0
]
.
Value
.
(
*
api
.
Namespace
)
.
Spec
.
Finalizers
finalizers
:=
a
ctions
[
0
]
.
Value
.
(
*
api
.
Namespace
)
.
Spec
.
Finalizers
if
len
(
finalizers
)
!=
1
{
t
.
Errorf
(
"There should be a single finalizer remaining"
)
}
...
...
@@ -100,8 +101,8 @@ func TestSyncNamespaceThatIsTerminating(t *testing.T) {
"finalize-namespace"
,
"delete-namespace"
)
actionSet
:=
util
.
NewStringSet
()
for
i
:=
range
mockClient
.
Actions
{
actionSet
.
Insert
(
mockClient
.
Actions
[
i
]
.
Action
)
for
_
,
action
:=
range
mockClient
.
Actions
()
{
actionSet
.
Insert
(
action
.
Action
)
}
if
!
actionSet
.
HasAll
(
expectedActionSet
.
List
()
...
)
{
t
.
Errorf
(
"Expected actions: %v, but got: %v"
,
expectedActionSet
,
actionSet
)
...
...
@@ -127,8 +128,8 @@ func TestSyncNamespaceThatIsActive(t *testing.T) {
t
.
Errorf
(
"Unexpected error when synching namespace %v"
,
err
)
}
actionSet
:=
util
.
NewStringSet
()
for
i
:=
range
mockClient
.
Actions
{
actionSet
.
Insert
(
mockClient
.
Actions
[
i
]
.
Action
)
for
_
,
action
:=
range
mockClient
.
Actions
()
{
actionSet
.
Insert
(
action
.
Action
)
}
if
len
(
actionSet
)
!=
0
{
t
.
Errorf
(
"Expected no action from controller, but got: %v"
,
actionSet
)
...
...
pkg/resourcequota/resource_quota_controller_test.go
View file @
618416ba
...
...
@@ -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
]
.
Value
.
(
*
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
]
.
Value
.
(
*
api
.
ResourceQuota
)
// ensure hard and used limits are what we expected
for
k
,
v
:=
range
expectedUsage
.
Status
.
Hard
{
...
...
@@ -263,7 +263,8 @@ func TestSyncResourceQuotaNoChange(t *testing.T) {
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
}
if
len
(
kubeClient
.
Actions
)
!=
1
&&
kubeClient
.
Actions
[
0
]
.
Action
!=
"list-pods"
{
actions
:=
kubeClient
.
Actions
()
if
len
(
actions
)
!=
1
&&
actions
[
0
]
.
Action
!=
"list-pods"
{
t
.
Errorf
(
"SyncResourceQuota made an unexpected client action when state was not dirty: %v"
,
kubeClient
.
Actions
)
}
}
...
...
pkg/serviceaccount/serviceaccounts_controller_test.go
View file @
618416ba
...
...
@@ -192,12 +192,13 @@ func TestServiceAccountCreation(t *testing.T) {
controller
.
serviceAccountDeleted
(
tc
.
DeletedServiceAccount
)
}
if
len
(
tc
.
ExpectCreatedServiceAccounts
)
!=
len
(
client
.
Actions
)
{
t
.
Errorf
(
"%s: Expected to create accounts %#v. Actual actions were: %#v"
,
k
,
tc
.
ExpectCreatedServiceAccounts
,
client
.
Actions
)
actions
:=
client
.
Actions
()
if
len
(
tc
.
ExpectCreatedServiceAccounts
)
!=
len
(
actions
)
{
t
.
Errorf
(
"%s: Expected to create accounts %#v. Actual actions were: %#v"
,
k
,
tc
.
ExpectCreatedServiceAccounts
,
actions
)
continue
}
for
i
,
expectedName
:=
range
tc
.
ExpectCreatedServiceAccounts
{
action
:=
client
.
A
ctions
[
i
]
action
:=
a
ctions
[
i
]
if
action
.
Action
!=
"create-serviceaccount"
{
t
.
Errorf
(
"%s: Unexpected action %s"
,
k
,
action
.
Action
)
break
...
...
pkg/serviceaccount/tokens_controller_test.go
View file @
618416ba
...
...
@@ -462,9 +462,10 @@ func TestTokenCreation(t *testing.T) {
controller
.
secretDeleted
(
tc
.
DeletedSecret
)
}
for
i
,
action
:=
range
client
.
Actions
{
actions
:=
client
.
Actions
()
for
i
,
action
:=
range
actions
{
if
len
(
tc
.
ExpectedActions
)
<
i
+
1
{
t
.
Errorf
(
"%s: %d unexpected actions: %+v"
,
k
,
len
(
client
.
Actions
)
-
len
(
tc
.
ExpectedActions
),
client
.
A
ctions
[
i
:
])
t
.
Errorf
(
"%s: %d unexpected actions: %+v"
,
k
,
len
(
actions
)
-
len
(
tc
.
ExpectedActions
),
a
ctions
[
i
:
])
break
}
...
...
@@ -479,8 +480,8 @@ func TestTokenCreation(t *testing.T) {
}
}
if
len
(
tc
.
ExpectedActions
)
>
len
(
client
.
A
ctions
)
{
t
.
Errorf
(
"%s: %d additional expected actions:%+v"
,
k
,
len
(
tc
.
ExpectedActions
)
-
len
(
client
.
Actions
),
tc
.
ExpectedActions
[
len
(
client
.
A
ctions
)
:
])
if
len
(
tc
.
ExpectedActions
)
>
len
(
a
ctions
)
{
t
.
Errorf
(
"%s: %d additional expected actions:%+v"
,
k
,
len
(
tc
.
ExpectedActions
)
-
len
(
actions
),
tc
.
ExpectedActions
[
len
(
a
ctions
)
:
])
}
}
}
plugin/pkg/admission/namespace/autoprovision/admission_test.go
View file @
618416ba
...
...
@@ -45,10 +45,11 @@ func TestAdmission(t *testing.T) {
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error returned from admission handler"
)
}
if
len
(
mockClient
.
Actions
)
!=
1
{
actions
:=
mockClient
.
Actions
()
if
len
(
actions
)
!=
1
{
t
.
Errorf
(
"Expected a create-namespace request"
)
}
if
mockClient
.
A
ctions
[
0
]
.
Action
!=
"create-namespace"
{
if
a
ctions
[
0
]
.
Action
!=
"create-namespace"
{
t
.
Errorf
(
"Expected a create-namespace request to be made via the client"
)
}
}
...
...
@@ -76,7 +77,7 @@ func TestAdmissionNamespaceExists(t *testing.T) {
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error returned from admission handler"
)
}
if
len
(
mockClient
.
Actions
)
!=
0
{
if
len
(
mockClient
.
Actions
()
)
!=
0
{
t
.
Errorf
(
"No client request should have been made"
)
}
}
...
...
@@ -97,7 +98,7 @@ func TestIgnoreAdmission(t *testing.T) {
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error returned from admission handler"
)
}
if
len
(
mockClient
.
Actions
)
!=
0
{
if
len
(
mockClient
.
Actions
()
)
!=
0
{
t
.
Errorf
(
"No client request should have been made"
)
}
}
...
...
@@ -105,9 +106,9 @@ func TestIgnoreAdmission(t *testing.T) {
// TestAdmissionNamespaceExistsUnknownToHandler
func
TestAdmissionNamespaceExistsUnknownToHandler
(
t
*
testing
.
T
)
{
namespace
:=
"test"
mockClient
:=
&
testclient
.
Fake
{
Err
:
errors
.
NewAlreadyExists
(
"namespaces"
,
namespace
),
}
mockClient
:=
&
testclient
.
Fake
{
}
mockClient
.
SetErr
(
errors
.
NewAlreadyExists
(
"namespaces"
,
namespace
))
store
:=
cache
.
NewStore
(
cache
.
MetaNamespaceKeyFunc
)
handler
:=
&
provision
{
client
:
mockClient
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment