From ad657e7212f9e58454a5feb4ad5364967b0fc15f Mon Sep 17 00:00:00 2001 From: Guilhem Lettron Date: Thu, 18 Jan 2018 14:22:54 +0100 Subject: [PATCH] Add tests for clusterwide feature --- pkg/controller/controller.go | 3 +- pkg/controller/controller_test.go | 46 +++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 4d9fe9ffe..17b7b2d7d 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -66,8 +66,7 @@ func (c *Controller) handleClusterEvent(event *Event) error { clus := event.Object if !c.managed(clus) { - c.logger.Info("Cluster isn't managed: %v", clus) - return nil + return fmt.Errorf("cluster (%s) isn't managed", clus.Name) } if clus.Status.IsFailed() { diff --git a/pkg/controller/controller_test.go b/pkg/controller/controller_test.go index 338e664d3..0a9c4339f 100644 --- a/pkg/controller/controller_test.go +++ b/pkg/controller/controller_test.go @@ -18,11 +18,10 @@ import ( "strings" "testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" - api "github.com/coreos/etcd-operator/pkg/apis/etcd/v1beta2" "github.com/coreos/etcd-operator/pkg/cluster" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/watch" ) func TestHandleClusterEventUpdateFailedCluster(t *testing.T) { @@ -73,3 +72,44 @@ func TestHandleClusterEventDeleteFailedCluster(t *testing.T) { t.Errorf("failed cluster not cleaned up after delete event, cluster struct: %v", c.clusters[name]) } } + +func TestHandleClusterEventClusterwide(t *testing.T) { + c := New(Config{ClusterWide: true}) + + clus := &api.EtcdCluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test", + Annotations: map[string]string{ + "etcd.database.coreos.com/scope": "clusterwide", + }, + }, + } + e := &Event{ + Type: watch.Modified, + Object: clus, + } + err := c.handleClusterEvent(e) + suffix := "isn't managed" + if strings.HasSuffix(err.Error(), suffix) { + t.Errorf("expect err='%s...', get=%v", suffix, err) + } +} + +func TestHandleClusterEventClusterwideIgnored(t *testing.T) { + c := New(Config{ClusterWide: true}) + + clus := &api.EtcdCluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test", + }, + } + e := &Event{ + Type: watch.Modified, + Object: clus, + } + err := c.handleClusterEvent(e) + suffix := "isn't managed" + if !strings.HasSuffix(err.Error(), suffix) { + t.Errorf("expect err='%s...', get=%v", suffix, err) + } +}