Skip to content

Commit a9ce79a

Browse files
committed
test(cli): Factor out createGitRepoProject()
Make the test's code more readable. Signed-off-by: Frank Viernau <[email protected]>
1 parent 24ede02 commit a9ce79a

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

cli/src/funTest/kotlin/AnalyzerFunTest.kt

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919

2020
package org.ossreviewtoolkit.cli
2121

22+
import io.kotest.core.TestConfiguration
2223
import io.kotest.core.spec.style.WordSpec
2324
import io.kotest.engine.spec.tempdir
2425
import io.kotest.matchers.concurrent.shouldCompleteWithin
2526
import io.kotest.matchers.shouldBe
2627

28+
import java.io.File
2729
import java.util.concurrent.TimeUnit
2830

2931
import org.ossreviewtoolkit.analyzer.Analyzer
@@ -45,18 +47,9 @@ class AnalyzerFunTest : WordSpec({
4547
"An analysis" should {
4648
"correctly report repositories git-repo for projects" {
4749
val expectedRepository = getAssetFile("git-repo-expected-repository.yml").readValue<Repository>()
48-
val pkg = Package.EMPTY.copy(
49-
vcsProcessed = VcsInfo(
50-
type = VcsType.GIT_REPO,
51-
url = "https://github.com/oss-review-toolkit/ort-test-data-git-repo?manifest=manifest.xml",
52-
revision = "31588aa8f8555474e1c3c66a359ec99e4cd4b1fa"
53-
)
54-
)
55-
val outputDir = tempdir().also {
56-
GitRepoFactory().create(PluginConfig.EMPTY).download(pkg, it)
57-
}
50+
val projectDir = createGitRepoProject()
5851

59-
val repository = analyze(outputDir, packageManagers = emptySet()).repository
52+
val repository = analyze(projectDir, packageManagers = emptySet()).repository
6053

6154
repository shouldBe expectedRepository
6255
}
@@ -85,3 +78,17 @@ class AnalyzerFunTest : WordSpec({
8578
}
8679
}
8780
})
81+
82+
private fun TestConfiguration.createGitRepoProject(): File {
83+
val pkg = Package.EMPTY.copy(
84+
vcsProcessed = VcsInfo(
85+
type = VcsType.GIT_REPO,
86+
url = "https://github.com/oss-review-toolkit/ort-test-data-git-repo?manifest=manifest.xml",
87+
revision = "31588aa8f8555474e1c3c66a359ec99e4cd4b1fa"
88+
)
89+
)
90+
91+
return tempdir().also {
92+
GitRepoFactory().create(PluginConfig.EMPTY).download(pkg, it)
93+
}
94+
}

0 commit comments

Comments
 (0)