Skip to content

Commit 3578752

Browse files
committed
feat: add TUS integration tests for upload lifecycle, creation with upload, and error handling.
1 parent 1d8bf67 commit 3578752

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

opencloudComLibrary/src/test/java/eu/opencloud/android/lib/resources/files/tus/TusIntegrationTest.kt

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import eu.opencloud.android.lib.common.accounts.AccountUtils
1010
import eu.opencloud.android.lib.common.authentication.OpenCloudCredentialsFactory
1111
import eu.opencloud.android.lib.common.operations.RemoteOperationResult
1212
import eu.opencloud.android.lib.resources.files.tus.CreateTusUploadRemoteOperation.Base64Encoder
13+
import okhttp3.mockwebserver.Dispatcher
1314
import okhttp3.mockwebserver.MockResponse
1415
import okhttp3.mockwebserver.MockWebServer
16+
import okhttp3.mockwebserver.RecordedRequest
1517
import org.junit.After
1618
import org.junit.Assert.*
1719
import org.junit.Before
@@ -190,13 +192,27 @@ class TusIntegrationTest {
190192
val firstChunkSize = 50L
191193

192194
// POST Create with Upload -> 201 + Location + Upload-Offset
193-
server.enqueue(
194-
MockResponse()
195-
.setResponseCode(201)
196-
.addHeader("Tus-Resumable", "1.0.0")
197-
.addHeader("Location", locationPath)
198-
.addHeader("Upload-Offset", firstChunkSize.toString())
199-
)
195+
server.dispatcher = object : Dispatcher() {
196+
override fun dispatch(request: RecordedRequest): MockResponse {
197+
if (request.path == collectionPath) {
198+
// Verify body content
199+
val bodySize = request.bodySize
200+
assertEquals(firstChunkSize, bodySize)
201+
202+
// Verify body bytes (first 50 bytes of the file)
203+
val expectedBytes = ByteArray(firstChunkSize.toInt()) { it.toByte() }
204+
val actualBytes = request.body.readByteArray()
205+
assertArrayEquals(expectedBytes, actualBytes)
206+
207+
return MockResponse()
208+
.setResponseCode(201)
209+
.addHeader("Tus-Resumable", "1.0.0")
210+
.addHeader("Location", locationPath)
211+
.addHeader("Upload-Offset", bodySize.toString())
212+
}
213+
return MockResponse().setResponseCode(404)
214+
}
215+
}
200216

201217
val create = CreateTusUploadRemoteOperation(
202218
file = localFile,

0 commit comments

Comments
 (0)