@@ -2,7 +2,6 @@ package controller
22
33import (
44 "context"
5- "fmt"
65 "testing"
76 "time"
87
@@ -34,7 +33,6 @@ func TestController(t *testing.T) {
3433 NodeResize bool
3534 CallCSIExpand bool
3635 expectBlockVolume bool
37- expectError bool
3836
3937 // is PVC being expanded in-use
4038 pvcInUse bool
@@ -113,7 +111,6 @@ func TestController(t *testing.T) {
113111 CallCSIExpand : false ,
114112 pvcHasInUseErrors : true ,
115113 pvcInUse : true ,
116- expectError : true ,
117114 },
118115 {
119116 Name : "Resize PVC, no FS resize, pvc-inuse but no failedprecondition error" ,
@@ -148,20 +145,15 @@ func TestController(t *testing.T) {
148145 }
149146 }
150147
148+ if test .pvcInUse {
149+ pod := withPVC (test .PVC .Name , pod ())
150+ initialObjects = append (initialObjects , pod )
151+ }
152+
151153 kubeClient , informerFactory := fakeK8s (initialObjects )
152154 pvInformer := informerFactory .Core ().V1 ().PersistentVolumes ()
153155 pvcInformer := informerFactory .Core ().V1 ().PersistentVolumeClaims ()
154-
155- for _ , obj := range initialObjects {
156- switch obj .(type ) {
157- case * v1.PersistentVolume :
158- pvInformer .Informer ().GetStore ().Add (obj )
159- case * v1.PersistentVolumeClaim :
160- pvcInformer .Informer ().GetStore ().Add (obj )
161- default :
162- t .Fatalf ("Test %s: Unknown initalObject type: %+v" , test .Name , obj )
163- }
164- }
156+ podInformer := informerFactory .Core ().V1 ().Pods ()
165157
166158 metricsManager := metrics .NewCSIMetricsManager ("" /* driverName */ )
167159 metricsAddress := ""
@@ -182,23 +174,28 @@ func TestController(t *testing.T) {
182174 }
183175 }
184176
185- if test .pvcInUse {
186- pod := withPVC (test .PVC .Name , pod ())
187- ctrlInstance .usedPVCs .addPod (pod )
188- if ! ctrlInstance .usedPVCs .checkForUse (test .PVC ) {
189- t .Fatalf ("pvc %s is not in use" , test .PVC .Name )
190- }
191- }
177+ stopCh := make (chan struct {})
178+ informerFactory .Start (stopCh )
192179
193- err = ctrlInstance .syncPVC (fmt .Sprintf ("%s/%s" , test .PVC .Namespace , test .PVC .Name ))
194- if err != nil && ! test .expectError {
195- t .Fatalf ("Test %s: Unexpected error: %v" , test .Name , err )
196- }
180+ ctx := context .TODO ()
181+ defer ctx .Done ()
182+ go controller .Run (1 , ctx )
197183
198- if test .expectError && err == nil {
199- t .Fatalf ("Test %s: expected error got no none" , test .Name )
184+ for _ , obj := range initialObjects {
185+ switch obj .(type ) {
186+ case * v1.PersistentVolume :
187+ pvInformer .Informer ().GetStore ().Add (obj )
188+ case * v1.PersistentVolumeClaim :
189+ pvcInformer .Informer ().GetStore ().Add (obj )
190+ case * v1.Pod :
191+ podInformer .Informer ().GetStore ().Add (obj )
192+ default :
193+ t .Fatalf ("Test %s: Unknown initalObject type: %+v" , test .Name , obj )
194+ }
200195 }
201196
197+ time .Sleep (time .Second * 2 )
198+
202199 expandCallCount := client .GetExpandCount ()
203200 if test .CallCSIExpand && expandCallCount == 0 {
204201 t .Fatalf ("for %s: expected csi expand call, no csi expand call was made" , test .Name )
0 commit comments