-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2558 from nextcloud/test/nextcloud/all-props-parsed
- Loading branch information
Showing
8 changed files
with
406 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ requesttoken | |
reshares | ||
resharing | ||
rgdnvw | ||
rgdnvck | ||
roomid | ||
rowocs | ||
setsip | ||
|
2 changes: 2 additions & 0 deletions
2
packages/nextcloud/packages/nextcloud_test/lib/nextcloud_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export 'src/fixtures.dart' hide appendFixture; | ||
export 'src/matchers/webdav_props.dart'; | ||
export 'src/models/nextcloud_tester.dart'; | ||
export 'src/presets.dart'; |
72 changes: 72 additions & 0 deletions
72
packages/nextcloud/packages/nextcloud_test/lib/src/matchers/webdav_props.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import 'package:built_collection/built_collection.dart'; | ||
import 'package:collection/collection.dart'; | ||
import 'package:http/http.dart' as http; | ||
// ignore: implementation_imports | ||
import 'package:matcher/src/expect/async_matcher.dart'; | ||
import 'package:nextcloud/webdav.dart'; | ||
import 'package:nextcloud_test/src/models/models.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:xml/xml.dart'; | ||
|
||
class _ContainsAllAvailableProps extends AsyncMatcher { | ||
_ContainsAllAvailableProps( | ||
this.tester, | ||
this.uri, | ||
); | ||
|
||
final NextcloudTester tester; | ||
final PathUri uri; | ||
|
||
@override | ||
Description describe(Description description) { | ||
return description; | ||
} | ||
|
||
@override | ||
Future<String?> matchAsync(dynamic item) async { | ||
if (item is! XmlElement) { | ||
return 'Expected XmlElement, got ${item.runtimeType}.'; | ||
} | ||
|
||
final parsedProps = _getMultistatusPropNames(item); | ||
if (parsedProps.isEmpty) { | ||
return 'Parsed props were empty'; | ||
} | ||
|
||
final streamedResponse = await tester.client.webdav.httpClient.send(tester.client.webdav.propfind_Request(uri)); | ||
if (streamedResponse.statusCode != 207) { | ||
return 'PROPFIND response status code was not 207'; | ||
} | ||
final rawResponse = await http.Response.fromStream(streamedResponse); | ||
|
||
final expectedProps = _getMultistatusPropNames(XmlDocument.parse(rawResponse.body).rootElement); | ||
if (expectedProps.isEmpty) { | ||
return 'Expected props were empty'; | ||
} | ||
|
||
if (parsedProps != expectedProps) { | ||
return 'Missing props: ${expectedProps.where((p) => !parsedProps.contains(p)).join(', ')}'; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
BuiltList<String> _getMultistatusPropNames(XmlElement root) { | ||
return root.firstElementChild!.childElements | ||
.singleWhere( | ||
(node) => | ||
node.name.local == 'propstat' && | ||
node.childElements.singleWhere((node) => node.name.local == 'status').innerText.contains('200 OK'), | ||
) | ||
.childElements | ||
.singleWhere((node) => node.name.local == 'prop') | ||
.childElements | ||
.map((el) => '{${el.name.namespaceUri}}${el.name.local}') | ||
.toList() | ||
.sorted() | ||
.toBuiltList(); | ||
} | ||
} | ||
|
||
/// Checks that all props have been parsed, by comparing them to a raw PROPFIND response of a request to [uri]. | ||
Matcher containsAllAvailableProps(NextcloudTester tester, PathUri uri) => _ContainsAllAvailableProps(tester, uri); |
1 change: 0 additions & 1 deletion
1
packages/nextcloud/packages/nextcloud_test/lib/src/presets.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.