Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
Add tests for clusterwide feature
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhem committed Jan 18, 2018
1 parent f769dda commit ad657e7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
3 changes: 1 addition & 2 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
46 changes: 43 additions & 3 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}

0 comments on commit ad657e7

Please sign in to comment.