@@ -94,7 +94,6 @@ void callDeleteOnControllerIfMarkedForDeletionButThereIsNoDefaultFinalizer() {
94
94
@ Test
95
95
void removesDefaultFinalizerOnDelete () {
96
96
markForDeletion (testCustomResource );
97
- testCustomResource .getMetadata ().getFinalizers ().add (DEFAULT_FINALIZER );
98
97
99
98
eventDispatcher .handleEvent (customResourceEvent (Watcher .Action .MODIFIED , testCustomResource ));
100
99
@@ -106,7 +105,6 @@ void removesDefaultFinalizerOnDelete() {
106
105
void doesNotRemovesTheFinalizerIfTheDeleteMethodRemovesFalse () {
107
106
when (resourceController .deleteResource (eq (testCustomResource ), any ())).thenReturn (false );
108
107
markForDeletion (testCustomResource );
109
- testCustomResource .getMetadata ().getFinalizers ().add (DEFAULT_FINALIZER );
110
108
111
109
eventDispatcher .handleEvent (customResourceEvent (Watcher .Action .MODIFIED , testCustomResource ));
112
110
@@ -116,7 +114,6 @@ void doesNotRemovesTheFinalizerIfTheDeleteMethodRemovesFalse() {
116
114
117
115
@ Test
118
116
void doesNotUpdateTheResourceIfNoUpdateUpdateControl () {
119
- testCustomResource .getMetadata ().getFinalizers ().add (DEFAULT_FINALIZER );
120
117
when (resourceController .createOrUpdateResource (eq (testCustomResource ), any ())).thenReturn (UpdateControl .noUpdate ());
121
118
122
119
eventDispatcher .handleEvent (customResourceEvent (Watcher .Action .MODIFIED , testCustomResource ));
@@ -126,6 +123,7 @@ void doesNotUpdateTheResourceIfNoUpdateUpdateControl() {
126
123
127
124
@ Test
128
125
void addsFinalizerIfNotMarkedForDeletionAndEmptyCustomResourceReturned () {
126
+ removeFinalizers (testCustomResource );
129
127
when (resourceController .createOrUpdateResource (eq (testCustomResource ), any ())).thenReturn (UpdateControl .noUpdate ());
130
128
131
129
eventDispatcher .handleEvent (customResourceEvent (Watcher .Action .MODIFIED , testCustomResource ));
@@ -135,20 +133,24 @@ void addsFinalizerIfNotMarkedForDeletionAndEmptyCustomResourceReturned() {
135
133
}
136
134
137
135
@ Test
138
- void doesNotAddFinalizerIfNoUpdateIsReturnedButMarkedForDeletion () {
136
+ void doesNotCallDeleteIfMarkedForDeletionButNotOurFinalizer () {
137
+ removeFinalizers (testCustomResource );
139
138
markForDeletion (testCustomResource );
140
- when (resourceController .createOrUpdateResource (eq (testCustomResource ), any ())).thenReturn (UpdateControl .noUpdate ());
141
139
142
140
eventDispatcher .handleEvent (customResourceEvent (Watcher .Action .MODIFIED , testCustomResource ));
143
141
144
- assertEquals (0 , testCustomResource .getMetadata ().getFinalizers ().size ());
145
142
verify (customResourceFacade , never ()).replaceWithLock (any ());
143
+ verify (resourceController , never ()).deleteResource (eq (testCustomResource ), any ());
146
144
}
147
145
148
146
private void markForDeletion (CustomResource customResource ) {
149
147
customResource .getMetadata ().setDeletionTimestamp ("2019-8-10" );
150
148
}
151
149
150
+ private void removeFinalizers (CustomResource customResource ) {
151
+ customResource .getMetadata ().getFinalizers ().clear ();
152
+ }
153
+
152
154
CustomResource getResource () {
153
155
TestCustomResource resource = new TestCustomResource ();
154
156
resource .setMetadata (new ObjectMetaBuilder ()
@@ -157,6 +159,7 @@ CustomResource getResource() {
157
159
.withDeletionGracePeriodSeconds (10L )
158
160
.withGeneration (10L )
159
161
.withName ("name" )
162
+ .withFinalizers (DEFAULT_FINALIZER )
160
163
.withNamespace ("namespace" )
161
164
.withResourceVersion ("resourceVersion" )
162
165
.withSelfLink ("selfLink" )
0 commit comments