Test for free space and allow 0

This commit is contained in:
Torsten Grote 2024-10-22 14:04:19 -03:00
parent 0fa14025b3
commit f1224f09f8
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
5 changed files with 32 additions and 1 deletions

View file

@ -36,4 +36,9 @@ class SafBackendTest : BackendTest(), KoinComponent {
fun `test remove create write file`(): Unit = runBlocking {
testRemoveCreateWriteFile()
}
@Test
fun `test free space and create app blob without root folder`(): Unit = runBlocking {
testTestFreeSpaceAndCreateBlob()
}
}

View file

@ -115,6 +115,7 @@ class AppBackupWorker(
Log.e(TAG, "Error while running setForeground: ", e)
}
val freeSpace = backendManager.getFreeSpace()
Log.i(TAG, "freeSpace: $freeSpace")
if (freeSpace != null && freeSpace < MIN_FREE_SPACE) {
nm.onInsufficientSpaceError()
return Result.failure()

View file

@ -12,6 +12,7 @@ import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
@VisibleForTesting
public abstract class BackendTest {
@ -159,4 +160,23 @@ public abstract class BackendTest {
}
}
protected suspend fun testTestFreeSpaceAndCreateBlob() {
assertTrue(backend.test())
// not asserting free space as each backend may have different amounts available
println("Free space: ${backend.getFreeSpace()}")
val repoId = Random.nextBytes(32).toHexString()
val blob = AppBackupFileType.Blob(repoId, Random.nextBytes(32).toHexString())
val bytes = Random.nextBytes(2342)
try {
backend.save(blob).use {
it.write(bytes)
}
assertContentEquals(bytes, backend.load(blob as FileHandle).readAllBytes())
} finally {
backend.remove(blob)
}
}
}

View file

@ -111,7 +111,7 @@ public class WebDavBackend(
log.debugLog { "getFreeSpace() = $response" }
val quota = response.properties.getOrNull(0) as? QuotaAvailableBytes
val availableBytes = quota?.quotaAvailableBytes ?: -1
if (availableBytes > 0) {
if (availableBytes >= 0) {
cont.resume(availableBytes)
} else {
cont.resume(null)

View file

@ -22,4 +22,9 @@ public class WebDavBackendTest : BackendTest() {
public fun `test remove, create, write file`(): Unit = runBlocking {
testRemoveCreateWriteFile()
}
@Test
public fun `test, free space and create app blob without root folder`(): Unit = runBlocking {
testTestFreeSpaceAndCreateBlob()
}
}