-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7984cb2
commit 1c05f87
Showing
1 changed file
with
41 additions
and
20 deletions.
There are no files selected for viewing
61 changes: 41 additions & 20 deletions
61
src/test/kotlin/com/sourcegraph/cody/initialization/UninstallListenerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,66 @@ | ||
package com.sourcegraph.cody.initialization | ||
|
||
import com.intellij.ide.plugins.* | ||
import com.intellij.openapi.extensions.PluginId | ||
import com.intellij.testFramework.fixtures.BasePlatformTestCase | ||
import com.sourcegraph.cody.config.CodyAuthenticationManager | ||
import com.sourcegraph.cody.telemetry.TelemetryV2 | ||
import com.sourcegraph.config.ConfigUtil.getPluginId | ||
import com.sourcegraph.config.ConfigUtil | ||
import io.mockk.* | ||
|
||
@Suppress("UnstableApiUsage") | ||
class UninstallListenerTest : BasePlatformTestCase() { | ||
|
||
fun `test plugin uninstall cleans up resources`() { | ||
val uninstallListener = UninstallListener() | ||
private val uninstallListener = UninstallListener() | ||
|
||
// Mock dependencies | ||
// relaxed = true to allow unit returning methods to auto-mock | ||
private val authManager = mockk<CodyAuthenticationManager>(relaxed = true) | ||
|
||
// Mock dependencies | ||
// relaxed = true to allow unit returning methods to auto-mock | ||
val authManager = mockk<CodyAuthenticationManager>(relaxed = true) | ||
override fun setUp() { | ||
super.setUp() | ||
|
||
// setup mock objects | ||
mockkObject(CodyAuthenticationManager) | ||
every { | ||
CodyAuthenticationManager.getInstance() | ||
} returns authManager | ||
every { CodyAuthenticationManager.getInstance() } returns authManager | ||
mockkObject(TelemetryV2) | ||
every { | ||
TelemetryV2.sendTelemetryEvent(any(), any(), any()) | ||
} returns Unit | ||
every { TelemetryV2.sendTelemetryEvent(any(), any(), any()) } returns Unit | ||
} | ||
|
||
private fun getPlugin() = | ||
PluginManagerCore.findPlugin(ConfigUtil.getPluginId()) ?: throw Exception("Plugin not found") | ||
|
||
fun `test plugin uninstall cleans up resources`() { | ||
// Execute uninstall | ||
uninstallListener.runActivity(project) | ||
val plugin = PluginManagerCore.findPlugin(getPluginId()) | ||
plugin ?: throw Exception("Plugin not found") | ||
val plugin = getPlugin() | ||
PluginInstaller.prepareToUninstall(plugin) | ||
verify { | ||
authManager.setActiveAccount(null) | ||
authManager.removeAll() | ||
TelemetryV2.sendTelemetryEvent( | ||
any(), | ||
"cody.extension", | ||
"uninstalled", | ||
any() | ||
) | ||
TelemetryV2.sendTelemetryEvent(any(), "cody.extension", "uninstalled", any()) | ||
} | ||
} | ||
|
||
fun `test plugin uninstall does nothing for unrelated plugins`() { | ||
// Execute uninstall | ||
val plugin = getPlugin() | ||
uninstallListener.runActivity(project) | ||
|
||
// Now mock out config util so that it returns a different plugin id | ||
// so that the UninstallListener thinks it's a different plugin | ||
mockkStatic(ConfigUtil::getPluginId) | ||
every { ConfigUtil.getPluginId() } returns PluginId.getId("com.sourcegraph.cody.test") | ||
|
||
PluginInstaller.prepareToUninstall(plugin) | ||
// Remove the static method mock so that it doesn't interfere with other tests | ||
unmockkStatic(ConfigUtil::getPluginId) | ||
|
||
// Verify that the uninstall listener didn't do anything | ||
verify(exactly = 0) { | ||
authManager.setActiveAccount(null) | ||
authManager.removeAll() | ||
TelemetryV2.sendTelemetryEvent(any(), "cody.extension", "uninstalled", any()) | ||
} | ||
} | ||
} |