Skip to content

Commit

Permalink
fix the Driver controller and ClientProfile controller unit tests
Browse files Browse the repository at this point in the history
Co-Authored-by: Raghavendra Talur <[email protected]>
Signed-off-by: Michael Adam <[email protected]>
  • Loading branch information
obnoxxx and raghavendra-talur committed Nov 15, 2024
1 parent f325f74 commit fcbf58b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
31 changes: 29 additions & 2 deletions internal/controller/clientprofile_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

csiv1alpha1 "github.com/ceph/ceph-csi-operator/api/v1alpha1"
Expand All @@ -33,25 +34,51 @@ import (
var _ = Describe("ClientProfile Controller", func() {
Context("When reconciling a resource", func() {
const resourceName = "test-resource"
const cephConnectionName = "foo"
const namespaceName = "default"

ctx := context.Background()

typeNamespacedName := types.NamespacedName{
Name: resourceName,
Namespace: "default", // TODO(user):Modify as needed
Namespace: namespaceName, // TODO(user):Modify as needed
}
clientProfile := &csiv1alpha1.ClientProfile{}
typeCephConnectionName := types.NamespacedName{
Name: cephConnectionName,
Namespace: namespaceName,
}
cephConn := &csiv1alpha1.CephConnection{}

BeforeEach(func() {
err := k8sClient.Get(ctx, typeCephConnectionName, cephConn)
if err != nil && errors.IsNotFound(err) {
resource := &csiv1alpha1.CephConnection{
ObjectMeta: metav1.ObjectMeta{
Name: cephConnectionName,
Namespace: namespaceName,
},
Spec: csiv1alpha1.CephConnectionSpec{
Monitors: []string{"10.98.44.171:6789"},
},
}
Expect(k8sClient.Create(ctx, resource)).To(Succeed())
}

By("creating the custom resource for the Kind ClientProfile")
err := k8sClient.Get(ctx, typeNamespacedName, clientProfile)
err = k8sClient.Get(ctx, typeNamespacedName, clientProfile)
if err != nil && errors.IsNotFound(err) {
resource := &csiv1alpha1.ClientProfile{
ObjectMeta: metav1.ObjectMeta{
Name: resourceName,
Namespace: "default",
},
// TODO(user): Specify other spec details if needed.
Spec: csiv1alpha1.ClientProfileSpec{
CephConnectionRef: corev1.LocalObjectReference{
Name: "foo",
},
},
}
Expect(k8sClient.Create(ctx, resource)).To(Succeed())
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/driver_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (

var _ = Describe("Driver Controller", func() {
Context("When reconciling a resource", func() {
const resourceName = "test-resource"
const resourceName = "test.rbd.csi.ceph.com"

ctx := context.Background()

Expand Down

0 comments on commit fcbf58b

Please sign in to comment.