|
1 | 1 | package controller |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "github.com/cybozu-go/mantle/internal/ceph" |
4 | 5 | "github.com/cybozu-go/mantle/test/util" |
5 | 6 | . "github.com/onsi/ginkgo/v2" |
6 | 7 | . "github.com/onsi/gomega" |
| 8 | + "go.uber.org/mock/gomock" |
7 | 9 | corev1 "k8s.io/api/core/v1" |
8 | 10 | storagev1 "k8s.io/api/storage/v1" |
9 | 11 | "k8s.io/apimachinery/pkg/api/resource" |
10 | 12 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
11 | 13 | ) |
12 | 14 |
|
| 15 | +var _ = Describe("util.createCloneByPV", func() { |
| 16 | + DescribeTable("matrix test", |
| 17 | + func(ctx SpecContext, |
| 18 | + pv *corev1.PersistentVolume, snapshotName, cloneName string, // arguments |
| 19 | + lsIsCalled bool, lsPool string, images []string, // for RBDLs |
| 20 | + infoIsCalled bool, infoPool, infoImage string, info *ceph.RBDImageInfo, // for RBDInfo |
| 21 | + cloneIsCalled bool, clonePool, cloneImage, cloneFeatures string, // for RBDClone |
| 22 | + expectedErr bool) { |
| 23 | + ctrl := gomock.NewController(GinkgoT()) |
| 24 | + defer ctrl.Finish() |
| 25 | + |
| 26 | + cmdMock := ceph.NewMockCephCmd(ctrl) |
| 27 | + if lsIsCalled { |
| 28 | + cmdMock.EXPECT().RBDLs(lsPool).Return(images, nil) |
| 29 | + } |
| 30 | + if infoIsCalled { |
| 31 | + cmdMock.EXPECT().RBDInfo(infoPool, infoImage).Return(info, nil) |
| 32 | + } |
| 33 | + if cloneIsCalled { |
| 34 | + cmdMock.EXPECT().RBDClone(clonePool, cloneImage, snapshotName, cloneName, cloneFeatures).Return(nil) |
| 35 | + } |
| 36 | + createCloneByPV(ctx, cmdMock, pv, snapshotName, cloneName) |
| 37 | + }, |
| 38 | + Entry("clone does not exist, create clone", |
| 39 | + &corev1.PersistentVolume{ |
| 40 | + Spec: corev1.PersistentVolumeSpec{ |
| 41 | + PersistentVolumeSource: corev1.PersistentVolumeSource{ |
| 42 | + CSI: &corev1.CSIPersistentVolumeSource{ |
| 43 | + VolumeAttributes: map[string]string{ |
| 44 | + "imageName": "bkImage", |
| 45 | + "pool": "bkPool", |
| 46 | + }, |
| 47 | + }, |
| 48 | + }, |
| 49 | + }, |
| 50 | + }, |
| 51 | + true, "bkPool", []string{"bkImage"}, |
| 52 | + false, "", "", nil, |
| 53 | + true, "bkPool", "bkImage", "deep-flatten", |
| 54 | + false, |
| 55 | + ), |
| 56 | + ) |
| 57 | +}) |
| 58 | + |
13 | 59 | var _ = Describe("util.getCephClusterIDFromPVC", func() { |
14 | 60 | var namespace string |
15 | 61 | storageClassName := util.GetUniqueName("sc-") |
|
0 commit comments