-
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.
refactor(nextcloud_test,nextcloud): run tests on web
Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
- Loading branch information
Showing
68 changed files
with
2,105 additions
and
376 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
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,16 @@ | ||
platforms: | ||
- vm | ||
- chrome | ||
|
||
define_platforms: | ||
chromium: | ||
name: Chromium | ||
extends: chrome | ||
settings: | ||
executable: chromium | ||
|
||
override_platforms: | ||
chrome: | ||
settings: | ||
arguments: --disable-web-security | ||
executable: chromium |
9 changes: 7 additions & 2 deletions
9
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,7 @@ | ||
export 'src/fixtures.dart' hide appendFixture, validateFixture; | ||
export 'src/presets.dart'; | ||
/// Nextcloud test library. | ||
/// | ||
/// Handles the server setup and allows to run tests against different test presets. | ||
/// All http requests of a test will be validated against predefined fixtures. | ||
library; | ||
|
||
export 'src/nextcloud_test.dart' show NextcloudTester, NextcloudTesterCallback, closeFixture, presets, resetFixture; |
2 changes: 0 additions & 2 deletions
2
packages/nextcloud/packages/nextcloud_test/lib/src/models/models.dart
This file was deleted.
Oops, something went wrong.
74 changes: 0 additions & 74 deletions
74
packages/nextcloud/packages/nextcloud_test/lib/src/models/nextcloud_tester.dart
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
packages/nextcloud/packages/nextcloud_test/lib/src/models/preset.dart
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
packages/nextcloud/packages/nextcloud_test/lib/src/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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export 'nextcloud_test/fixture_interceptor.dart'; | ||
export 'nextcloud_test/fixtures.dart'; | ||
export 'nextcloud_test/nextcloud_tester.dart'; | ||
export 'nextcloud_test/presets.dart'; |
File renamed without changes.
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
98 changes: 98 additions & 0 deletions
98
packages/nextcloud/packages/nextcloud_test/lib/src/nextcloud_test/nextcloud_tester.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,98 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:built_collection/built_collection.dart'; | ||
import 'package:cookie_store/cookie_store.dart'; | ||
import 'package:http/http.dart' as http; | ||
import 'package:interceptor_http_client/interceptor_http_client.dart'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:nextcloud/nextcloud.dart'; | ||
import 'package:nextcloud_test/src/nextcloud_test.dart'; | ||
import 'package:nextcloud_test_api/client.dart'; | ||
|
||
/// The shared base http client. | ||
/// | ||
/// Both the nextcloud communication and the communication to the test manager | ||
/// are handled through this client. | ||
@internal | ||
final http.Client httpClient = http.Client(); | ||
|
||
/// Class that manages the creation of nextcloud api clients and the test environment. | ||
final class NextcloudTester { | ||
/// Creates a new Nextcloud tester for the given [preset] with the initial [username]. | ||
NextcloudTester({ | ||
required NextcloudTestApiClient testClient, | ||
required Preset preset, | ||
required String username, | ||
}) : _preset = preset, | ||
_username = username, | ||
_testClient = testClient; | ||
|
||
Preset _preset; | ||
|
||
final String _username; | ||
|
||
final NextcloudTestApiClient _testClient; | ||
|
||
late Uri _hostURL; | ||
|
||
/// URL where the target is available from itself. | ||
late Uri targetURL; | ||
|
||
/// The Nextcloud api client for the default user. | ||
/// | ||
/// Use [createClient] to create a separate one. | ||
late NextcloudClient client; | ||
|
||
/// The app version tested. | ||
Version get version => _preset.version; | ||
|
||
/// Creates a new [NextcloudClient] for a given [username]. | ||
/// | ||
/// It is expected that the password of the user matches its [username]. | ||
Future<NextcloudClient> createClient({String username = 'user1'}) async { | ||
final appPassword = await _testClient.createAppPassword( | ||
preset: _preset, | ||
username: username, | ||
); | ||
|
||
final interceptedClient = InterceptorHttpClient( | ||
baseClient: httpClient, | ||
interceptors: BuiltList([ | ||
CookieStoreInterceptor( | ||
cookieStore: CookieStore(), | ||
), | ||
const FixtureInterceptor(appendFixture: appendFixture), | ||
]), | ||
); | ||
|
||
return NextcloudClient( | ||
_hostURL, | ||
loginName: username, | ||
password: username, | ||
appPassword: appPassword, | ||
httpClient: interceptedClient, | ||
); | ||
} | ||
|
||
/// Initializes the tester creating the target and default client. | ||
Future<void> init(String platform) async { | ||
_preset = _preset.rebuild((b) { | ||
b.platform = platform; | ||
}); | ||
|
||
final response = await _testClient.setup( | ||
preset: _preset, | ||
); | ||
_hostURL = response.hostURL; | ||
targetURL = response.targetURL; | ||
|
||
client = await createClient(username: _username); | ||
} | ||
|
||
/// Closes the tester. | ||
Future<void> close() async { | ||
await _testClient.tearDown( | ||
preset: _preset, | ||
); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
packages/nextcloud/packages/nextcloud_test/lib/src/nextcloud_test/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:meta/meta.dart'; | ||
import 'package:nextcloud_test/src/nextcloud_test.dart'; | ||
import 'package:nextcloud_test_api/client.dart'; | ||
import 'package:test/test.dart'; | ||
// ignore: implementation_imports | ||
import 'package:test_api/src/backend/invoker.dart'; | ||
|
||
/// Signature for callback to [presets]. | ||
typedef NextcloudTesterCallback = void Function(NextcloudTester tester); | ||
|
||
final _testClient = NextcloudTestApiClient.localhost( | ||
httpClient: httpClient, | ||
); | ||
|
||
/// All tests for apps that depend on the server version must be wrapped with this method and pass along the preset. | ||
@isTestGroup | ||
Future<void> presets( | ||
String presetGroup, | ||
String app, | ||
NextcloudTesterCallback body, { | ||
String username = defaultTestUsername, | ||
String? testOn, | ||
Timeout? timeout, | ||
Object? skip, | ||
Object? tags, | ||
Map<String, dynamic>? onPlatform, | ||
int? retry, | ||
}) async { | ||
final response = await _testClient.getPresets(group: presetGroup); | ||
final presets = response.presets; | ||
|
||
if (presets.isEmpty) { | ||
throw Exception('Unknown preset type "$presetGroup"'); | ||
} | ||
|
||
group( | ||
presetGroup, | ||
() { | ||
void innerBody() { | ||
for (final version in presets) { | ||
group('${version.major}.${version.minor}', () { | ||
final preset = Preset((b) { | ||
b | ||
..groupName = presetGroup | ||
..appName = app | ||
..version = version; | ||
}); | ||
|
||
final tester = NextcloudTester( | ||
preset: preset, | ||
username: username, | ||
testClient: _testClient, | ||
); | ||
|
||
setUpAll(() async { | ||
final platform = jsonEncode( | ||
Invoker.current!.liveTest.suite.platform.serialize(), | ||
); | ||
|
||
await tester.init(platform); | ||
}); | ||
|
||
tearDownAll(() async { | ||
await tester.close(); | ||
}); | ||
|
||
tearDown(() async { | ||
await validateFixture(_testClient, preset); | ||
}); | ||
|
||
body(tester); | ||
}); | ||
} | ||
} | ||
|
||
if (app != presetGroup) { | ||
group(app, innerBody); | ||
} else { | ||
innerBody(); | ||
} | ||
}, | ||
testOn: testOn, | ||
timeout: timeout, | ||
skip: skip, | ||
tags: tags, | ||
onPlatform: onPlatform, | ||
retry: retry, | ||
); | ||
} |
Oops, something went wrong.