From 3266e0fb023c5b740e8680d0e95496db87f4aac2 Mon Sep 17 00:00:00 2001 From: Shehab Mohamed Date: Sun, 1 Sep 2024 09:53:40 +0300 Subject: [PATCH] Add append download test with the new [DioFileMode] --- dio_test/lib/src/test/download_tests.dart | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/dio_test/lib/src/test/download_tests.dart b/dio_test/lib/src/test/download_tests.dart index f81e30a9c..660e8c9c9 100644 --- a/dio_test/lib/src/test/download_tests.dart +++ b/dio_test/lib/src/test/download_tests.dart @@ -380,6 +380,54 @@ void downloadTests( completes, ); }); + test('append bytes previous download', () async { + final cancelToken = CancelToken(); + final path = p.join(tmp.path, 'download_3.txt'); + final requestedBytes = 1024 * 1024 * 10; + var recievedBytes1 = 0; + await expectLater( + dio.download( + '/bytes/$requestedBytes', + path, + cancelToken: cancelToken, + onReceiveProgress: (c, t) { + if (c > 5000) { + recievedBytes1 = c; + cancelToken.cancel(); + } + }, + deleteOnError: false, + ), + throwsDioException( + DioExceptionType.cancel, + stackTraceContains: 'test/download_tests.dart', + ), + ); + + final cancelToken2 = CancelToken(); + var recievedBytes2 = 0; + expectLater( + dio.download( + '/bytes/$requestedBytes', + path, + cancelToken: cancelToken, + onReceiveProgress: (c, t) { + recievedBytes2 = c; + if (c > 5000) { + cancelToken2.cancel(); + } + }, + deleteOnError: false, + fileMode: DioFileMode.append, + ), + throwsDioException( + DioExceptionType.cancel, + stackTraceContains: 'test/download_tests.dart', + ), + ); + await Future.delayed(const Duration(milliseconds: 100), () {}); + expect(File(path).lengthSync(), recievedBytes1 + recievedBytes2); + }); }, testOn: 'vm', );