Skip to content

Commit

Permalink
feat: add test for initialization options
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch committed Nov 8, 2023
1 parent b71064c commit bc48fcc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/snyk/common/lsp/LanguageServerWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class LanguageServerWrapper(private val lsPath: String = getCliFile().absolutePa
languageServer.workspaceService.executeCommand(param)
}

private fun getInitializationOptions(): LanguageServerSettings {
fun getInitializationOptions(): LanguageServerSettings {
val ps = pluginSettings()
return LanguageServerSettings(
activateSnykOpenSource = "false",
Expand Down
22 changes: 21 additions & 1 deletion src/test/java/snyk/common/lsp/LanguageServerWrapperTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.unmockkAll
import io.mockk.verify
import io.snyk.plugin.getCliFile
import io.snyk.plugin.pluginSettings
import io.snyk.plugin.services.SnykApplicationSettingsStateService
import junit.framework.TestCase.assertEquals
import org.eclipse.lsp4j.ExecuteCommandParams
import org.eclipse.lsp4j.InitializeParams
import org.eclipse.lsp4j.services.LanguageServer
Expand All @@ -22,13 +24,14 @@ class LanguageServerWrapperTest {

private val projectMock: Project = mockk()
private val lsMock: LanguageServer = mockk()
private val settings = SnykApplicationSettingsStateService()
private lateinit var cut: LanguageServerWrapper

@Before
fun setUp() {
unmockkAll()
mockkStatic("io.snyk.plugin.UtilsKt")
every { pluginSettings() } returns SnykApplicationSettingsStateService()
every { pluginSettings() } returns settings
mockkStatic("snyk.PluginInformationKt")
every { pluginInfo } returns mockk(relaxed = true)
every { pluginInfo.integrationName } returns "Snyk Intellij Plugin"
Expand Down Expand Up @@ -67,4 +70,21 @@ class LanguageServerWrapperTest {

verify { lsMock.workspaceService.executeCommand(any<ExecuteCommandParams>()) }
}

@Test
fun getInitializationOptions() {
settings.token = "testToken"
settings.customEndpointUrl = "testEndpoint/"
settings.ignoreUnknownCA = true
settings.cliPath = "testCliPath"

val actual = cut.getInitializationOptions()

assertEquals("false", actual.activateSnykCode)
assertEquals("false", actual.activateSnykIac)
assertEquals("false", actual.activateSnykOpenSource)
assertEquals(settings.token, actual.token)
assertEquals("${settings.ignoreUnknownCA}", actual.insecure)
assertEquals(getCliFile().absolutePath, actual.cliPath)
}
}

0 comments on commit bc48fcc

Please sign in to comment.