File tree 2 files changed +14
-4
lines changed
main/kotlin/com/redhat/devtools/intellij/kubernetes/editor
test/kotlin/com/redhat/devtools/intellij/kubernetes/editor
2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -50,19 +50,22 @@ open class EditorResource(
50
50
/* *
51
51
* Sets the resource to this instance. Only modified versions of the same resource are processed.
52
52
* Will do nothing if the given resource is a different resource in name, namespace, kind etc.
53
+ * Resets the existing resource state if a new resource is set
53
54
*
54
55
* @param new the new resource that should be set to this editor resource
55
56
*
56
- * @see isSameResource
57
+ * @see [areEqual]
58
+ * @see [isSameResource]
59
+ * @see [setState]
57
60
*/
58
61
fun setResource (new : HasMetadata ) {
59
62
resourceChangeMutex.withLock {
60
63
val existing = this .resource
61
64
if (new.isSameResource(existing)
62
65
&& ! areEqual(new, existing)) {
63
66
this .resource = new
67
+ setState(null ) // reset state
64
68
}
65
- setState(null ) // reset state
66
69
}
67
70
}
68
71
@@ -90,8 +93,11 @@ open class EditorResource(
90
93
91
94
/* *
92
95
* Returns the state of this editor resource.
96
+ * Returns a cached state if it exists, creates it if it doesn't.
93
97
*
94
98
* @return the state of this editor resource.
99
+ *
100
+ * @see [createState]
95
101
*/
96
102
fun getState (): EditorResourceState {
97
103
return resourceChangeMutex.withLock {
Original file line number Diff line number Diff line change @@ -311,10 +311,14 @@ class EditorResourceTest {
311
311
doReturn(true )
312
312
.whenever(clusterResource).isAuthorized()
313
313
val editorResource = createEditorResource(POD2 )
314
+ val modifiedPod2 = PodBuilder (POD2 )
315
+ .editMetadata()
316
+ .withLabels<String , String >(mapOf (" jedi" to " yoda" ))
317
+ .endMetadata()
318
+ .build()
314
319
val error = Error (" oh my!" )
315
320
editorResource.setState(error)
316
- editorResource.setLastPushedPulled(POD3 ) // modified = (current resource != lastPushedPulled)
317
- editorResource.setResource(POD2 ) // cause state to be recreated
321
+ editorResource.setResource(modifiedPod2) // new resource != existing resource, causes state to be reset and then recreated
318
322
// when
319
323
val state = editorResource.getState()
320
324
// then
You can’t perform that action at this time.
0 commit comments