Skip to content

Commit

Permalink
fix:project startup test
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Apr 27, 2024
1 parent 01b7faa commit 7f6f6ee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/com/dsoftware/ghmanager/psi/Tools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.util.Collections
object Tools {
fun isActionFile(virtualFile: VirtualFile): Boolean {
return (virtualFile.name == "action.yml" || virtualFile.name == "action.yaml")
&& virtualFile.parent.path.endsWith(".github/actions")
&& virtualFile.parent.parent.path.endsWith(".github/actions")
}

fun isWorkflowFile(virtualFile: VirtualFile): Boolean {
Expand Down
41 changes: 27 additions & 14 deletions src/test/kotlin/com/dsoftware/ghmanager/psi/ProjectStartupTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package com.dsoftware.ghmanager.psi

import com.intellij.codeInsight.navigation.openFileWithPsiElement
import com.intellij.openapi.components.service
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.psi.PsiManager
import com.intellij.testFramework.common.initTestApplication
import com.intellij.testFramework.junit5.RunInEdt
import com.intellij.testFramework.rules.ClassLevelProjectModelExtension
import com.intellij.testFramework.rules.ProjectModelExtension
import com.intellij.testFramework.useProject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
Expand All @@ -15,20 +14,16 @@ import org.junit.jupiter.api.extension.RegisterExtension

@RunInEdt(writeIntent = true)
class ProjectStartupTest {


companion object {
init {
initTestApplication()
}

@JvmField
@RegisterExtension
protected val projectRule: ClassLevelProjectModelExtension = ClassLevelProjectModelExtension()
init {
initTestApplication()
}

@JvmField
@RegisterExtension
protected val projectRule: ProjectModelExtension = ProjectModelExtension()

@Test
fun testScanWorkflowFile() {
fun `testScanWorkflowFile workflow-file is scanned`() {
val content = """
jobs:
build:
Expand All @@ -49,9 +44,27 @@ class ProjectStartupTest {
val gitHubActionDataService = project.service<GitHubActionDataService>()
Assertions.assertEquals(1, gitHubActionDataService.actionsToResolve.size)
}
}

@Test
fun `testScanWorkflowFile action-file is scanned`() {
val content = """
runs:
using: "composite"
steps:
- uses: mshick/add-pr-comment@v2
message-id: coverage
""".trimIndent()
val workflowFile = projectRule.baseProjectDir
.newVirtualFile(".github/actions/test-coverage/action.yaml", content.toByteArray())

// projectResource.after()
val project = projectRule.project
project.useProject {
val psiFile = PsiManager.getInstance(project).findFile(workflowFile)
openFileWithPsiElement(psiFile!!, true, true)
val gitHubActionDataService = project.service<GitHubActionDataService>()
Assertions.assertEquals(1, gitHubActionDataService.actionsToResolve.size)
}
}


Expand Down

0 comments on commit 7f6f6ee

Please sign in to comment.