Skip to content

Commit

Permalink
Merge pull request #1315 from nextcloud/refactor/nextcloud_test/remov…
Browse files Browse the repository at this point in the history
…e-version-handling-mess
  • Loading branch information
provokateurin authored Dec 19, 2023
2 parents f357607 + 175c1c6 commit f67078f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 141 deletions.
2 changes: 1 addition & 1 deletion packages/nextcloud/test/dashboard_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void main() {
final items = response.body.ocs.data['recommendations']!.items;
expect(items, hasLength(7));
},
skip: preset.version.getRaw() < Version(27, 1, 0),
skip: preset.version < Version(27, 1, 0),
);
});
},
Expand Down
37 changes: 17 additions & 20 deletions packages/nextcloud_test/bin/generate_presets.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:nextcloud/core.dart' as core;
import 'package:nextcloud/nextcloud.dart';
import 'package:nextcloud_test/src/app.dart';
import 'package:nextcloud_test/src/extended_version.dart';
import 'package:universal_io/io.dart';
import 'package:version/version.dart';

Future<void> main() async {
const appIDs = [
Expand Down Expand Up @@ -43,7 +43,8 @@ Future<void> main() async {
}
}

File('${appPresetsDir.path}/${release.version.withoutPatch()}').writeAsStringSync(buffer.toString());
File('${appPresetsDir.path}/${release.version.major}.${release.version.minor}')
.writeAsStringSync(buffer.toString());
}
}

Expand All @@ -63,21 +64,21 @@ Future<void> main() async {
buffer.writeln('${app.id.toUpperCase()}_URL=${release.url}');
}

File('${serverPresetsDir.path}/${serverVersion.withoutPatch()}').writeAsStringSync(buffer.toString());
File('${serverPresetsDir.path}/${serverVersion.major}.${serverVersion.minor}').writeAsStringSync(buffer.toString());
}

final latestPresetLink = Link('docker/presets/latest');
if (latestPresetLink.existsSync()) {
latestPresetLink.updateSync('server/${serverVersions.first.withoutPatch()}');
latestPresetLink.updateSync('server/${serverVersions.first.major}.${serverVersions.first.minor}');
} else {
latestPresetLink.createSync('server/${serverVersions.first.withoutPatch()}');
latestPresetLink.createSync('server/${serverVersions.first.major}.${serverVersions.first.minor}');
}

httpClient.close(force: true);
}

Future<List<ExtendedVersion>> _getServerVersions(final HttpClient httpClient) async {
final versions = <ExtendedVersion, ExtendedVersion>{};
Future<List<Version>> _getServerVersions(final HttpClient httpClient) async {
final versions = <Version, Version>{};
String? next = 'https://hub.docker.com/v2/repositories/library/nextcloud/tags?page_size=1000';

while (next != null) {
Expand All @@ -96,14 +97,10 @@ Future<List<ExtendedVersion>> _getServerVersions(final HttpClient httpClient) as
try {
final tag = result as Map<String, dynamic>;

final version = ExtendedVersion.parse(tag['name'] as String);
if (version.minor == null || version.patch == null) {
continue;
}

final normalizedVersion = version.withoutPatch();
final version = Version.parse(tag['name'] as String);
final normalizedVersion = Version(version.major, version.minor, 0);

if (version < coreMinVersion || version.major > core.maxMajor) {
if (version < core.minVersion || version.major > core.maxMajor) {
continue;
}

Expand Down Expand Up @@ -138,22 +135,22 @@ Future<List<App>> _getApps(final List<String> appIDs, final HttpClient httpClien
continue;
}

final releases = <ExtendedVersion, AppRelease>{};
final releases = <Version, AppRelease>{};

final releasesItems = app['releases'] as List;
for (final releaseItem in releasesItems) {
final release = releaseItem as Map<String, dynamic>;

final version = ExtendedVersion.parse(release['version'] as String);
final normalizedVersion = version.withoutPatch();
final version = Version.parse(release['version'] as String);
final normalizedVersion = Version(version.major, version.minor, 0);

final rawPlatformVersionSpec = release['rawPlatformVersionSpec'] as String;
final minimumServerVersionRequirement =
ExtendedVersion.parse(rawPlatformVersionSpec.split(' ')[0].replaceFirst('>=', ''));
Version.parse(rawPlatformVersionSpec.split(' ')[0].replaceFirst('>=', ''));
final maximumServerVersionRequirement =
ExtendedVersion.parse(rawPlatformVersionSpec.split(' ')[1].replaceFirst('<=', ''));
Version.parse(rawPlatformVersionSpec.split(' ')[1].replaceFirst('<=', ''));

if (maximumServerVersionRequirement < coreMinVersion) {
if (maximumServerVersionRequirement < core.minVersion) {
continue;
}
if (minimumServerVersionRequirement.major > core.maxMajor) {
Expand Down
19 changes: 10 additions & 9 deletions packages/nextcloud_test/lib/src/app.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:meta/meta.dart';
import 'package:nextcloud_test/src/extended_version.dart';
import 'package:version/version.dart';

/// Describes a release of an [App] from https://apps.nextcloud.com
@internal
typedef AppRelease = ({
ExtendedVersion version,
Version version,
String url,
ExtendedVersion minimumServerVersion,
ExtendedVersion maximumServerVersion,
Version minimumServerVersion,
Version maximumServerVersion,
});

/// Describes an app from https://apps.nextcloud.com
Expand All @@ -19,13 +19,13 @@ typedef App = ({

@internal
extension AppFindLatestRelease on App {
AppRelease? findLatestCompatibleRelease(final ExtendedVersion serverVersion, {final bool allowUnstable = false}) {
AppRelease? findLatestCompatibleRelease(final Version serverVersion, {final bool allowUnstable = false}) {
final compatibleReleases = releases
.where(
(final release) =>
serverVersion >= release.minimumServerVersion &&
serverVersion <= release.maximumServerVersion &&
(allowUnstable || !release.version.getRaw().isPreRelease),
serverVersion < release.maximumServerVersion.incrementMajor() &&
(allowUnstable || !release.version.isPreRelease),
)
.toList()
..sort((final a, final b) => b.version.compareTo(a.version));
Expand All @@ -40,10 +40,11 @@ extension AppFindLatestRelease on App {

@internal
extension AppReleaseFindLatestServerVersion on AppRelease {
ExtendedVersion findLatestServerVersion(final List<ExtendedVersion> serverVersions) {
Version findLatestServerVersion(final List<Version> serverVersions) {
final compatibleReleases = serverVersions
.where(
(final serverVersion) => serverVersion >= minimumServerVersion && serverVersion <= maximumServerVersion,
(final serverVersion) =>
serverVersion >= minimumServerVersion && serverVersion < maximumServerVersion.incrementMajor(),
)
.toList()
..sort((final a, final b) => b.compareTo(a));
Expand Down
2 changes: 1 addition & 1 deletion packages/nextcloud_test/lib/src/docker_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DockerContainer {

/// Creates a new docker container and returns its representation.
static Future<DockerContainer> create(final Preset preset) async {
final dockerImageName = 'ghcr.io/nextcloud/neon/dev:${preset.name}-${preset.version}';
final dockerImageName = 'ghcr.io/nextcloud/neon/dev:${preset.name}-${preset.version.major}.${preset.version.minor}';

var result = await runExecutableArguments(
'docker',
Expand Down
103 changes: 0 additions & 103 deletions packages/nextcloud_test/lib/src/extended_version.dart

This file was deleted.

2 changes: 1 addition & 1 deletion packages/nextcloud_test/lib/src/fixtures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void validateFixture(final Preset preset) {

// Remove the groups that are the preset name and the preset version and the app is kept.
for (var i = 0; i <= 2; i++) {
if (groups[i] == preset.version.toString()) {
if (groups[i] == '${preset.version.major}.${preset.version.minor}') {
if (i == 1) {
// Remove preset version
groups.removeAt(1);
Expand Down
12 changes: 6 additions & 6 deletions packages/nextcloud_test/lib/src/presets.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'package:nextcloud/nextcloud.dart';
import 'package:nextcloud_test/nextcloud_test.dart';
import 'package:nextcloud_test/src/extended_version.dart';
import 'package:test/test.dart';
import 'package:universal_io/io.dart';
import 'package:version/version.dart';

/// Combination of preset `name` and preset `version`.
typedef Preset = ({String name, ExtendedVersion version});
typedef Preset = ({String name, Version version});

final Map<String, List<ExtendedVersion>> _presets = () {
final presets = <String, List<ExtendedVersion>>{};
final Map<String, List<Version>> _presets = () {
final presets = <String, List<Version>>{};

final presetGroups = Directory('../nextcloud_test/docker/presets')
.listSync(followLinks: false)
Expand All @@ -19,7 +19,7 @@ final Map<String, List<ExtendedVersion>> _presets = () {
final presetVersions = Directory('../nextcloud_test/docker/presets/$presetGroup')
.listSync(followLinks: false)
.whereType<File>()
.map((final f) => ExtendedVersion.parse(PathUri.parse(f.path).name));
.map((final f) => Version.parse(PathUri.parse(f.path).name));

presets[presetGroup] = presetVersions.toList();
}
Expand All @@ -41,7 +41,7 @@ void presets(

void innerBody() {
for (final presetVersion in _presets[presetGroup]!) {
group(presetVersion, () {
group('${presetVersion.major}.${presetVersion.minor}', () {
final preset = (name: presetGroup, version: presetVersion);

tearDown(() {
Expand Down

0 comments on commit f67078f

Please sign in to comment.