[db] Catch NotFoundException in RepoAdder

This commit is contained in:
Torsten Grote
2023-08-24 17:07:53 +02:00
committed by Michael Pöhn
parent b5c8f2c92c
commit 7b52db331c
2 changed files with 52 additions and 0 deletions

View File

@@ -177,6 +177,10 @@ internal class RepoAdder(
log.error(e) { "Error fetching repo." }
addRepoState.value = AddRepoError(INVALID_INDEX, e)
return
} catch (e: NotFoundException) { // v1 repos can also have 404
log.error(e) { "Error fetching repo." }
addRepoState.value = AddRepoError(INVALID_INDEX, e)
return
}
// set final result
val finalRepo = receivedRepo

View File

@@ -559,6 +559,54 @@ internal class RepoAdderTest {
assertEquals(63, addRepoState.apps.size)
}
@Test
fun testDownloadV1ThrowsNotFoundException() = runTest {
val url = "https://example.org/repo"
val jarFile = folder.newFile()
every { tempFileProvider.createTempFile() } returns jarFile
every {
downloaderFactory.create(
repo = match { it.address == url && it.formatVersion == IndexFormatVersion.TWO },
uri = Uri.parse("$url/entry.jar"),
indexFile = any(),
destFile = jarFile,
)
} returns downloader
every { downloader.download() } throws NotFoundException()
every {
downloaderFactory.create(
repo = match { it.address == url && it.formatVersion == IndexFormatVersion.ONE },
uri = Uri.parse("$url/index-v1.jar"),
indexFile = any(),
destFile = jarFile,
)
} returns downloader
every { downloader.download() } throws NotFoundException()
repoAdder.addRepoState.test {
assertIs<None>(awaitItem())
repoAdder.fetchRepository(
url = url,
username = null,
password = null,
proxy = null
)
val state1 = awaitItem()
assertIs<Fetching>(state1)
assertNull(state1.repo)
assertTrue(state1.apps.isEmpty())
assertFalse(state1.canAdd)
val state2 = awaitItem()
assertTrue(state2 is AddRepoError, "$state2")
assertEquals(INVALID_INDEX, state2.errorType)
}
}
private fun expectDownloadOfMinRepo(url: String) {
val urlTrimmed = url.trimEnd('/')
val jarFile = folder.newFile()