Skip to content

Commit 828794e

Browse files
committed
test(vcs): Simplify Git workling tree assertions
Also better follow the AAA pattern while at it. Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
1 parent a8f4e4f commit 828794e

File tree

1 file changed

+26
-37
lines changed
  • plugins/version-control-systems/git/src/funTest/kotlin

1 file changed

+26
-37
lines changed

plugins/version-control-systems/git/src/funTest/kotlin/GitFunTest.kt

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import io.kotest.assertions.throwables.shouldThrow
2424
import io.kotest.core.annotation.Tags
2525
import io.kotest.core.spec.style.WordSpec
2626
import io.kotest.engine.spec.tempdir
27+
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
2728
import io.kotest.matchers.shouldBe
2829

2930
import java.io.File
@@ -78,47 +79,39 @@ class GitFunTest : WordSpec({
7879

7980
"get the given revision" {
8081
val pkg = Package.EMPTY.copy(vcsProcessed = VcsInfo(VcsType.GIT, REPO_URL, REPO_REV))
81-
val expectedFiles = listOf(
82-
".git",
83-
".gitignore",
82+
83+
val workingTree = git.download(pkg, outputDir)
84+
85+
workingTree.isValid() shouldBe true
86+
workingTree.getRevision() shouldBe REPO_REV
87+
workingTree.getRootPath().walk().maxDepth(1).mapNotNullTo(mutableListOf()) { file ->
88+
file.toRelativeString(outputDir).takeIf { it.isNotEmpty() && !it.startsWith('.') }
89+
}.shouldContainExactlyInAnyOrder(
8490
"CHANGELOG.md",
8591
"LICENSE",
8692
"README.md",
8793
"lib",
8894
"package.json",
8995
"specs"
9096
)
91-
92-
val workingTree = git.download(pkg, outputDir)
93-
val actualFiles = workingTree.getRootPath().walk().maxDepth(1).mapNotNullTo(mutableListOf()) {
94-
it.toRelativeString(workingTree.getRootPath()).ifEmpty { null }
95-
}.sorted()
96-
97-
workingTree.isValid() shouldBe true
98-
workingTree.getRevision() shouldBe REPO_REV
99-
actualFiles.joinToString("\n") shouldBe expectedFiles.joinToString("\n")
10097
}
10198

10299
"get only the given path" {
103100
val pkg = Package.EMPTY.copy(vcsProcessed = VcsInfo(VcsType.GIT, REPO_URL, REPO_REV, path = REPO_PATH))
104-
val expectedFiles = listOf(
105-
File("LICENSE"),
106-
File("README.md"),
107-
File(REPO_PATH, "dep_graph.js"),
108-
File(REPO_PATH, "index.d.ts")
109-
)
110101

111102
val workingTree = git.download(pkg, outputDir)
112-
val actualFiles = workingTree.getRootPath().walkBottomUp()
113-
.onEnter { it.name != ".git" }
114-
.filter { it.isFile }
115-
.map { it.relativeTo(outputDir) }
116-
.sortedBy { it.path }
117-
.toList()
118103

119104
workingTree.isValid() shouldBe true
120105
workingTree.getRevision() shouldBe REPO_REV
121-
actualFiles.joinToString("\n") shouldBe expectedFiles.joinToString("\n")
106+
workingTree.getRootPath().walk().mapNotNullTo(mutableListOf()) { file ->
107+
file.toRelativeString(outputDir).takeIf { it.isNotEmpty() && !it.startsWith('.') }
108+
}.shouldContainExactlyInAnyOrder(
109+
"LICENSE",
110+
"README.md",
111+
"lib",
112+
"lib/dep_graph.js",
113+
"lib/index.d.ts"
114+
)
122115
}
123116

124117
"work based on a package version" {
@@ -142,23 +135,19 @@ class GitFunTest : WordSpec({
142135
// Use a non-blank dummy revision to enforce multiple revision candidates being tried.
143136
vcsProcessed = VcsInfo(VcsType.GIT, REPO_URL, "dummy", path = REPO_PATH_FOR_VERSION)
144137
)
145-
val expectedFiles = listOf(
146-
File("LICENSE"),
147-
File("README.md"),
148-
File(REPO_PATH_FOR_VERSION, "dep_graph_spec.js")
149-
)
150138

151139
val workingTree = git.download(pkg, outputDir)
152-
val actualFiles = workingTree.getRootPath().walkBottomUp()
153-
.onEnter { it.name != ".git" }
154-
.filter { it.isFile }
155-
.map { it.relativeTo(outputDir) }
156-
.sortedBy { it.path }
157-
.toList()
158140

159141
workingTree.isValid() shouldBe true
160142
workingTree.getRevision() shouldBe REPO_REV_FOR_VERSION
161-
actualFiles.joinToString("\n") shouldBe expectedFiles.joinToString("\n")
143+
workingTree.getRootPath().walk().mapNotNullTo(mutableListOf()) { file ->
144+
file.toRelativeString(outputDir).takeIf { it.isNotEmpty() && !it.startsWith('.') }
145+
}.shouldContainExactlyInAnyOrder(
146+
"LICENSE",
147+
"README.md",
148+
"specs",
149+
"specs/dep_graph_spec.js"
150+
)
162151
}
163152
}
164153
})

0 commit comments

Comments
 (0)