Skip to content

Commit

Permalink
Merge pull request #189 from DataDog/nogorodnikov/rum-1052/delete-old…
Browse files Browse the repository at this point in the history
…-shrinked-mapping-file-before-writing

RUM-1052: Delete old shrinked mapping file before writing to it
  • Loading branch information
0xnm authored Sep 13, 2023
2 parents 8025b34 + e1b760a commit 148c985
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ open class DdMappingFileUploadTask
)

val shrinkedFile = File(mappingFile.parent, MAPPING_OPTIMIZED_FILE_NAME)
if (shrinkedFile.exists()) {
shrinkedFile.delete()
}
// sort is needed to have predictable replacement in the following case:
// imagine there are 2 keys - "androidx.work" and "androidx.work.Job", and the latter
// occurs much more often than the rest under "androidx.work.*". So for the more efficient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,59 @@ internal class DdMappingFileUploadTaskTest {
}
}

@Test
fun `𝕄 upload file 𝕎 applyTask() { delete old shrinked mapping file before writing }`(
forge: Forge
) {
// Given
val expectedLines = forge.aList {
forge.anAlphabeticalString() + forge.aString { ' ' }
}
val fakeMappingFile = File(tempDir, fakeMappingFileName)
fakeMappingFile.writeText(
expectedLines.joinToString(separator = "\n") {
val indent = if (forge.aBool()) forge.aString { ' ' } else ""
indent + it
}
)

testedTask.mappingFileTrimIndents = true
testedTask.mappingFilePath = fakeMappingFile.path
val fakeRepositoryFile = File(tempDir, fakeRepositoryFileName)
testedTask.repositoryFile = fakeRepositoryFile
whenever(mockRepositoryDetector.detectRepositories(any(), eq("")))
.doReturn(listOf(fakeRepoInfo))
val oldShrinkedMappingFile = File(
fakeMappingFile.parent,
DdMappingFileUploadTask.MAPPING_OPTIMIZED_FILE_NAME
)
oldShrinkedMappingFile.createNewFile()
oldShrinkedMappingFile.writeText(forge.aString())

// When
testedTask.applyTask()

// Then
argumentCaptor<File> {
verify(mockUploader).upload(
eq(fakeSite),
capture(),
eq(fakeRepositoryFile),
eq(fakeApiKey.value),
eq(
DdAppIdentifier(
serviceName = fakeService,
version = fakeVersion,
variant = fakeVariant
)
),
eq(fakeRepoInfo),
useGzip = eq(true)
)
assertThat(lastValue.readLines()).isEqualTo(expectedLines)
}
}

@Test
fun `𝕄 upload file 𝕎 applyTask { remote url provided }`() {
// Given
Expand Down

0 comments on commit 148c985

Please sign in to comment.