Skip to content

Commit 64f45c2

Browse files
committed
test(downloader): Make getRevisionCandidates() tests independent of Git
Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 2205dbd commit 64f45c2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

downloader/src/test/kotlin/VersionControlSystemTest.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@ import io.kotest.matchers.shouldBe
2525

2626
import io.mockk.every
2727
import io.mockk.mockk
28+
import io.mockk.spyk
2829

2930
import java.io.File
3031
import java.io.IOException
3132

3233
import org.ossreviewtoolkit.model.Package
3334
import org.ossreviewtoolkit.model.VcsInfo
3435
import org.ossreviewtoolkit.model.VcsType
35-
import org.ossreviewtoolkit.plugins.api.PluginConfig
36-
import org.ossreviewtoolkit.plugins.versioncontrolsystems.git.GitFactory
3736
import org.ossreviewtoolkit.utils.common.div
3837

3938
class VersionControlSystemTest : WordSpec({
@@ -84,11 +83,11 @@ class VersionControlSystemTest : WordSpec({
8483
)
8584

8685
val workingTree = mockk<WorkingTree>()
86+
val vcs = spyk<VersionControlSystem>()
8787

8888
every { workingTree.guessRevisionName(any(), any()) } returns "v1.6.0"
8989

90-
GitFactory().create(PluginConfig.EMPTY)
91-
.getRevisionCandidates(workingTree, pkg, allowMovingRevisions = true) shouldBeSuccess listOf(
90+
vcs.getRevisionCandidates(workingTree, pkg, allowMovingRevisions = true) shouldBeSuccess listOf(
9291
"v1.6.0"
9392
)
9493
}
@@ -103,6 +102,11 @@ class VersionControlSystemTest : WordSpec({
103102
)
104103

105104
val workingTree = mockk<WorkingTree>()
105+
val vcs = spyk<VersionControlSystem> {
106+
every { type } returns VcsType.GIT
107+
every { isFixedRevision(any(), "master") } returns Result.success(false)
108+
every { isFixedRevision(any(), "main") } returns Result.success(false)
109+
}
106110

107111
every {
108112
workingTree.guessRevisionName(any(), any())
@@ -111,8 +115,7 @@ class VersionControlSystemTest : WordSpec({
111115
every { workingTree.listRemoteBranches() } returns listOf("main")
112116
every { workingTree.listRemoteTags() } returns emptyList()
113117

114-
GitFactory().create(PluginConfig.EMPTY)
115-
.getRevisionCandidates(workingTree, pkg, allowMovingRevisions = true) shouldBeSuccess listOf(
118+
vcs.getRevisionCandidates(workingTree, pkg, allowMovingRevisions = true) shouldBeSuccess listOf(
116119
"master",
117120
"main"
118121
)

0 commit comments

Comments
 (0)