From dd7dfcbc3d09e436ff409df043614628c9421388 Mon Sep 17 00:00:00 2001 From: Chris Simon Date: Sat, 16 Mar 2024 04:26:14 +0000 Subject: [PATCH] test(intellij): start adding some ci tests for the intellij plugin --- .github/actions/upload-reports/action.yml | 4 +-- .github/workflows/contextive.yml | 10 +++--- src/intellij/contextive/build.gradle.kts | 10 ++++++ .../contextive/LanguageServerDownloader.kt | 2 +- .../ContextiveLspServerSupportProviderTest.kt | 36 +++++++++++++++++++ .../LanguageServerDownloaderKtTest.kt | 31 ++++++++++++++++ 6 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 src/intellij/contextive/src/test/kotlin/tech/contextive/contextive/ContextiveLspServerSupportProviderTest.kt create mode 100644 src/intellij/contextive/src/test/kotlin/tech/contextive/contextive/LanguageServerDownloaderKtTest.kt diff --git a/.github/actions/upload-reports/action.yml b/.github/actions/upload-reports/action.yml index ec9cca12..8ac971b3 100644 --- a/.github/actions/upload-reports/action.yml +++ b/.github/actions/upload-reports/action.yml @@ -35,7 +35,7 @@ runs: if: always() with: name: ${{ steps.name-slug.outputs.slug }}-test-results-net${{ env.DOTNET_VERSION }}-${{ runner.os }} - path: "**/TestResults/TestResults*-${{ env.DOTNET_VERSION }}-${{ runner.os }}.xml" + path: "**/(TestResults|test-results)/*.xml" - name: Create ${{ inputs.name }}Test Report Check @@ -43,7 +43,7 @@ runs: if: always() with: name: ${{ inputs.name }} Tests (net${{ env.DOTNET_VERSION }} - ${{ runner.os }}) - path: "**/TestResults/TestResults*-${{ env.DOTNET_VERSION }}-${{ runner.os }}.xml" + path: "**/(TestResults|test-results)/*.xml" reporter: ${{ inputs.reporter }} diff --git a/.github/workflows/contextive.yml b/.github/workflows/contextive.yml index 818e68c5..2b56afdb 100644 --- a/.github/workflows/contextive.yml +++ b/.github/workflows/contextive.yml @@ -49,8 +49,8 @@ jobs: run: ./gradlew build working-directory: src/intellij/contextive - # - uses: ./.github/actions/upload-reports - # if: always() - # with: - # name: 'Contextive VsCode Extension' - # reporter: java-junit \ No newline at end of file + - uses: ./.github/actions/upload-reports + if: always() + with: + name: 'Contextive IntelliJ Plugin' + reporter: java-junit \ No newline at end of file diff --git a/src/intellij/contextive/build.gradle.kts b/src/intellij/contextive/build.gradle.kts index 483c26ba..d8c46a6e 100644 --- a/src/intellij/contextive/build.gradle.kts +++ b/src/intellij/contextive/build.gradle.kts @@ -13,6 +13,9 @@ repositories { dependencies { implementation("net.lingala.zip4j:zip4j:2.11.5") + testImplementation(kotlin("test")) + testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.0") + testImplementation("io.mockk:mockk:1.13.10") } // Configure Gradle IntelliJ Plugin @@ -54,4 +57,11 @@ tasks { publishPlugin { token.set(System.getenv("PUBLISH_TOKEN")) } + + test { + useJUnitPlatform() + testLogging { + events("PASSED", "SKIPPED", "FAILED") + } + } } diff --git a/src/intellij/contextive/src/main/kotlin/tech/contextive/contextive/LanguageServerDownloader.kt b/src/intellij/contextive/src/main/kotlin/tech/contextive/contextive/LanguageServerDownloader.kt index b95a71ea..03cbb437 100644 --- a/src/intellij/contextive/src/main/kotlin/tech/contextive/contextive/LanguageServerDownloader.kt +++ b/src/intellij/contextive/src/main/kotlin/tech/contextive/contextive/LanguageServerDownloader.kt @@ -21,7 +21,7 @@ private const val LANGUAGE_SERVER_TEMPLATE = "https://github.com/dev-cycles/contextive/releases/download/v%s/Contextive.LanguageServer-%s-%s-%1\$s.zip" private const val CONTEXTIVE_ID = "tech.contextive.contextive" -private fun getOsCode(): String = System.getProperty("os.name").lowercase().run { +fun getOsCode(): String = System.getProperty("os.name").lowercase().run { when { "win" in this -> "win" "mac" in this -> "osx" diff --git a/src/intellij/contextive/src/test/kotlin/tech/contextive/contextive/ContextiveLspServerSupportProviderTest.kt b/src/intellij/contextive/src/test/kotlin/tech/contextive/contextive/ContextiveLspServerSupportProviderTest.kt new file mode 100644 index 00000000..b66aef7a --- /dev/null +++ b/src/intellij/contextive/src/test/kotlin/tech/contextive/contextive/ContextiveLspServerSupportProviderTest.kt @@ -0,0 +1,36 @@ +package tech.contextive.contextive + +import com.intellij.openapi.project.BaseProjectDirectories +import com.intellij.openapi.project.BaseProjectDirectories.Companion.getBaseDirectories +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.platform.lsp.api.LspServerSupportProvider +import io.mockk.* + + +class ContextiveLspServerSupportProviderTest { + + @Test + fun ShouldAlwaysStartLanguageServer() { + val lspServerSupportProvider = ContextiveLspServerSupportProvider() + + val project = mockk { + every { getService(any()) } returns + mockk { + every { getBaseDirectories() } returns emptySet() + } + } + val file = mockk() + val serverStarter = mockk { + every { ensureServerStarted(any()) } returns Unit + } + + lspServerSupportProvider.fileOpened(project, file, serverStarter); + + verify { serverStarter.ensureServerStarted(any()) } + + confirmVerified(serverStarter) + } +} \ No newline at end of file diff --git a/src/intellij/contextive/src/test/kotlin/tech/contextive/contextive/LanguageServerDownloaderKtTest.kt b/src/intellij/contextive/src/test/kotlin/tech/contextive/contextive/LanguageServerDownloaderKtTest.kt new file mode 100644 index 00000000..e9746690 --- /dev/null +++ b/src/intellij/contextive/src/test/kotlin/tech/contextive/contextive/LanguageServerDownloaderKtTest.kt @@ -0,0 +1,31 @@ +package tech.contextive.contextive + +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.CsvSource + +class LanguageServerDownloaderKtTest { + + @BeforeEach + fun setUp() { + } + + @AfterEach + fun tearDown() { + } + + @ParameterizedTest + @CsvSource("Windows,win", "MacOs X,osx", "Ubuntu,linux") + fun shouldGetOsCode(osName: String, expectedOsCode: String) { + val existingOsName = System.getProperty("os.name") + System.setProperty("os.name", osName) + + val osCode = getOsCode() + + assertEquals(expectedOsCode, osCode) + + System.setProperty("os.name", existingOsName) + } +} \ No newline at end of file