Skip to content

Commit 0b6c028

Browse files
committed
Extract testing VolumeReactor into a separate package
1 parent 6d691c9 commit 0b6c028

File tree

6 files changed

+693
-609
lines changed

6 files changed

+693
-609
lines changed

pkg/controller/volume/persistentvolume/delete_test.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"k8s.io/api/core/v1"
2424
storage "k8s.io/api/storage/v1"
25+
pvtesting "k8s.io/kubernetes/pkg/controller/volume/persistentvolume/testing"
2526
)
2627

2728
// Test single call to syncVolume, expecting recycling to happen.
@@ -91,11 +92,9 @@ func TestDeleteSync(t *testing.T) {
9192
noclaims,
9293
noclaims,
9394
noevents, noerrors,
94-
wrapTestWithInjectedOperation(wrapTestWithReclaimCalls(operationDelete, []error{}, testSyncVolume), func(ctrl *PersistentVolumeController, reactor *volumeReactor) {
95+
wrapTestWithInjectedOperation(wrapTestWithReclaimCalls(operationDelete, []error{}, testSyncVolume), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) {
9596
// Delete the volume before delete operation starts
96-
reactor.lock.Lock()
97-
delete(reactor.volumes, "volume8-6")
98-
reactor.lock.Unlock()
97+
reactor.DeleteVolume("volume8-6")
9998
}),
10099
},
101100
{
@@ -108,16 +107,12 @@ func TestDeleteSync(t *testing.T) {
108107
noclaims,
109108
newClaimArray("claim8-7", "uid8-7", "10Gi", "volume8-7", v1.ClaimBound, nil),
110109
noevents, noerrors,
111-
wrapTestWithInjectedOperation(wrapTestWithReclaimCalls(operationDelete, []error{}, testSyncVolume), func(ctrl *PersistentVolumeController, reactor *volumeReactor) {
112-
reactor.lock.Lock()
113-
defer reactor.lock.Unlock()
110+
wrapTestWithInjectedOperation(wrapTestWithReclaimCalls(operationDelete, []error{}, testSyncVolume), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) {
114111
// Bind the volume to resurrected claim (this should never
115112
// happen)
116113
claim := newClaim("claim8-7", "uid8-7", "10Gi", "volume8-7", v1.ClaimBound, nil)
117-
reactor.claims[claim.Name] = claim
114+
reactor.AddClaimBoundToVolume(claim)
118115
ctrl.claims.Add(claim)
119-
volume := reactor.volumes["volume8-7"]
120-
volume.Status.Phase = v1.VolumeBound
121116
}),
122117
},
123118
{
@@ -141,7 +136,7 @@ func TestDeleteSync(t *testing.T) {
141136
noclaims,
142137
noclaims,
143138
noevents, noerrors,
144-
func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error {
139+
func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error {
145140
// Inject external deleter annotation
146141
test.initialVolumes[0].Annotations[annDynamicallyProvisioned] = "external.io/test"
147142
test.expectedVolumes[0].Annotations[annDynamicallyProvisioned] = "external.io/test"
@@ -184,7 +179,7 @@ func TestDeleteSync(t *testing.T) {
184179
newClaimArray("claim8-12", "uid8-12", "10Gi", "volume8-12-2", v1.ClaimBound, nil),
185180
newClaimArray("claim8-12", "uid8-12", "10Gi", "volume8-12-2", v1.ClaimBound, nil),
186181
noevents, noerrors,
187-
func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error {
182+
func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error {
188183
// Inject external deleter annotation
189184
test.initialVolumes[0].Annotations[annDynamicallyProvisioned] = "external.io/test"
190185
test.expectedVolumes[0].Annotations[annDynamicallyProvisioned] = "external.io/test"

0 commit comments

Comments
 (0)