Browse Source

nextcloud: Add test for creating directory recursively

pull/28/head
jld3103 2 years ago
parent
commit
7951dc2639
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 9
      packages/nextcloud/lib/src/clients/custom/webdav/client.dart
  2. 9
      packages/nextcloud/test/webdav_test.dart

9
packages/nextcloud/lib/src/clients/custom/webdav/client.dart

@ -146,25 +146,28 @@ class WebDavClient {
}
/// just like mkdir -p
Future mkdirs(
Future<HttpClientResponse?> 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]

9
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();

Loading…
Cancel
Save