Skip to content

Commit

Permalink
handle null file configs (when removed) when notified of changes
Browse files Browse the repository at this point in the history
this change is required by the change in ConfigWatcher at
redhat-developer/intellij-common#202

Signed-off-by: Andre Dietisheim <[email protected]>
  • Loading branch information
adietish committed Nov 22, 2023
1 parent 3e1cf9e commit a49dbc5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sinceIdeaBuild=232
projectVersion=1.2.1-SNAPSHOT
jetBrainsToken=invalid
jetBrainsChannel=stable
intellijPluginVersion=1.15.0
intellijPluginVersion=1.16.0
intellijCommonVersion=1.9.3-SNAPSHOT
telemetryPluginVersion=1.0.0.44
kotlin.stdlib.default.dependency = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,13 @@ open class AllContexts(
* The latter gets closed/recreated whenever the context changes in
* [com.redhat.devtools.intellij.kubernetes.model.client.KubeConfigAdapter].
*/
val watcher = ConfigWatcher(path) { _, config -> onKubeConfigChanged(config) }
val watcher = ConfigWatcher(path) { _, config: io.fabric8.kubernetes.api.model.Config? -> onKubeConfigChanged(config) }
runAsync(watcher::run)
}

protected open fun onKubeConfigChanged(fileConfig: io.fabric8.kubernetes.api.model.Config) {
protected open fun onKubeConfigChanged(fileConfig: io.fabric8.kubernetes.api.model.Config?) {
synchronized(this) {
fileConfig ?: return
val client = client.get() ?: return
val clientConfig = client.config.configuration
if (ConfigHelper.areEqual(fileConfig, clientConfig)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,15 @@ class AllContextsTest {
verify(modelChange, never()).fireCurrentNamespaceChanged(anyOrNull(), anyOrNull())
}

@Test
fun `#onKubeConfigChanged() should NOT fire if new config is null`() {
// given
// when
allContexts.onKubeConfigChanged(null)
// then
verify(modelChange, never()).fireAllContextsChanged()
}

@Test
fun `#onKubeConfigChanged() should NOT fire if existing config and given config are equal`() {
// given
Expand Down Expand Up @@ -550,7 +559,7 @@ class AllContextsTest {
}

/** override with public method so that it can be tested**/
public override fun onKubeConfigChanged(fileConfig: Config) {
public override fun onKubeConfigChanged(fileConfig: Config?) {
super.onKubeConfigChanged(fileConfig)
}

Expand Down

0 comments on commit a49dbc5

Please sign in to comment.