From ea7599012999d45995cc4c9188667e5bb88a8428 Mon Sep 17 00:00:00 2001 From: guicamest Date: Thu, 19 Oct 2023 13:17:08 +0200 Subject: [PATCH] test: `finding in tempdir and tempdir/somedir/somefile and tempdir/otherdir/somefile have the same content` --- .../core/DuplicateFinderTest.kt | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/core/src/test/kotlin/com/sleepcamel/gduplicatefinder/core/DuplicateFinderTest.kt b/core/src/test/kotlin/com/sleepcamel/gduplicatefinder/core/DuplicateFinderTest.kt index cbd0dc5..e340e2e 100644 --- a/core/src/test/kotlin/com/sleepcamel/gduplicatefinder/core/DuplicateFinderTest.kt +++ b/core/src/test/kotlin/com/sleepcamel/gduplicatefinder/core/DuplicateFinderTest.kt @@ -209,6 +209,44 @@ class DuplicateFinderTest { } } } + + @Test + @DisplayName( + """ + finding in tempdir and tempdir/somedir/somefile and tempdir/otherdir/somefile + have the same content + """, + ) + fun `two files with same name in different directories have same content hash`() { + val subdirectories = + createTempDirectory().let { root -> + listOf("somedir", "otherdir").map { dirname -> + (root / Paths.get(dirname)).createDirectory() + } + } + val files = + subdirectories.map { + (it / Paths.get("somefile")).apply { writeText("hi") } + } + + val expectedDuplicateGroup = + DuplicateGroup( + hash = "hi".contentHash(), + paths = files.map { it.absolute() }, + ) + + runTest { + val duplicateFinder = SequentialDuplicateFinder(this) + val execution = duplicateFinder.find(listOf(subdirectories.first().parent)) + + val duplicateEntries = execution.duplicateEntries() + assertThat(duplicateEntries).hasSize(1) + duplicateEntries.first().also { group -> + assertThat(group.hash).isEqualTo(expectedDuplicateGroup.hash) + assertThat(group.paths).containsExactlyInAnyOrderElementsOf(expectedDuplicateGroup.paths) + } + } + } } }