Skip to content

Commit 405ace7

Browse files
committed
only reset resource state if resource is modified (#634)
Signed-off-by: Andre Dietisheim <[email protected]>
1 parent e07d0b7 commit 405ace7

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Diff for: src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/EditorResource.kt

+8-2
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,22 @@ open class EditorResource(
5050
/**
5151
* Sets the resource to this instance. Only modified versions of the same resource are processed.
5252
* 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
5354
*
5455
* @param new the new resource that should be set to this editor resource
5556
*
56-
* @see isSameResource
57+
* @see [areEqual]
58+
* @see [isSameResource]
59+
* @see [setState]
5760
*/
5861
fun setResource(new: HasMetadata) {
5962
resourceChangeMutex.withLock {
6063
val existing = this.resource
6164
if (new.isSameResource(existing)
6265
&& !areEqual(new, existing)) {
6366
this.resource = new
67+
setState(null) // reset state
6468
}
65-
setState(null) // reset state
6669
}
6770
}
6871

@@ -90,8 +93,11 @@ open class EditorResource(
9093

9194
/**
9295
* Returns the state of this editor resource.
96+
* Returns a cached state if it exists, creates it if it doesn't.
9397
*
9498
* @return the state of this editor resource.
99+
*
100+
* @see [createState]
95101
*/
96102
fun getState(): EditorResourceState {
97103
return resourceChangeMutex.withLock {

Diff for: src/test/kotlin/com/redhat/devtools/intellij/kubernetes/editor/EditorResourceTest.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,14 @@ class EditorResourceTest {
311311
doReturn(true)
312312
.whenever(clusterResource).isAuthorized()
313313
val editorResource = createEditorResource(POD2)
314+
val modifiedPod2 = PodBuilder(POD2)
315+
.editMetadata()
316+
.withLabels<String, String>(mapOf("jedi" to "yoda"))
317+
.endMetadata()
318+
.build()
314319
val error = Error("oh my!")
315320
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
318322
// when
319323
val state = editorResource.getState()
320324
// then

0 commit comments

Comments
 (0)