Skip to content

Commit

Permalink
test(downloader): Use a dedicated repository for GitWorkingTreeFunTest
Browse files Browse the repository at this point in the history
Use a dedicated repository [1] for testing the `GitWorkingTree`
implementation instead of the pipdeptree repository. This decouples the
tests from changes in the pipdeptree repository.

[1]: https://github.com/oss-review-toolkit/ort-test-data-git

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.io>
  • Loading branch information
mnonnenmacher committed Sep 22, 2023
1 parent b066399 commit 4338904
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 57 deletions.
Binary file not shown.
84 changes: 27 additions & 57 deletions downloader/src/funTest/kotlin/vcs/GitWorkingTreeFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,62 +21,62 @@ package org.ossreviewtoolkit.downloader.vcs

import io.kotest.core.spec.style.StringSpec
import io.kotest.engine.spec.tempdir
import io.kotest.matchers.collections.containAll
import io.kotest.matchers.collections.containExactlyInAnyOrder
import io.kotest.matchers.maps.beEmpty
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe

import java.io.File

import org.ossreviewtoolkit.downloader.VersionControlSystem
import org.ossreviewtoolkit.downloader.WorkingTree
import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.utils.common.unpack
import org.ossreviewtoolkit.utils.ort.ortDataDirectory
import org.ossreviewtoolkit.utils.test.getAssetFile

class GitWorkingTreeFunTest : StringSpec({
val git = Git()
val zipContentDir = tempdir()
val repoDir = tempdir()
val vcsInfo = VcsInfo(
type = VcsType.GIT,
url = "https://github.com/oss-review-toolkit/ort-test-data-git.git",
revision = "main"
)

lateinit var workingTree: WorkingTree

beforeSpec {
val zipFile = getAssetFile("pipdeptree-2018-01-03-git.zip")
println("Extracting '$zipFile' to '$zipContentDir'...")
zipFile.unpack(zipContentDir)
println("Cloning ${vcsInfo.url} to '$repoDir'...")
workingTree = git.initWorkingTree(repoDir, vcsInfo)
git.updateWorkingTree(workingTree, "main")
}

"Git detects non-working-trees" {
git.getWorkingTree(tempdir()).isValid() shouldBe false
}

"Detected Git working tree information is correct" {
val workingTree = git.getWorkingTree(zipContentDir)

workingTree.isValid() shouldBe true
workingTree.getInfo() shouldBe VcsInfo(
type = VcsType.GIT,
url = "https://github.com/naiquevin/pipdeptree.git",
revision = "6f70dd5508331b6cfcfe3c1b626d57d9836cfd7c",
path = ""
)
workingTree.getInfo() shouldBe vcsInfo.copy(revision = "6f09f276c4426c387c6663f54bbd45aea8d81dac")
workingTree.getNested() should beEmpty()
workingTree.getRootPath() shouldBe zipContentDir
workingTree.getPathToRoot(zipContentDir.resolve("tests")) shouldBe "tests"
workingTree.getRootPath() shouldBe repoDir
workingTree.getPathToRoot(repoDir.resolve("README.md")) shouldBe "README.md"
}

"Git correctly lists remote branches" {
val workingTree = git.getWorkingTree(zipContentDir)

// Ignore auto-created branches by Dependabot to avoid regular updates to this list.
workingTree.listRemoteBranches().filterNot { it.startsWith("dependabot/") } should containAll(
"main"
workingTree.listRemoteBranches() should containExactlyInAnyOrder(
"main",
"branch1",
"branch2",
"branch3"
)
}

"Git correctly lists remote tags" {
val workingTree = git.getWorkingTree(zipContentDir)

workingTree.listRemoteTags() should containAll(expectedRemoteTags)
workingTree.listRemoteTags() should containExactlyInAnyOrder(
"tag1",
"tag2",
"tag3"
)
}

"Git correctly lists submodules" {
Expand All @@ -88,36 +88,6 @@ class GitWorkingTreeFunTest : StringSpec({
"plugins/package-managers/stack/src/funTest/assets/projects/external/quickcheck-state-machine"
).associateWith { VersionControlSystem.getPathInfo(File("../$it")) }

val workingTree = git.getWorkingTree(File(".."))
workingTree.getNested() shouldBe expectedSubmodules
git.getWorkingTree(File("..")).getNested() shouldBe expectedSubmodules
}
})

private val expectedRemoteTags = listOf(
"0.10.0",
"0.10.1",
"0.11.0",
"0.12.0",
"0.12.1",
"0.13.0",
"0.13.1",
"0.13.2",
"0.5.0",
"0.6.0",
"0.7.0",
"0.8.0",
"0.9.0",
"1.0.0",
"2.0.0",
"2.0.0b1",
"2.1.0",
"2.2.0",
"2.2.1",
"2.3.0",
"2.3.1",
"2.3.2",
"2.3.3",
"2.4.0",
"2.5.0",
"2.5.1"
)

0 comments on commit 4338904

Please sign in to comment.