Skip to content

test(model): Fix the test for cyclic dependencies #10083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions model/src/test/kotlin/utils/DependencyGraphBuilderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import io.kotest.core.spec.style.WordSpec
import io.kotest.matchers.collections.beEmpty
import io.kotest.matchers.collections.containExactly
import io.kotest.matchers.collections.containExactlyInAnyOrder
import io.kotest.matchers.collections.shouldContainExactly
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
import io.kotest.matchers.collections.shouldHaveSize
import io.kotest.matchers.should
Expand Down Expand Up @@ -197,19 +196,32 @@ class DependencyGraphBuilderTest : WordSpec({
}

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

val graph = createGraphBuilder()
.addDependency(scope, depCyc2)
.build()
val scopes = graph.createScopes()
val handler = object : DependencyHandler<Int> {
override fun identifierFor(dependency: Int) = Identifier.EMPTY.copy(name = dependency.toString())

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

graph.nodes shouldHaveSize 3
override fun linkageFor(dependency: Int) = PackageLinkage.DYNAMIC

override fun createPackage(dependency: Int, issues: MutableCollection<Issue>) = null
}

val graph = DependencyGraphBuilder(handler)
.addDependency("root", 1)
.build(checkReferences = false)

graph.nodes shouldHaveSize 6
graph.edges shouldHaveSize 7
}

"check for illegal references when building the graph" {
Expand Down
Loading