Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch committed Jan 8, 2025
1 parent f06cb8e commit a5fd609
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/main/kotlin/snyk/common/lsp/LanguageServerWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import io.snyk.plugin.getWaitForResultsTimeout
import io.snyk.plugin.pluginSettings
import io.snyk.plugin.runInBackground
import io.snyk.plugin.toLanguageServerURL
import io.snyk.plugin.toVirtualFile
import io.snyk.plugin.ui.toolwindow.SnykPluginDisposable
import org.eclipse.lsp4j.ClientCapabilities
import org.eclipse.lsp4j.ClientInfo
Expand Down Expand Up @@ -68,6 +67,7 @@ import snyk.pluginInfo
import snyk.trust.WorkspaceTrustService
import snyk.trust.confirmScanningAndSetWorkspaceTrustedStateIfNeeded
import java.io.FileNotFoundException
import java.net.URI
import java.util.Collections
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
Expand All @@ -88,7 +88,8 @@ class LanguageServerWrapper(
private var authenticatedUser: Map<String, String>? = null
private var initializeResult: InitializeResult? = null
private val gson = Gson()
private val configuredWorkspaceFolders: MutableSet<WorkspaceFolder> = Collections.synchronizedSet(mutableSetOf())
// internal for test set up
internal val configuredWorkspaceFolders: MutableSet<WorkspaceFolder> = Collections.synchronizedSet(mutableSetOf())
private var disposed = false
get() {
return ApplicationManager.getApplication().isDisposed || field
Expand Down Expand Up @@ -436,7 +437,7 @@ class LanguageServerWrapper(
if (notAuthenticated()) return
if (DumbService.getInstance(project).isDumb) return
try {
val folderUri = folder.toVirtualFile().toLanguageServerURL()
val folderUri = URI.create(folder).toASCIIString()
if (!configuredWorkspaceFolders.any { it.uri == folderUri }) return
val param = ExecuteCommandParams()
param.command = COMMAND_WORKSPACE_FOLDER_SCAN
Expand Down
9 changes: 7 additions & 2 deletions src/test/kotlin/snyk/common/lsp/LanguageServerWrapperTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import junit.framework.TestCase.fail
import org.eclipse.lsp4j.DidChangeConfigurationParams
import org.eclipse.lsp4j.ExecuteCommandParams
import org.eclipse.lsp4j.InitializeParams
import org.eclipse.lsp4j.WorkspaceFolder
import org.eclipse.lsp4j.services.LanguageServer
import org.junit.After
import org.junit.Before
Expand All @@ -31,6 +32,7 @@ import snyk.common.lsp.analytics.ScanDoneEvent
import snyk.common.lsp.settings.FolderConfigSettings
import snyk.pluginInfo
import snyk.trust.WorkspaceTrustService
import java.net.URI
import java.util.concurrent.CompletableFuture

class LanguageServerWrapperTest {
Expand Down Expand Up @@ -218,7 +220,10 @@ class LanguageServerWrapperTest {
lsMock.workspaceService.executeCommand(any<ExecuteCommandParams>())
} returns CompletableFuture.completedFuture(null)

cut.sendFolderScanCommand("testFolder", projectMock)
val folder = "testFolder"
cut.configuredWorkspaceFolders.add(WorkspaceFolder(URI(folder).toString(), folder))

cut.sendFolderScanCommand(folder, projectMock)

verify { lsMock.workspaceService.executeCommand(any<ExecuteCommandParams>()) }
}
Expand Down Expand Up @@ -263,7 +268,7 @@ class LanguageServerWrapperTest {
every { dumbServiceMock.isDumb } returns false
settings.scanOnSave = true

cut.updateConfiguration()
cut.updateConfiguration(true)

verify { lsMock.workspaceService.didChangeConfiguration(any<DidChangeConfigurationParams>()) }

Expand Down

0 comments on commit a5fd609

Please sign in to comment.