Skip to content

Commit

Permalink
Merge pull request #2323 from nextcloud/feat/nextcloud_test/local-tes…
Browse files Browse the repository at this point in the history
…ting
  • Loading branch information
provokateurin authored Jul 28, 2024
2 parents 918c99e + 3cbecec commit 297fb41
Show file tree
Hide file tree
Showing 54 changed files with 592 additions and 417 deletions.
2 changes: 1 addition & 1 deletion packages/neon_framework/lib/src/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class _HomePageState extends State<HomePage> {
final versionCheck = entry.value;
final appName = l10n.appImplementationName(entry.key);

buffer.writeln('- $appName >=${versionCheck.minimumVersion} <${versionCheck.maximumMajor + 1}.0.0');
buffer.writeln('- $appName >=${versionCheck.minimumVersion}');
}

final message = l10n.errorUnsupportedAppVersions(buffer.toString());
Expand Down
3 changes: 0 additions & 3 deletions packages/neon_framework/test/apps_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,11 @@ void main() {
final versionCheckCore = VersionCheck(
versions: BuiltList([Version(0, 0, 0)]),
minimumVersion: core.minVersion,
maximumMajor: core.maxMajor,
);

final versionCheck1 = VersionCheck(
versions: BuiltList([Version(2, 0, 0)]),
minimumVersion: Version(2, 0, 0),
maximumMajor: 2,
);

final appImplementation1 = MockAppImplementation();
Expand All @@ -346,7 +344,6 @@ void main() {
final versionCheck2 = VersionCheck(
versions: BuiltList([Version(1, 0, 0)]),
minimumVersion: Version(2, 0, 0),
maximumMajor: 2,
);

final appImplementation2 = MockAppImplementation();
Expand Down
5 changes: 0 additions & 5 deletions packages/nextcloud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ They can be accessed using getters on the `NextcloudClient`.

For an example checkout the [example](https://github.com/nextcloud/neon/blob/main/packages/nextcloud/example/example.dart).

## Development

Except for WebDAV all client code is generated using OpenAPI specifications which can be found in the `lib/src/api/` folder.
These OpenAPI specifications are [generated](https://github.com/nextcloud/openapi-extractor) from the PHP source code.

## Compatibility/Support policy

| Component | Supported versions (1) |
Expand Down
41 changes: 41 additions & 0 deletions packages/nextcloud/doc/development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Development

Except for WebDAV all client code is generated using OpenAPI specifications which can be found in the `lib/src/api/` folder.
These OpenAPI specifications are [generated](https://github.com/nextcloud/openapi-extractor) from the PHP source code.

## Checking test do not interfere with each other

All tests should be standalone and never affect any other tests.
With enough caution this is feasible to implement, but to verify the tests do not depend on the order of execution they should be run multiple times with different seeds:

```sh
for i in {0..4}; do fvm flutter test --test-randomize-ordering-seed $i; done
```

## Testing against development versions

Make sure to have the following apps in your server development setup and the appropriate versions you want to test checked out:

- https://codeberg.org/NextPush/uppush
- https://framagit.org/framasoft/nextcloud/drop_account
- https://github.com/nextcloud/cookbook
- https://github.com/nextcloud/news
- https://github.com/nextcloud/notes
- https://github.com/nextcloud/notifications
- https://github.com/nextcloud/password_policy
- https://github.com/nextcloud/spreed
- https://github.com/nextcloud/tables
- https://github.com/nextcloud/text

To run the tests against development versions follow these steps:

```sh
cd /path/to/server
/path/to/neon/packages/nextcloud_test/docker/local.sh

# Open a second terminal
cd /path/to/neon/packages/nextcloud
URL="http://localhost:8080" DIR="/path/to/server" fvm dart test --concurrency=1
```

Forcing the serial execution of all tests is necessary because the used SQLite database can be locked which results in tests blocking and failing other concurrent tests.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ extension CookbookVersionCheck on cookbook.$Client {
return VersionCheck(
versions: versions,
minimumVersion: minAppVersion,
maximumMajor: null,
);
}
}
5 changes: 0 additions & 5 deletions packages/nextcloud/lib/src/api/core/core_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import 'package:version/version.dart';
/// Minimum version of core/Server supported
final minVersion = Version(28, 0, 0);

/// Maximum major of core/Server supported
const maxMajor = 29;

/// Checks whether the server [version] is a dev, beta or RC version.
bool _isDevelopmentServerVersion(String version) {
return version.contains('dev') || version.contains('beta') || version.contains('RC');
Expand All @@ -29,7 +26,6 @@ extension CoreVersionCheck on core.$Client {
return VersionCheck(
versions: BuiltList([version]),
minimumVersion: minVersion,
maximumMajor: maxMajor,
isSupportedOverride: _isDevelopmentServerVersion(capabilities.version.string) ? true : null,
);
}
Expand All @@ -40,7 +36,6 @@ extension CoreStatusVersionCheck on core.Status {
VersionCheck get versionCheck => VersionCheck(
versions: BuiltList([Version.parse(version)]),
minimumVersion: minVersion,
maximumMajor: maxMajor,
isSupportedOverride: _isDevelopmentServerVersion(versionstring) ? true : null,
);
}
Expand Down
1 change: 0 additions & 1 deletion packages/nextcloud/lib/src/api/news/news_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ extension NewsVersionCheck on news.$Client {
return VersionCheck(
versions: versions?.map((version) => Version.parse(version.substring(1).replaceAll('-', '.'))).toBuiltList(),
minimumVersion: minVersion,
maximumMajor: null,
);
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/nextcloud/lib/src/api/notes/notes_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ extension NotesVersionCheck on notes.$Client {
return VersionCheck(
versions: versions?.map(Version.parse).toBuiltList(),
minimumVersion: minVersion,
maximumMajor: null,
);
}
}
4 changes: 0 additions & 4 deletions packages/nextcloud/lib/src/api/spreed/spreed_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import 'package:version/version.dart';
/// The minimum version of the spreed app that is supported.
final minVersion = Version(18, 0, 0);

/// Maximum major of spreed supported
const maxMajor = 19;

/// Extension for checking whether spreed is supported.
extension SpreedVersionCheck on spreed.$Client {
/// Checks whether the spreed app installed on the server is supported by this client.
Expand All @@ -20,7 +17,6 @@ extension SpreedVersionCheck on spreed.$Client {
return VersionCheck(
versions: version != null ? BuiltList([Version.parse(version)]) : null,
minimumVersion: minVersion,
maximumMajor: maxMajor,
);
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/nextcloud/lib/src/api/tables/tables_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ extension TablesVersionCheck on tables.$Client {
return VersionCheck(
versions: version != null ? BuiltList([Version.parse(version)]) : null,
minimumVersion: minAppVersion,
maximumMajor: null,
);
}
}
19 changes: 4 additions & 15 deletions packages/nextcloud/lib/src/models/version_check.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,26 @@ import 'package:built_collection/built_collection.dart';
import 'package:meta/meta.dart';
import 'package:version/version.dart';

/// Holds the [versions], [minimumVersion] and [maximumMajor] of an app.
/// Holds the [versions], [minimumVersion] of an app.
@immutable
class VersionCheck {
/// Creates a new [VersionCheck].
///
/// If the [maximumMajor] is `null` the compatibility of the major of the [minimumVersion] is checked.
const VersionCheck({
required this.versions,
required this.minimumVersion,
required int? maximumMajor,
bool? isSupportedOverride,
}) : _maximumMajor = maximumMajor,
_isSupportedOverride = isSupportedOverride;
}) : _isSupportedOverride = isSupportedOverride;

/// Current version of the app.
final BuiltList<Version>? versions;

/// Minimum version of the app.
final Version minimumVersion;

final int? _maximumMajor;

/// Maximum major version of the app.
int get maximumMajor => _maximumMajor ?? minimumVersion.major;

/// Overrides the check if the current version is supported.
final bool? _isSupportedOverride;

/// Whether the [versions] is allowed by the [minimumVersion] and [maximumMajor].
/// Whether the [versions] is allowed by the [minimumVersion].
///
/// If [versions] is `null` or empty it is assumed that the app is supported.
/// Only one of the [versions] has to be supported to return `true`.
Expand All @@ -44,7 +35,7 @@ class VersionCheck {
}

for (final version in versions!) {
if (version >= minimumVersion && version.major <= maximumMajor) {
if (version >= minimumVersion) {
return true;
}
}
Expand All @@ -57,14 +48,12 @@ class VersionCheck {
other is VersionCheck &&
other.versions == versions &&
other.minimumVersion == minimumVersion &&
other.maximumMajor == maximumMajor &&
other._isSupportedOverride == _isSupportedOverride;

@override
int get hashCode => Object.hashAll([
versions,
minimumVersion,
maximumMajor,
_isSupportedOverride,
]);
}
19 changes: 10 additions & 9 deletions packages/nextcloud/test/cookbook_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ import 'package:nextcloud_test/nextcloud_test.dart';
import 'package:test/test.dart';

void main() {
final targetFactory = TestTargetFactory.create();

presets(
targetFactory,
'cookbook',
'cookbook',
(preset) {
late DockerContainer container;
late TestTargetInstance target;
late NextcloudClient client;

setUp(() async {
container = await DockerContainer.create(preset);
client = await TestNextcloudClient.create(container);
setUpAll(() async {
target = await targetFactory.spawn(preset);
client = await target.createClient();
});

tearDown(() async {
await container.destroy();
tearDownAll(() async {
await target.destroy();
});

group('CookbookVersionCheck', () {
Expand Down Expand Up @@ -115,7 +116,7 @@ void main() {

group('recipes', () {
test('callImport', () async {
final url = cookbook.UrlBuilder()..url = 'http://localhost/static/recipe.html';
final url = cookbook.UrlBuilder()..url = '${target.targetURL}/static/recipe.html';
final response = await client.cookbook.recipes.$import($body: url.build());
addTearDown(() async {
closeFixture();
Expand Down
15 changes: 8 additions & 7 deletions packages/nextcloud/test/core_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ import 'package:nextcloud_test/nextcloud_test.dart';
import 'package:test/test.dart';

void main() {
final targetFactory = TestTargetFactory.create();

presets(
targetFactory,
'server',
'core',
(preset) {
late DockerContainer container;
late TestTargetInstance target;
late NextcloudClient client;
setUpAll(() async {
container = await DockerContainer.create(preset);
client = await TestNextcloudClient.create(container);
target = await targetFactory.spawn(preset);
client = await target.createClient();
});
tearDownAll(() async {
await container.destroy();
await target.destroy();
});

test('Is supported from capabilities', () async {
Expand Down Expand Up @@ -94,8 +97,6 @@ void main() {
containsAll([
'dashboard',
'files',
'photos',
'activity',
'spreed',
'notes',
'tables',
Expand Down Expand Up @@ -168,7 +169,7 @@ void main() {
group('App password', () {
test('Delete', () async {
// Separate client to not break other tests
final client = await TestNextcloudClient.create(container);
final client = await target.createClient();

await client.core.appPassword.deleteAppPassword();
await expectLater(
Expand Down
11 changes: 7 additions & 4 deletions packages/nextcloud/test/dashboard_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ import 'package:nextcloud_test/nextcloud_test.dart';
import 'package:test/test.dart';

void main() {
final targetFactory = TestTargetFactory.create();

presets(
targetFactory,
'server',
'dashboard',
(preset) {
late DockerContainer container;
late TestTargetInstance target;
late NextcloudClient client;
setUpAll(() async {
container = await DockerContainer.create(preset);
client = await TestNextcloudClient.create(container);
target = await targetFactory.spawn(preset);
client = await target.createClient();
});
tearDownAll(() async {
await container.destroy();
await target.destroy();
});

test('Get widgets', () async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ POST http://localhost/index\.php/apps/cookbook/api/v1/import
accept: application/json
authorization: Basic mock
content-type: application/json; charset=utf-8
\{"url":"http://localhost/static/recipe\.html"\}
\{"url":"http://.*/static/recipe\.html"\}
2 changes: 1 addition & 1 deletion packages/nextcloud/test/fixtures/news/add_feed.regexp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GET http://localhost/index\.php/apps/news/api/v1-3/feeds
accept: application/json
authorization: Basic mock
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml
accept: application/json
authorization: Basic mock
GET http://localhost/index\.php/apps/news/api/v1-3/feeds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
POST http://localhost/index\.php/apps/news/api/v1-3/folders\?name=test1
accept: application/json
authorization: Basic mock
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml&folderId=[0-9]+
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml&folderId=[0-9]+
accept: application/json
authorization: Basic mock
2 changes: 1 addition & 1 deletion packages/nextcloud/test/fixtures/news/delete_feed.regexp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml
accept: application/json
authorization: Basic mock
DELETE http://localhost/index\.php/apps/news/api/v1-3/feeds/[0-9]+
Expand Down
2 changes: 1 addition & 1 deletion packages/nextcloud/test/fixtures/news/list_articles.regexp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GET http://localhost/index\.php/apps/news/api/v1-3/items\?type=3&id=0&getRead=1&batchSize=-1&offset=0&oldestFirst=0
accept: application/json
authorization: Basic mock
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml
accept: application/json
authorization: Basic mock
GET http://localhost/index\.php/apps/news/api/v1-3/items\?type=3&id=0&getRead=1&batchSize=-1&offset=0&oldestFirst=0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml
accept: application/json
authorization: Basic mock
GET http://localhost/index\.php/apps/news/api/v1-3/items\?type=3&id=0&getRead=1&batchSize=-1&offset=0&oldestFirst=0
accept: application/json
authorization: Basic mock
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fnasa\.xml
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fnasa\.xml
accept: application/json
authorization: Basic mock
GET http://localhost/index\.php/apps/news/api/v1-3/items\?type=3&id=0&getRead=1&batchSize=-1&offset=0&oldestFirst=0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml
accept: application/json
authorization: Basic mock
GET http://localhost/index\.php/apps/news/api/v1-3/items\?type=6&id=0&getRead=1&batchSize=-1&offset=0&oldestFirst=0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml
accept: application/json
authorization: Basic mock
GET http://localhost/index\.php/apps/news/api/v1-3/items\?type=6&id=0&getRead=1&batchSize=-1&offset=0&oldestFirst=0
Expand Down
Loading

0 comments on commit 297fb41

Please sign in to comment.