@@ -22,13 +22,11 @@ import (
2222 datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
2323 "github.com/fluid-cloudnative/fluid/pkg/common"
2424 "github.com/fluid-cloudnative/fluid/pkg/utils/fake"
25- "sigs.k8s.io/controller-runtime/pkg/client"
26-
2725 appsv1 "k8s.io/api/apps/v1"
2826 corev1 "k8s.io/api/core/v1"
2927 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30-
3128 "k8s.io/apimachinery/pkg/runtime"
29+ "sigs.k8s.io/controller-runtime/pkg/client"
3230)
3331
3432// func TestGetTemplateToInjectForFuse(t *testing.T) {
@@ -1169,3 +1167,180 @@ func TestGetFuseDaemonset(t *testing.T) {
11691167 }
11701168 }
11711169}
1170+
1171+ func TestGetMountInfoFromVolumeClaim (t * testing.T ) {
1172+ namespace := "default"
1173+ testPVCInputs := []* corev1.PersistentVolumeClaim {{
1174+ ObjectMeta : metav1.ObjectMeta {Name : "fluid-dataset" ,
1175+ Namespace : namespace },
1176+ Spec : corev1.PersistentVolumeClaimSpec {
1177+ VolumeName : "default-fluid-dataset" ,
1178+ },
1179+ }, {
1180+ ObjectMeta : metav1.ObjectMeta {Name : "nonfluidpvc" ,
1181+ Annotations : common .ExpectedFluidAnnotations ,
1182+ Namespace : namespace },
1183+ Spec : corev1.PersistentVolumeClaimSpec {
1184+ VolumeName : "nonfluidpv" ,
1185+ },
1186+ }, {
1187+ ObjectMeta : metav1.ObjectMeta {Name : "nopv" ,
1188+ Annotations : common .ExpectedFluidAnnotations ,
1189+ Namespace : namespace },
1190+ Spec : corev1.PersistentVolumeClaimSpec {
1191+ VolumeName : "nopv" ,
1192+ },
1193+ }, {
1194+ ObjectMeta : metav1.ObjectMeta {Name : "fluid-dataset-subpath" ,
1195+ Annotations : common .ExpectedFluidAnnotations ,
1196+ Namespace : namespace },
1197+ Spec : corev1.PersistentVolumeClaimSpec {
1198+ VolumeName : "default-fluid-dataset-subpath" ,
1199+ },
1200+ }}
1201+
1202+ objs := []runtime.Object {}
1203+
1204+ for _ , pvc := range testPVCInputs {
1205+ objs = append (objs , pvc .DeepCopy ())
1206+ }
1207+
1208+ testPVInputs := []* corev1.PersistentVolume {{
1209+ ObjectMeta : metav1.ObjectMeta {Name : "default-fluid-dataset" },
1210+ Spec : corev1.PersistentVolumeSpec {
1211+ PersistentVolumeSource : corev1.PersistentVolumeSource {
1212+ CSI : & corev1.CSIPersistentVolumeSource {
1213+ Driver : "fuse.csi.fluid.io" ,
1214+ VolumeAttributes : map [string ]string {
1215+ common .VolumeAttrFluidPath : "/runtime-mnt/jindo/big-data/nofounddataset/jindofs-fuse" ,
1216+ common .VolumeAttrMountType : common .JindoRuntime ,
1217+ },
1218+ },
1219+ },
1220+ },
1221+ }, {
1222+ ObjectMeta : metav1.ObjectMeta {Name : "nonfluidpv" , Annotations : common .ExpectedFluidAnnotations },
1223+ Spec : corev1.PersistentVolumeSpec {},
1224+ }, {
1225+ ObjectMeta : metav1.ObjectMeta {Name : "default-fluid-dataset-subpath" },
1226+ Spec : corev1.PersistentVolumeSpec {
1227+ PersistentVolumeSource : corev1.PersistentVolumeSource {
1228+ CSI : & corev1.CSIPersistentVolumeSource {
1229+ Driver : "fuse.csi.fluid.io" ,
1230+ VolumeAttributes : map [string ]string {
1231+ common .VolumeAttrFluidPath : "/runtime-mnt/jindo/big-data/nofounddataset/jindofs-fuse" ,
1232+ common .VolumeAttrMountType : common .JindoRuntime ,
1233+ common .VolumeAttrFluidSubPath : "subtest" ,
1234+ },
1235+ },
1236+ },
1237+ },
1238+ }}
1239+
1240+ for _ , pv := range testPVInputs {
1241+ objs = append (objs , pv .DeepCopy ())
1242+ }
1243+
1244+ type args struct {
1245+ name string
1246+ namespace string
1247+ }
1248+ tests := []struct {
1249+ name string
1250+ args args
1251+ wantError bool
1252+ wantPath string
1253+ wantType string
1254+ wantSubPath string
1255+ }{{
1256+ name : "volumeClaim doesn't exist" ,
1257+ args : args {
1258+ name : "notExist" ,
1259+ namespace : namespace ,
1260+ },
1261+ wantError : true ,
1262+ }, {
1263+ name : "non fluid pv" ,
1264+ args : args {
1265+ name : "nonfluidpvc" ,
1266+ namespace : namespace ,
1267+ },
1268+ wantError : true ,
1269+ }, {
1270+ name : " fluid pv" ,
1271+ args : args {
1272+ name : "fluid-dataset" ,
1273+ namespace : namespace ,
1274+ },
1275+ wantError : false ,
1276+ wantPath : "/runtime-mnt/jindo/big-data/nofounddataset/jindofs-fuse" ,
1277+ wantType : common .JindoRuntime ,
1278+ }, {
1279+ name : "no pv" ,
1280+ args : args {
1281+ name : "nopv" ,
1282+ namespace : namespace ,
1283+ },
1284+ wantError : true ,
1285+ }, {
1286+ name : "sub pv" ,
1287+ args : args {
1288+ name : "fluid-dataset-subpath" ,
1289+ namespace : namespace ,
1290+ },
1291+ wantError : false ,
1292+ wantPath : "/runtime-mnt/jindo/big-data/nofounddataset/jindofs-fuse" ,
1293+ wantType : common .JindoRuntime ,
1294+ wantSubPath : "subtest" ,
1295+ }}
1296+
1297+ for _ , tt := range tests {
1298+ t .Run (tt .name , func (t * testing.T ) {
1299+ testScheme := runtime .NewScheme ()
1300+ _ = corev1 .AddToScheme (testScheme )
1301+ runtimeInfo := RuntimeInfo {
1302+ name : tt .args .name ,
1303+ namespace : tt .args .namespace ,
1304+ runtimeType : common .JindoRuntime ,
1305+ client : fake .NewFakeClientWithScheme (testScheme , objs ... ),
1306+ }
1307+
1308+ path , mountType , subpath , err := runtimeInfo .getMountInfo ()
1309+ got := err != nil
1310+
1311+ if got != tt .wantError {
1312+ t .Errorf ("testcase %v getMountInfo() for %v in %v = %v, err = %v" , tt .name ,
1313+ tt .args .name ,
1314+ tt .args .namespace ,
1315+ got ,
1316+ err )
1317+ }
1318+
1319+ if path != tt .wantPath {
1320+ t .Errorf ("testcase %v GetMountInfoFromVolumeClaim() for %v in %v got path %v, want path = %v" , tt .name ,
1321+ tt .args .name ,
1322+ tt .args .namespace ,
1323+ path ,
1324+ tt .wantPath )
1325+ }
1326+
1327+ if mountType != tt .wantType {
1328+ t .Errorf ("testcase %v GetMountInfoFromVolumeClaim() for %v in %v got mountType %v, want mountType = %v" , tt .name ,
1329+ tt .args .name ,
1330+ tt .args .namespace ,
1331+ mountType ,
1332+ tt .wantType )
1333+ }
1334+
1335+ if subpath != tt .wantSubPath {
1336+ t .Errorf ("testcase %v GetMountInfoFromVolumeClaim() for %v in %v got subpath %v, want subpath = %v" , tt .name ,
1337+ tt .args .name ,
1338+ tt .args .namespace ,
1339+ subpath ,
1340+ tt .wantSubPath )
1341+ }
1342+
1343+ })
1344+ }
1345+
1346+ }
0 commit comments