Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Commit

Permalink
metrics - Fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
cscetbon committed Mar 5, 2020
1 parent 8d44a10 commit 4d4d1eb
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 71 deletions.
72 changes: 36 additions & 36 deletions pkg/apis/db/v1alpha1/cassandracluster_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func TestInitCassandraRackList_NoTopo(t *testing.T) {

cc.InitCassandraRackList()

assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["dc1-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["dc1-rack1"].CassandraLastAction.Name)
assert.Equal(1, len(cc.Status.CassandraRackStatus))

assert.Equal(1, cc.GetDCSize())
Expand All @@ -200,7 +200,7 @@ func TestInitCassandraRackList_TopoDCNoRack(t *testing.T) {

cc.InitCassandraRackList()

assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)
assert.Equal(1, len(cc.Status.CassandraRackStatus))

assert.Equal(1, cc.GetDCSize())
Expand All @@ -215,10 +215,10 @@ func TestInitCassandraRackList_2DC(t *testing.T) {

cc.InitCassandraRackList()

assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack2"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["stats-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["stats-rack2"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack2"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["stats-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["stats-rack2"].CassandraLastAction.Name)
assert.Equal(4, len(cc.Status.CassandraRackStatus))

}
Expand All @@ -230,15 +230,15 @@ func TestInitCassandraRackinStatus(t *testing.T) {

cc.InitCassandraRackList()

assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack2"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["stats-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["stats-rack2"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack2"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["stats-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["stats-rack2"].CassandraLastAction.Name)
assert.Equal(4, len(cc.Status.CassandraRackStatus))
//Add new DC from existing RackStatus
cc.InitCassandraRackinStatus(&cc.Status, "foo", "bar")

assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["foo-bar"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["foo-bar"].CassandraLastAction.Name)
assert.Equal(5, len(cc.Status.CassandraRackStatus))
}

Expand All @@ -249,7 +249,7 @@ func TestGetStatusDCRackSize(t *testing.T) {

cc.InitCassandraRackList()

assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)

assert.Equal(2, cc.GetDCSize())
assert.Equal(2, cc.GetRackSize(0))
Expand Down Expand Up @@ -287,8 +287,8 @@ func TestGetStatusDCRackSize_KeepChanges(t *testing.T) {
assert.Equal(nb, cc.GetDCRackSize())

//add info in status
cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name = ActionUpdateSeedList
assert.Equal(cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name, ActionUpdateSeedList)
cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name = ActionUpdateSeedList.Name
assert.Equal(cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name, ActionUpdateSeedList.Name)

//Remove 1 dc
cc.Spec.Topology.DC.Remove(1)
Expand All @@ -302,7 +302,7 @@ func TestGetStatusDCRackSize_KeepChanges(t *testing.T) {
nb = len(status.CassandraRackStatus)
assert.Equal(2, nb)
assert.Equal(nb, cc.GetDCRackSize())
assert.Equal(cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name, ActionUpdateSeedList)
assert.Equal(cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name, ActionUpdateSeedList.Name)
assert.Equal(2, len(status.CassandraRackStatus))
}

Expand All @@ -313,10 +313,10 @@ func TestInitSeedList_2DC(t *testing.T) {

//cc.InitCassandraRackList()

assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack2"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["stats-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["stats-rack2"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack2"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["stats-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["stats-rack2"].CassandraLastAction.Name)

cc.Status.SeedList = cc.InitSeedList()

Expand All @@ -336,7 +336,7 @@ func TestInitSeedList_NoTopo(t *testing.T) {

//cc.InitCassandraRackList()

assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["dc1-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["dc1-rack1"].CassandraLastAction.Name)
assert.Equal(1, len(cc.Status.CassandraRackStatus))

cc.Status.SeedList = cc.InitSeedList()
Expand All @@ -355,8 +355,8 @@ func TestInitSeedList_1DC(t *testing.T) {

//cc.InitCassandraRackList()

assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack2"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack2"].CassandraLastAction.Name)
assert.Equal(2, len(cc.Status.CassandraRackStatus))

cc.Status.SeedList = cc.InitSeedList()
Expand All @@ -377,15 +377,15 @@ func TestInitSeedList_2DC5R(t *testing.T) {

//cc.InitCassandraRackList()

assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack2"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack3"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack4"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack5"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["stats-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["stats-rack2"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["stats-rack3"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["stats-rack4"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack2"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack3"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack4"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack5"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["stats-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["stats-rack2"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["stats-rack3"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["stats-rack4"].CassandraLastAction.Name)
assert.Equal(9, len(cc.Status.CassandraRackStatus))

cc.Status.SeedList = cc.InitSeedList()
Expand All @@ -408,8 +408,8 @@ func TestInitSeedList_1DC1R1P(t *testing.T) {

//cc.InitCassandraRackList()

assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack2"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack2"].CassandraLastAction.Name)
assert.Equal(2, len(cc.Status.CassandraRackStatus))

cc.Status.SeedList = cc.InitSeedList()
Expand All @@ -426,8 +426,8 @@ func TestIsPodInSeedList(t *testing.T) {

cc := helperInitCluster(t, "cassandracluster-1DC1R1P.yaml")

assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial, cc.Status.CassandraRackStatus["online-rack2"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack1"].CassandraLastAction.Name)
assert.Equal(ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["online-rack2"].CassandraLastAction.Name)
assert.Equal(2, len(cc.Status.CassandraRackStatus))

cc.Status.SeedList = cc.InitSeedList()
Expand Down Expand Up @@ -494,7 +494,7 @@ func TestSetDefaults(t *testing.T) {
assert.Equal(CPUAndMem{CPU: "500m", Memory: "1Gi"}, cluster.Spec.Resources.Limits)

assert.Equal(DefaultUserID, *cluster.Spec.RunAsUser)
assert.Equal(ClusterPhaseInitial, cluster.Status.Phase)
assert.Equal(ClusterPhaseInitial.Name, cluster.Status.Phase)
assert.Equal(int32(defaultMaxPodUnavailable), cluster.Spec.MaxPodUnavailable)
assert.Equal([]string{"defaults-test-dc1-rack1-0.defaults-test.default"}, cluster.Status.SeedList)

Expand Down
21 changes: 10 additions & 11 deletions pkg/controller/cassandracluster/cassandra_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ import (
"context"
"fmt"

"k8s.io/api/core/v1"
//"k8s.io/apimachinery/pkg/runtime"
"reflect"

v1 "k8s.io/api/core/v1"

appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
//"k8s.io/client-go/kubernetes/scheme"
//"sigs.k8s.io/controller-runtime/pkg/client/fake"

"strconv"
"testing"

Expand Down Expand Up @@ -97,9 +96,9 @@ func TestUpdateStatusIfSeedListHasChanged(t *testing.T) {
}
cc.InitCassandraRackList()

assert.Equal(api.ClusterPhaseInitial, cc.Status.CassandraRackStatus["dc1-rack1"].CassandraLastAction.Name)
assert.Equal(api.ClusterPhaseInitial, cc.Status.CassandraRackStatus["dc1-rack2"].CassandraLastAction.Name)
assert.Equal(api.ClusterPhaseInitial, cc.Status.CassandraRackStatus["dc2-rack1"].CassandraLastAction.Name)
assert.Equal(api.ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["dc1-rack1"].CassandraLastAction.Name)
assert.Equal(api.ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["dc1-rack2"].CassandraLastAction.Name)
assert.Equal(api.ClusterPhaseInitial.Name, cc.Status.CassandraRackStatus["dc2-rack1"].CassandraLastAction.Name)
assert.Equal(3, len(cc.Status.CassandraRackStatus))

cc.Status.SeedList = cc.InitSeedList()
Expand Down Expand Up @@ -223,17 +222,17 @@ func helperCreateCassandraCluster(t *testing.T, cassandraClusterFileName string)
if err = rcc.client.Get(context.TODO(), req.NamespacedName, cc); err != nil {
t.Fatalf("can't get cassandracluster: (%v)", err)
}
assert.Equal(cc.Status.Phase, api.ClusterPhaseRunning)
assert.Equal(cc.Status.Phase, api.ClusterPhaseRunning.Name)

for _, dcRackName := range cc.GetDCRackNames() {
assert.Equal(cc.Status.CassandraRackStatus[dcRackName].Phase, api.ClusterPhaseRunning,
assert.Equal(cc.Status.CassandraRackStatus[dcRackName].Phase, api.ClusterPhaseRunning.Name,
"dc-rack: %s", dcRackName)
assert.Equal(cc.Status.CassandraRackStatus[dcRackName].CassandraLastAction.Name, api.ClusterPhaseInitial,
assert.Equal(cc.Status.CassandraRackStatus[dcRackName].CassandraLastAction.Name, api.ClusterPhaseInitial.Name,
"dc-rack: %s", dcRackName)
assert.Equal(cc.Status.CassandraRackStatus[dcRackName].CassandraLastAction.Status, api.StatusDone,
"dc-rack %s", dcRackName)
}
assert.Equal(cc.Status.LastClusterAction, api.ClusterPhaseInitial)
assert.Equal(cc.Status.LastClusterAction, api.ClusterPhaseInitial.Name)
assert.Equal(cc.Status.LastClusterActionStatus, api.StatusDone)

return rcc, &req
Expand Down
Loading

0 comments on commit 4d4d1eb

Please sign in to comment.