From 2ad0fbd99ab3ca0dcf6d100a12f8936325700b47 Mon Sep 17 00:00:00 2001 From: deads2k Date: Tue, 11 Oct 2016 13:12:58 -0400 Subject: [PATCH] filter informer actions when inspecting controller unit test reactions --- .../deployment/deployment_controller_test.go | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/pkg/controller/deployment/deployment_controller_test.go b/pkg/controller/deployment/deployment_controller_test.go index 4d6e1aaa024..f587728917f 100644 --- a/pkg/controller/deployment/deployment_controller_test.go +++ b/pkg/controller/deployment/deployment_controller_test.go @@ -193,20 +193,9 @@ func (f *fixture) run(deploymentName string) { f.t.Errorf("error syncing deployment: %v", err) } - actions := f.client.Actions() + actions := filterInformerActions(f.client.Actions()) informerActions := 0 for i, action := range actions { - if len(action.GetNamespace()) == 0 && - (action.Matches("list", "pods") || - action.Matches("list", "replicasets") || - action.Matches("list", "deployments") || - action.Matches("watch", "pods") || - action.Matches("watch", "replicasets") || - action.Matches("watch", "deployments")) { - informerActions++ - continue - } - if len(f.actions)+informerActions < i+1 { f.t.Errorf("%d unexpected actions: %+v", len(actions)-len(f.actions), actions[i:]) break @@ -275,8 +264,26 @@ func TestDeploymentController_dontSyncDeploymentsWithEmptyPodSelector(t *testing if len(fake.Actions()) == 0 { return } - for _, action := range fake.Actions() { + for _, action := range filterInformerActions(fake.Actions()) { t.Logf("unexpected action: %#v", action) } t.Errorf("expected deployment controller to not take action") } + +func filterInformerActions(actions []core.Action) []core.Action { + ret := []core.Action{} + for _, action := range actions { + if len(action.GetNamespace()) == 0 && + (action.Matches("list", "pods") || + action.Matches("list", "deployments") || + action.Matches("list", "replicasets") || + action.Matches("watch", "pods") || + action.Matches("watch", "deployments") || + action.Matches("watch", "replicasets")) { + continue + } + ret = append(ret, action) + } + + return ret +}