Skip to content

Commit 8a8e36d

Browse files
committed
test(downloader): Move getPathToRoot() tests to functional tests
While these do not require the external `git` CLI tool, they make JGit calls that access ORT's Git repository on the file system, and thus should rather be functional tests. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 64f45c2 commit 8a8e36d

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

downloader/src/funTest/kotlin/VersionControlSystemFunTest.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,50 @@ import io.kotest.matchers.shouldBe
2828
import io.kotest.matchers.shouldNot
2929
import io.kotest.matchers.shouldNotBe
3030

31+
import java.io.File
32+
3133
import org.ossreviewtoolkit.model.VcsType
3234
import org.ossreviewtoolkit.plugins.api.PluginConfig
35+
import org.ossreviewtoolkit.utils.common.div
3336

3437
@Tags("RequiresExternalTool")
3538
class VersionControlSystemFunTest : WordSpec({
39+
val vcsRoot = File("..").absoluteFile.normalize()
40+
val relProjDir = File("src/test")
41+
val absProjDir = relProjDir.absoluteFile
42+
43+
"For an absolute working directory, getPathToRoot()" should {
44+
val absVcsDir = VersionControlSystem.forDirectory(absProjDir)!!
45+
46+
"work if given absolute paths" {
47+
absVcsDir.getPathToRoot(vcsRoot) shouldBe ""
48+
absVcsDir.getPathToRoot(vcsRoot / "downloader" / "src") shouldBe "downloader/src"
49+
absVcsDir.getPathToRoot(absProjDir / "kotlin") shouldBe "downloader/src/test/kotlin"
50+
}
51+
52+
"work if given relative paths" {
53+
absVcsDir.getPathToRoot(File(".")) shouldBe "downloader"
54+
absVcsDir.getPathToRoot(File("..")) shouldBe ""
55+
absVcsDir.getPathToRoot(File("src/test/kotlin")) shouldBe "downloader/src/test/kotlin"
56+
}
57+
}
58+
59+
"For a relative working directory, getPathToRoot()" should {
60+
val relVcsDir = VersionControlSystem.forDirectory(relProjDir)!!
61+
62+
"work if given absolute paths" {
63+
relVcsDir.getPathToRoot(vcsRoot) shouldBe ""
64+
relVcsDir.getPathToRoot(vcsRoot / "downloader" / "src") shouldBe "downloader/src"
65+
relVcsDir.getPathToRoot(absProjDir / "kotlin") shouldBe "downloader/src/test/kotlin"
66+
}
67+
68+
"work if given relative paths" {
69+
relVcsDir.getPathToRoot(relProjDir) shouldBe "downloader/src/test"
70+
relVcsDir.getPathToRoot(File("..")) shouldBe ""
71+
relVcsDir.getPathToRoot(File("src/test/kotlin")) shouldBe "downloader/src/test/kotlin"
72+
}
73+
}
74+
3675
"forUrl()" should {
3776
"return null for an unsupported repository URL" {
3877
val repositoryUrl = "https://example.com"

downloader/src/test/kotlin/VersionControlSystemTest.kt

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,57 +21,18 @@ package org.ossreviewtoolkit.downloader
2121

2222
import io.kotest.core.spec.style.WordSpec
2323
import io.kotest.matchers.result.shouldBeSuccess
24-
import io.kotest.matchers.shouldBe
2524

2625
import io.mockk.every
2726
import io.mockk.mockk
2827
import io.mockk.spyk
2928

30-
import java.io.File
3129
import java.io.IOException
3230

3331
import org.ossreviewtoolkit.model.Package
3432
import org.ossreviewtoolkit.model.VcsInfo
3533
import org.ossreviewtoolkit.model.VcsType
36-
import org.ossreviewtoolkit.utils.common.div
3734

3835
class VersionControlSystemTest : WordSpec({
39-
val vcsRoot = File("..").absoluteFile.normalize()
40-
val relProjDir = File("src/test")
41-
val absProjDir = relProjDir.absoluteFile
42-
43-
"For an absolute working directory, getPathToRoot()" should {
44-
val absVcsDir = VersionControlSystem.forDirectory(absProjDir)!!
45-
46-
"work if given absolute paths" {
47-
absVcsDir.getPathToRoot(vcsRoot) shouldBe ""
48-
absVcsDir.getPathToRoot(vcsRoot / "downloader" / "src") shouldBe "downloader/src"
49-
absVcsDir.getPathToRoot(absProjDir / "kotlin") shouldBe "downloader/src/test/kotlin"
50-
}
51-
52-
"work if given relative paths" {
53-
absVcsDir.getPathToRoot(File(".")) shouldBe "downloader"
54-
absVcsDir.getPathToRoot(File("..")) shouldBe ""
55-
absVcsDir.getPathToRoot(File("src/test/kotlin")) shouldBe "downloader/src/test/kotlin"
56-
}
57-
}
58-
59-
"For a relative working directory, getPathToRoot()" should {
60-
val relVcsDir = VersionControlSystem.forDirectory(relProjDir)!!
61-
62-
"work if given absolute paths" {
63-
relVcsDir.getPathToRoot(vcsRoot) shouldBe ""
64-
relVcsDir.getPathToRoot(vcsRoot / "downloader" / "src") shouldBe "downloader/src"
65-
relVcsDir.getPathToRoot(absProjDir / "kotlin") shouldBe "downloader/src/test/kotlin"
66-
}
67-
68-
"work if given relative paths" {
69-
relVcsDir.getPathToRoot(relProjDir) shouldBe "downloader/src/test"
70-
relVcsDir.getPathToRoot(File("..")) shouldBe ""
71-
relVcsDir.getPathToRoot(File("src/test/kotlin")) shouldBe "downloader/src/test/kotlin"
72-
}
73-
}
74-
7536
"getRevisionCandidates()" should {
7637
"prefer a matching tag name over a branch name from metadata" {
7738
val pkg = Package.EMPTY.copy(

0 commit comments

Comments
 (0)