Skip to content

Commit 2d18c93

Browse files
committed
test(model): Fix the test for cyclic dependencies
There is no cycle in the originally defined depCyc2 -> depFoo -> depCyc1 dependency chain. Doing so is actually not directly possible with the recursively defined `PackageReference` class. Solve that by using a primitive `DependencyHandler` that just uses indexes to identify dependencies. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent f26c647 commit 2d18c93

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

model/src/test/kotlin/utils/DependencyGraphBuilderTest.kt

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import io.kotest.core.spec.style.WordSpec
2424
import io.kotest.matchers.collections.beEmpty
2525
import io.kotest.matchers.collections.containExactly
2626
import io.kotest.matchers.collections.containExactlyInAnyOrder
27-
import io.kotest.matchers.collections.shouldContainExactly
2827
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
2928
import io.kotest.matchers.collections.shouldHaveSize
3029
import io.kotest.matchers.should
@@ -197,19 +196,32 @@ class DependencyGraphBuilderTest : WordSpec({
197196
}
198197

199198
"deal with cycles in dependencies" {
200-
val scope = "CyclicScope"
201-
val depCyc1 = createDependency("org.cyclic", "cyclic", "77.7")
202-
val depFoo = createDependency("org.foo", "foo", "1.2.0", dependencies = setOf(depCyc1))
203-
val depCyc2 = createDependency("org.cyclic", "cyclic", "77.7", dependencies = setOf(depFoo))
199+
// A simple map of indexed nodes with their dependencies.
200+
@Suppress("NoMultipleSpaces")
201+
val dependencies = mapOf(
202+
1 to listOf(2, 3),
203+
2 to listOf(4, 5),
204+
3 to listOf(1), // Cycle: 1 -> 3 -> 1
205+
5 to listOf(6),
206+
6 to listOf(2) // Cycle: 1 -> 2 -> 5 -> 6 -> 2
207+
)
204208

205-
val graph = createGraphBuilder()
206-
.addDependency(scope, depCyc2)
207-
.build()
208-
val scopes = graph.createScopes()
209+
val handler = object : DependencyHandler<Int> {
210+
override fun identifierFor(dependency: Int) = Identifier.EMPTY.copy(name = dependency.toString())
209211

210-
scopeDependencies(scopes, scope) shouldContainExactly listOf(depCyc2)
212+
override fun dependenciesFor(dependency: Int) = dependencies[dependency].orEmpty()
211213

212-
graph.nodes shouldHaveSize 3
214+
override fun linkageFor(dependency: Int) = PackageLinkage.DYNAMIC
215+
216+
override fun createPackage(dependency: Int, issues: MutableCollection<Issue>) = null
217+
}
218+
219+
val graph = DependencyGraphBuilder(handler)
220+
.addDependency("root", 1)
221+
.build(checkReferences = false)
222+
223+
graph.nodes shouldHaveSize 6
224+
graph.edges shouldHaveSize 7
213225
}
214226

215227
"check for illegal references when building the graph" {

0 commit comments

Comments
 (0)