|
| 1 | +package sidecar_controller |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + crdv1beta1 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta1" |
| 7 | + |
| 8 | + v1 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1" |
| 9 | + "k8s.io/apimachinery/pkg/labels" |
| 10 | + "k8s.io/client-go/tools/record" |
| 11 | +) |
| 12 | + |
| 13 | +type fakeContentLister struct { |
| 14 | +} |
| 15 | + |
| 16 | +func (f *fakeContentLister) List(selector labels.Selector) (ret []*v1.VolumeSnapshotContent, err error) { |
| 17 | + return nil, nil |
| 18 | +} |
| 19 | +func (f *fakeContentLister) Get(name string) (*v1.VolumeSnapshotContent, error) { |
| 20 | + return &v1.VolumeSnapshotContent{}, nil |
| 21 | +} |
| 22 | + |
| 23 | +func TestDeleteCSIGroupSnapshotOperation(t *testing.T) { |
| 24 | + ctrl := &csiSnapshotSideCarController{ |
| 25 | + contentLister: &fakeContentLister{}, |
| 26 | + handler: &csiHandler{}, |
| 27 | + eventRecorder: &record.FakeRecorder{}, |
| 28 | + } |
| 29 | + |
| 30 | + defer func() { |
| 31 | + if r := recover(); r != nil { |
| 32 | + t.Errorf("deleteCSIGroupSnapshotOperation() panicked with: %v", r) |
| 33 | + } |
| 34 | + }() |
| 35 | + err := ctrl.deleteCSIGroupSnapshotOperation(nil) |
| 36 | + if err == nil { |
| 37 | + t.Errorf("expected deleteCSIGroupSnapshotOperation to return error when groupsnapshotContent is nil: %v", err) |
| 38 | + } |
| 39 | + gsc := crdv1beta1.VolumeGroupSnapshotContent{ |
| 40 | + Status: &crdv1beta1.VolumeGroupSnapshotContentStatus{ |
| 41 | + VolumeSnapshotHandlePairList: []crdv1beta1.VolumeSnapshotHandlePair{ |
| 42 | + { |
| 43 | + VolumeHandle: "test-pv", |
| 44 | + SnapshotHandle: "test-vsc", |
| 45 | + }, |
| 46 | + }, |
| 47 | + }, |
| 48 | + } |
| 49 | + err = ctrl.deleteCSIGroupSnapshotOperation(&gsc) |
| 50 | + if err == nil { |
| 51 | + t.Errorf("expected deleteCSIGroupSnapshotOperation to return error when groupsnapshotContent is empty: %v", err) |
| 52 | + } |
| 53 | +} |
0 commit comments