Skip to content

Commit 11239ee

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 9663709 commit 11239ee

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,30 @@ class DependencyGraphBuilderTest : WordSpec({
197197
}
198198

199199
"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))
200+
val dependencies = mapOf(
201+
1 to listOf(2, 3),
202+
2 to listOf(4, 5),
203+
3 to listOf(1), // Cycle: 1 -> 3 -> 1
204+
5 to listOf(6),
205+
6 to listOf(2) // Cycle: 1 -> 2 -> 5 -> 6 -> 2
206+
)
204207

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

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

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

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

0 commit comments

Comments
 (0)