-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add storagegroupcontroller UT initial
Signed-off-by: Shi, Crane <[email protected]>
- Loading branch information
1 parent
ee44769
commit 1ea8660
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
pkg/crcontrollers/storagegroup/storagegroupcontroller_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package storagegroup | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
api "github.com/dell/csi-baremetal/api/generated/v1" | ||
apiV1 "github.com/dell/csi-baremetal/api/v1" | ||
sgcrd "github.com/dell/csi-baremetal/api/v1/storagegroupcrd" | ||
"github.com/dell/csi-baremetal/pkg/base/k8s" | ||
) | ||
|
||
var ( | ||
testNs = "default" | ||
testID = "someID" | ||
nodeID = "node-uuid" | ||
|
||
testLogger = logrus.New() | ||
testCtx = context.Background() | ||
driveUUID = uuid.New().String() | ||
driveUUID2 = uuid.New().String() | ||
driveSerialNumber = "VDH19UBD" | ||
driveSerialNumber2 = "MDH16UAC" | ||
testSG1Name = "test-hdd-1" | ||
|
||
drive1 = api.Drive{ | ||
UUID: driveUUID, | ||
Size: 1024 * 1024 * 1024 * 500, | ||
NodeId: nodeID, | ||
Type: apiV1.DriveTypeHDD, | ||
Status: apiV1.DriveStatusOnline, | ||
Health: apiV1.HealthBad, | ||
IsSystem: true, | ||
SerialNumber: driveSerialNumber, | ||
} | ||
|
||
drive2 = api.Drive{ | ||
UUID: driveUUID2, | ||
Size: 1024 * 1024 * 1024 * 500, | ||
NodeId: nodeID, | ||
Type: apiV1.DriveTypeHDD, | ||
Status: apiV1.DriveStatusOnline, | ||
Health: apiV1.HealthGood, | ||
SerialNumber: driveSerialNumber2, | ||
} | ||
|
||
testSG1 = sgcrd.StorageGroup{ | ||
TypeMeta: v1.TypeMeta{Kind: "StorageGroup", APIVersion: apiV1.APIV1Version}, | ||
ObjectMeta: v1.ObjectMeta{Name: testSG1Name}, | ||
Spec: api.StorageGroupSpec{ | ||
DriveSelector: &api.DriveSelector{ | ||
NumberDrivesPerNode: 1, | ||
MatchFields: map[string]string{"Type": "HDD"}, | ||
}, | ||
}, | ||
} | ||
) | ||
|
||
func setup() *k8s.KubeClient { | ||
kubeClient, err := k8s.GetFakeKubeClient(testNs, testLogger) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return kubeClient | ||
} | ||
|
||
func TestStorageGroupController_NewController(t *testing.T) { | ||
kubeClient, err := k8s.GetFakeKubeClient(testNs, testLogger) | ||
assert.Nil(t, err) | ||
|
||
controller := NewController(kubeClient, kubeClient, testLogger) | ||
assert.NotNil(t, controller) | ||
assert.NotNil(t, controller.client) | ||
assert.NotNil(t, controller.crHelper) | ||
|
||
assert.NotNil(t, controller.log) | ||
assert.NotEqual(t, controller.log, testLogger) | ||
} |