From 7951dc263975e000b83ddb1d703d8cbfaead1180 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Thu, 21 Jul 2022 12:01:41 +0200 Subject: [PATCH] nextcloud: Add test for creating directory recursively --- .../nextcloud/lib/src/clients/custom/webdav/client.dart | 9 ++++++--- packages/nextcloud/test/webdav_test.dart | 9 +++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/nextcloud/lib/src/clients/custom/webdav/client.dart b/packages/nextcloud/lib/src/clients/custom/webdav/client.dart index 00331144..00b1cafd 100644 --- a/packages/nextcloud/lib/src/clients/custom/webdav/client.dart +++ b/packages/nextcloud/lib/src/clients/custom/webdav/client.dart @@ -146,25 +146,28 @@ class WebDavClient { } /// just like mkdir -p - Future mkdirs( + Future mkdirs( final String remotePath, { final bool safe = true, }) async { final dirs = remotePath.trim().split('/')..removeWhere((final value) => value == ''); if (dirs.isEmpty) { - return; + return null; } if (remotePath.trim().startsWith('/')) { dirs[0] = '/${dirs[0]}'; } final prevPath = StringBuffer(); + late HttpClientResponse response; for (final dir in dirs) { - await mkdir( + response = await mkdir( '$prevPath/$dir', safe: safe, ); prevPath.write('/$dir'); } + + return response; } /// remove dir with given [path] diff --git a/packages/nextcloud/test/webdav_test.dart b/packages/nextcloud/test/webdav_test.dart index f6592a29..7b13bc40 100644 --- a/packages/nextcloud/test/webdav_test.dart +++ b/packages/nextcloud/test/webdav_test.dart @@ -52,6 +52,15 @@ Future main() async { expect(response.statusCode, equals(201)); }); + test('Create directory recursively', () async { + final response = await client.webdav.mkdirs('test/bla'); + expect(response!.statusCode, equals(201)); + + final files = await client.webdav.ls('/test'); + expect(files, hasLength(1)); + expect(files[0].path, '/test/bla/'); + }); + test('Upload files', () async { final pngBytes = File('test/files/test.png').readAsBytesSync(); final txtBytes = File('test/files/test.txt').readAsBytesSync();