Skip to content

Commit

Permalink
Add unit test for the generateMgrSpec function
Browse files Browse the repository at this point in the history
Signed-off-by: Malay Kumar Parida <[email protected]>
  • Loading branch information
malayparida2000 committed Oct 19, 2023
1 parent edefefe commit e370713
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions controllers/storagecluster/cephcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"reflect"
"strconv"
"strings"
"testing"

Expand All @@ -14,6 +15,7 @@ import (
api "github.com/red-hat-storage/ocs-operator/v4/api/v1"
ocsv1 "github.com/red-hat-storage/ocs-operator/v4/api/v1"
"github.com/red-hat-storage/ocs-operator/v4/controllers/defaults"
"github.com/red-hat-storage/ocs-operator/v4/controllers/util"
ocsutil "github.com/red-hat-storage/ocs-operator/v4/controllers/util"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
rookCephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
Expand Down Expand Up @@ -295,6 +297,46 @@ func TestNewCephClusterMonData(t *testing.T) {
}
}

func TestGenerateMgrSpec(t *testing.T) {
cases := []struct {
label string
sc *api.StorageCluster
isSingleNode bool
expectedMgr cephv1.MgrSpec
}{
{
label: "Default case",
sc: &api.StorageCluster{},
expectedMgr: cephv1.MgrSpec{
Count: defaults.DefaultMgrCount,
Modules: []cephv1.Module{
{Name: "pg_autoscaler", Enabled: true},
{Name: "balancer", Enabled: true},
},
},
},
{
label: "Single node deployment",
sc: &api.StorageCluster{},
isSingleNode: true,
expectedMgr: cephv1.MgrSpec{
Count: 1,
Modules: []cephv1.Module{
{Name: "pg_autoscaler", Enabled: true},
{Name: "balancer", Enabled: true},
},
},
},
}

for _, c := range cases {
t.Logf("Case: %s\n", c.label)
t.Setenv(util.SingleNodeEnvVar, strconv.FormatBool(c.isSingleNode))
actual := generateMgrSpec(c.sc)
assert.DeepEqual(t, c.expectedMgr, actual)
}
}

func TestStorageClassDeviceSetCreation(t *testing.T) {
sc1 := &api.StorageCluster{}
sc1.Spec.StorageDeviceSets = mockDeviceSets
Expand Down

0 comments on commit e370713

Please sign in to comment.