Skip to content

Commit

Permalink
test(intellij): start adding some ci tests for the intellij plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissimon-au committed Mar 16, 2024
1 parent ab3348d commit dd7dfcb
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/actions/upload-reports/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ 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
uses: dorny/test-reporter@v1
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 }}


Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/contextive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- uses: ./.github/actions/upload-reports
if: always()
with:
name: 'Contextive IntelliJ Plugin'
reporter: java-junit
10 changes: 10 additions & 0 deletions src/intellij/contextive/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -54,4 +57,11 @@ tasks {
publishPlugin {
token.set(System.getenv("PUBLISH_TOKEN"))
}

test {
useJUnitPlatform()
testLogging {
events("PASSED", "SKIPPED", "FAILED")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Project> {
every { getService<BaseProjectDirectories>(any()) } returns
mockk {
every { getBaseDirectories() } returns emptySet()
}
}
val file = mockk<VirtualFile>()
val serverStarter = mockk<LspServerSupportProvider.LspServerStarter> {
every { ensureServerStarted(any()) } returns Unit
}

lspServerSupportProvider.fileOpened(project, file, serverStarter);

verify { serverStarter.ensureServerStarted(any()) }

confirmVerified(serverStarter)
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit dd7dfcb

Please sign in to comment.