@@ -106,6 +106,22 @@ func newCloneDataVolume(name string) *cdiv1.DataVolume {
106
106
}
107
107
}
108
108
109
+ func newUploadDataVolume (name string ) * cdiv1.DataVolume {
110
+ return & cdiv1.DataVolume {
111
+ TypeMeta : metav1.TypeMeta {APIVersion : cdiv1 .SchemeGroupVersion .String ()},
112
+ ObjectMeta : metav1.ObjectMeta {
113
+ Name : name ,
114
+ Namespace : metav1 .NamespaceDefault ,
115
+ },
116
+ Spec : cdiv1.DataVolumeSpec {
117
+ Source : cdiv1.DataVolumeSource {
118
+ UPLOAD : & cdiv1.DataVolumeSourceUpload {},
119
+ },
120
+ PVC : & corev1.PersistentVolumeClaimSpec {},
121
+ },
122
+ }
123
+ }
124
+
109
125
func (f * fixture ) newController () (* DataVolumeController , informers.SharedInformerFactory , kubeinformers.SharedInformerFactory ) {
110
126
f .client = fake .NewSimpleClientset (f .objects ... )
111
127
f .kubeclient = k8sfake .NewSimpleClientset (f .kubeobjects ... )
@@ -543,3 +559,106 @@ func TestCloneClaimLost(t *testing.T) {
543
559
f .expectUpdateDataVolumeStatusAction (result )
544
560
f .run (getKey (dataVolume , t ))
545
561
}
562
+
563
+ // Upload tests
564
+ func TestUploadScheduled (t * testing.T ) {
565
+ f := newFixture (t )
566
+ dataVolume := newUploadDataVolume ("upload-datavolume" )
567
+ pvc , _ := newPersistentVolumeClaim (dataVolume )
568
+
569
+ dataVolume .Status .Phase = cdiv1 .Pending
570
+ pvc .Status .Phase = corev1 .ClaimBound
571
+ pvc .Annotations [AnnUploadRequest ] = ""
572
+
573
+ f .dataVolumeLister = append (f .dataVolumeLister , dataVolume )
574
+ f .objects = append (f .objects , dataVolume )
575
+ f .pvcLister = append (f .pvcLister , pvc )
576
+ f .kubeobjects = append (f .kubeobjects , pvc )
577
+
578
+ result := dataVolume .DeepCopy ()
579
+ result .Status .Phase = cdiv1 .UploadScheduled
580
+ f .expectUpdateDataVolumeStatusAction (result )
581
+ f .run (getKey (dataVolume , t ))
582
+ }
583
+
584
+ func TestUploadReady (t * testing.T ) {
585
+ f := newFixture (t )
586
+ dataVolume := newUploadDataVolume ("upload-datavolume" )
587
+ pvc , _ := newPersistentVolumeClaim (dataVolume )
588
+
589
+ dataVolume .Status .Phase = cdiv1 .Pending
590
+ pvc .Status .Phase = corev1 .ClaimBound
591
+ pvc .Annotations [AnnUploadRequest ] = ""
592
+ pvc .Annotations [AnnPodPhase ] = "Running"
593
+
594
+ f .dataVolumeLister = append (f .dataVolumeLister , dataVolume )
595
+ f .objects = append (f .objects , dataVolume )
596
+ f .pvcLister = append (f .pvcLister , pvc )
597
+ f .kubeobjects = append (f .kubeobjects , pvc )
598
+
599
+ result := dataVolume .DeepCopy ()
600
+ result .Status .Phase = cdiv1 .UploadReady
601
+ f .expectUpdateDataVolumeStatusAction (result )
602
+ f .run (getKey (dataVolume , t ))
603
+ }
604
+
605
+ func TestUploadSucceeded (t * testing.T ) {
606
+ f := newFixture (t )
607
+ dataVolume := newUploadDataVolume ("upload-datavolume" )
608
+ pvc , _ := newPersistentVolumeClaim (dataVolume )
609
+
610
+ dataVolume .Status .Phase = cdiv1 .Pending
611
+ pvc .Status .Phase = corev1 .ClaimBound
612
+ pvc .Annotations [AnnUploadRequest ] = ""
613
+ pvc .Annotations [AnnPodPhase ] = "Succeeded"
614
+
615
+ f .dataVolumeLister = append (f .dataVolumeLister , dataVolume )
616
+ f .objects = append (f .objects , dataVolume )
617
+ f .pvcLister = append (f .pvcLister , pvc )
618
+ f .kubeobjects = append (f .kubeobjects , pvc )
619
+
620
+ result := dataVolume .DeepCopy ()
621
+ result .Status .Phase = cdiv1 .Succeeded
622
+ f .expectUpdateDataVolumeStatusAction (result )
623
+ f .run (getKey (dataVolume , t ))
624
+ }
625
+
626
+ func TestUploadPodFailed (t * testing.T ) {
627
+ f := newFixture (t )
628
+ dataVolume := newCloneDataVolume ("upload-datavolume" )
629
+ pvc , _ := newPersistentVolumeClaim (dataVolume )
630
+
631
+ dataVolume .Status .Phase = cdiv1 .Pending
632
+ pvc .Status .Phase = corev1 .ClaimBound
633
+ pvc .Annotations [AnnUploadRequest ] = ""
634
+ pvc .Annotations [AnnPodPhase ] = "Failed"
635
+
636
+ f .dataVolumeLister = append (f .dataVolumeLister , dataVolume )
637
+ f .objects = append (f .objects , dataVolume )
638
+ f .pvcLister = append (f .pvcLister , pvc )
639
+ f .kubeobjects = append (f .kubeobjects , pvc )
640
+
641
+ result := dataVolume .DeepCopy ()
642
+ result .Status .Phase = cdiv1 .Failed
643
+ f .expectUpdateDataVolumeStatusAction (result )
644
+ f .run (getKey (dataVolume , t ))
645
+ }
646
+
647
+ func TestUploadClaimLost (t * testing.T ) {
648
+ f := newFixture (t )
649
+ dataVolume := newUploadDataVolume ("upload-datavolume" )
650
+ pvc , _ := newPersistentVolumeClaim (dataVolume )
651
+
652
+ dataVolume .Status .Phase = cdiv1 .Pending
653
+ pvc .Status .Phase = corev1 .ClaimLost
654
+
655
+ f .dataVolumeLister = append (f .dataVolumeLister , dataVolume )
656
+ f .objects = append (f .objects , dataVolume )
657
+ f .pvcLister = append (f .pvcLister , pvc )
658
+ f .kubeobjects = append (f .kubeobjects , pvc )
659
+
660
+ result := dataVolume .DeepCopy ()
661
+ result .Status .Phase = cdiv1 .Failed
662
+ f .expectUpdateDataVolumeStatusAction (result )
663
+ f .run (getKey (dataVolume , t ))
664
+ }
0 commit comments