func TestDeviceController(t *testing.T) {

	// Set the logger to development mode for verbose logs.
	logf.SetLogger(logf.ZapLogger(true))

	// Create a fake client to mock API calls.
	cl, s := CreateFakeClient(t)

	// Create a ReconcileBlockDevice object with the scheme and fake client.
	r := &ReconcileBlockDevice{client: cl, scheme: s, recorder: fakeRecorder}

	// Mock request to simulate Reconcile() being called on an event for a
	// watched resource .
	req := reconcile.Request{
		NamespacedName: types.NamespacedName{
			Name:      deviceName,
			Namespace: namespace,
		},
	}

	res, err := r.Reconcile(req)
	if err != nil {
		t.Fatalf("reconcile: (%v)", err)
	}

	// Check the result of reconciliation to make sure it has the desired state.
	if !res.Requeue {
		t.Log("reconcile did not requeue request as expected")
	}

	deviceInstance := &openebsv1alpha1.BlockDevice{}
	err = r.client.Get(context.TODO(), req.NamespacedName, deviceInstance)
	if err != nil {
		t.Errorf("get deviceInstance : (%v)", err)
	}

	// Disk Status state should be Active as expected.
	if deviceInstance.Status.State == ndm.NDMActive {
		t.Logf("BlockDevice Object state:%v match expected state:%v", deviceInstance.Status.State, ndm.NDMActive)
	} else {
		t.Fatalf("BlockDevice Object state:%v did not match expected state:%v", deviceInstance.Status.State, ndm.NDMActive)
	}
}
// TestDeviceController runs ReconcileDisk.Reconcile() against a
// fake client that tracks a BlockDevice object.
// Test description:
// Create a disk obj and associated blockdevice obj, check status of blockdevice obj,
// it should be Active, now mark disk Inactive and trigger reconcile logic
// on blockdevice, it would mark blockdevice Inactive as well. Check status of blockdevice,
// this time it should be Inactive.
TestDeviceController runs ReconcileDisk.Reconcile() against a
fake client that tracks a BlockDevice object.
Test description:
Create a disk obj and associated blockdevice obj, check status of blockdevice obj,
it should be Active, now mark disk Inactive and trigger reconcile logic
on blockdevice, it would mark blockdevice Inactive as well. Check status of blockdevice,
this time it should be Inactive.
// TestDeviceController runs ReconcileDisk . Reconcile () against a // fake client that tracks a BlockDevice object . // Test description : // Create a disk obj and associated blockdevice obj check status of blockdevice obj // it should be Active now mark disk Inactive and trigger reconcile logic // on blockdevice it would mark blockdevice Inactive as well . Check status of blockdevice // this time it should be Inactive .
func TestDeviceController(t *testing.T) {
	logf.SetLogger(logf.ZapLogger(true))
	cl, s := CreateFakeClient(t)
	r := &ReconcileBlockDevice{client: cl, scheme: s, recorder: fakeRecorder}
	req := reconcile.Request{
		NamespacedName: types.NamespacedName{
			Name:      deviceName,
			Namespace: namespace,
		},
	}
	res, err := r.Reconcile(req)
	if err != nil {
		t.Fatalf("reconcile: (%v)", err)
	}
	if !res.Requeue {
		t.Log("reconcile did not requeue request as expected")
	}
	deviceInstance := &openebsv1alpha1.BlockDevice{}
	err = r.client.Get(context.TODO(), req.NamespacedName, deviceInstance)
	if err != nil {
		t.Errorf("get deviceInstance : (%v)", err)
	}
	if deviceInstance.Status.State == ndm.NDMActive {
		t.Logf("BlockDevice Object state:%v match expected state:%v", deviceInstance.Status.State, ndm.NDMActive)
	} else {
		t.Fatalf("BlockDevice Object state:%v did not match expected state:%v", deviceInstance.Status.State, ndm.NDMActive)
	}
}
func TestDeviceController ( t * testing . T ) { logf . SetLogger ( logf . ZapLogger ( true ) ) cl , s := CreateFakeClient ( t ) r := & ReconcileBlockDevice { client : cl , scheme : s , recorder : fakeRecorder } req := reconcile . Request { NamespacedName : types . NamespacedName { Name : deviceName , Namespace : namespace , } , } res , err := r . Reconcile ( req ) if err != nil { t . Fatalf ( " " , err ) } if ! res . Requeue { t . Log ( " " ) } deviceInstance := & openebsv1alpha1 . BlockDevice { } err = r . client . Get ( context . TODO ( ) , req . NamespacedName , deviceInstance ) if err != nil { t . Errorf ( " " , err ) } if deviceInstance . Status . State == ndm . NDMActive { t . Logf ( " " , deviceInstance . Status . State , ndm . NDMActive ) } else { t . Fatalf ( " " , deviceInstance . Status . State , ndm . NDMActive ) } }
TestDeviceController runs ReconcileDisk.Reconcile() against a
fake client that tracks a BlockDevice object.
TestDeviceController runs ReconcileDisk . Reconcile () against a fake client that tracks a BlockDevice object .
// Set the logger to development mode for verbose logs. // Create a fake client to mock API calls. // Create a ReconcileBlockDevice object with the scheme and fake client. // Mock request to simulate Reconcile() being called on an event for a // watched resource . // Check the result of reconciliation to make sure it has the desired state. // Disk Status state should be Active as expected.