Skip to content

Commit

Permalink
chore(DuplicateFinderTest): parametrize `same file is detected as one…
Browse files Browse the repository at this point in the history
… is found via symbolic link`, include test for duplicate directory (root / root)
  • Loading branch information
guicamest committed Nov 21, 2023
1 parent e34a3a7 commit 8c7ac05
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ import kotlinx.coroutines.test.runTest
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Condition
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Named
import org.junit.jupiter.api.Named.named
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import java.nio.file.FileSystem
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.attribute.PosixFilePermissions
import java.util.stream.Stream
import kotlin.io.path.absolute
import kotlin.io.path.createDirectory
import kotlin.io.path.createSymbolicLinkPointingTo
Expand All @@ -26,6 +33,7 @@ import kotlin.test.Test
class DuplicateFinderTest {
@DisplayName("not detect duplicates when")
@Nested
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
inner class NoDuplicates {
private val duplicateFinder: DuplicateFinder = SequentialDuplicateFinder(GlobalScope)

Expand Down Expand Up @@ -115,8 +123,11 @@ class DuplicateFinderTest {
}
}

@Test
fun `same file is detected as one is found via symbolic link`(): Unit =
@ParameterizedTest
@MethodSource("symbolicLinkTests")
fun `same file is detected as one is found via symbolic link`(
directoriesFn: (SymbolicTestDirectories) -> List<Path>,
): Unit =
inLinux { fs ->
val root = fs.rootDirectories.first()
val volumes = (root / fs.getPath("Volumes")).createDirectory()
Expand All @@ -128,15 +139,23 @@ class DuplicateFinderTest {
val execution =
findDuplicates(
parentScope = this,
directories = listOf(root, linkedToRoot),
directories = directoriesFn(SymbolicTestDirectories(root, volumes, linkedToRoot)),
)

val duplicateEntries = execution.duplicateEntries()
assertThat(duplicateEntries).isEmpty()
}
}

private fun symbolicLinkTests(): Stream<Named<(SymbolicTestDirectories) -> List<Path>>> =
Stream.of(
named("root / link") { d: SymbolicTestDirectories -> listOf(d.root, d.link) },
named("duplicate directory") { d: SymbolicTestDirectories -> listOf(d.root, d.root) },
)
}

data class SymbolicTestDirectories(val root: Path, val volumes: Path, val link: Path)

@DisplayName("detect duplicates when")
@Nested
inner class Duplicates {
Expand Down

0 comments on commit 8c7ac05

Please sign in to comment.