Skip to content

Commit

Permalink
refactor(nextcloud_test): move test presets to a separate package
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolas Rimikis <[email protected]>
  • Loading branch information
Leptopoda committed Sep 1, 2024
1 parent 73c6008 commit e4f4029
Show file tree
Hide file tree
Showing 63 changed files with 116 additions and 68 deletions.
2 changes: 1 addition & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"packages/neon_framework/example/web/sqflite_sw.js",
"packages/neon_framework/example/web/sqlite3.wasm",
"packages/neon_lints/lib",
"packages/nextcloud/packages/nextcloud_test/docker/static",
"packages/nextcloud/packages/nextcloud_test_presets/docker/static",
"packages/nextcloud/test/files",
"packages/nextcloud/test/fixtures"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/nextcloud/doc/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ To run the tests against development versions follow these steps:

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

# Open a second terminal
cd /path/to/neon/packages/nextcloud
Expand Down
53 changes: 0 additions & 53 deletions packages/nextcloud/packages/nextcloud_test/lib/src/app.dart

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ final class DockerContainerFactory extends TestTargetFactory<DockerContainerInst

@override
BuiltListMultimap<String, Version> getPresets() {
final files = Glob('packages/nextcloud_test/docker/presets/**/*').listSync();
final files = Glob('packages/nextcloud_test_presets/docker/presets/**/*').listSync();

return BuiltListMultimap<String, Version>.build((b) {
for (final file in files) {
Expand Down
1 change: 1 addition & 0 deletions packages/nextcloud/packages/nextcloud_test_presets/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:neon_lints/dart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:nextcloud_test_presets/presets_builder.dart';

Future<void> main() async {
await generatePresets();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// Tools to generate the Nextcloud test presets.
library;

export 'src/generate_presets.dart';
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'dart:convert';
import 'dart:io' show Directory, File, Link;

import 'package:http/http.dart' as http;
import 'package:nextcloud/core.dart' as core;
import 'package:nextcloud_test/src/app.dart';
import 'package:universal_io/io.dart' show Directory, File, Link;
import 'package:version/version.dart';
import 'package:nextcloud_test_presets/src/models/models.dart';

Future<void> main() async {
/// Generates the test presets.
Future<void> generatePresets() async {
const appIDs = [
'cookbook',
'news',
Expand Down Expand Up @@ -169,7 +169,7 @@ Future<List<App>> _getApps(List<String> appIDs, http.Client httpClient) async {

final download = release['download'] as String;

final appRelease = (
final appRelease = AppRelease(
version: version,
url: download,
minimumServerVersion: minimumServerVersionRequirement,
Expand All @@ -184,7 +184,7 @@ Future<List<App>> _getApps(List<String> appIDs, http.Client httpClient) async {
}

apps.add(
(
App(
id: id,
releases: releases.values.toList(),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:meta/meta.dart';
import 'package:nextcloud_test_presets/src/models/models.dart';

/// Describes an app from https://apps.nextcloud.com
@internal
class App {
App({
required this.id,
required this.releases,
});

final String id;
final List<AppRelease> releases;

AppRelease? findLatestCompatibleRelease(Version serverVersion, {bool allowUnstable = false}) {
final compatibleReleases = releases
.where(
(release) =>
serverVersion >= release.minimumServerVersion &&
serverVersion < release.maximumServerVersion.incrementMajor() &&
(allowUnstable || !release.version.isPreRelease),
)
.toList()
..sort((a, b) => b.version.compareTo(a.version));
return compatibleReleases.firstOrNull;
}

AppRelease findLatestRelease() {
final sortedReleases = releases..sort((a, b) => b.version.compareTo(a.version));
return sortedReleases.first;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:meta/meta.dart';
import 'package:nextcloud_test_presets/src/models/models.dart';

/// Describes a release of an [App] from https://apps.nextcloud.com
@internal
class AppRelease {
const AppRelease({
required this.version,
required this.url,
required this.minimumServerVersion,
required this.maximumServerVersion,
});

final Version version;
final String url;
final Version minimumServerVersion;
final Version maximumServerVersion;

Version? findLatestServerVersion(List<Version> serverVersions) {
final compatibleReleases = serverVersions
.where(
(serverVersion) =>
serverVersion >= minimumServerVersion && serverVersion < maximumServerVersion.incrementMajor(),
)
.toList()
..sort((a, b) => b.compareTo(a));
return compatibleReleases.firstOrNull;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export 'package:version/version.dart';
export 'app.dart';
export 'app_release.dart';
18 changes: 18 additions & 0 deletions packages/nextcloud/packages/nextcloud_test_presets/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: nextcloud_test_presets
version: 1.0.0
publish_to: none

environment:
sdk: ^3.0.0

dependencies:
http: ^1.2.0
meta: ^1.0.0
nextcloud: ^7.0.0
version: ^3.0.0

dev_dependencies:
neon_lints:
git:
url: https://github.com/nextcloud/neon
path: packages/neon_lints
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# melos_managed_dependency_overrides: dynamite_runtime,neon_lints,nextcloud
dependency_overrides:
dynamite_runtime:
path: ../../../dynamite/packages/dynamite_runtime
neon_lints:
path: ../../../neon_lints
nextcloud:
path: ../..
4 changes: 2 additions & 2 deletions tool/build-dev-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cd "$(dirname "$0")/.."
source tool/common.sh

if [ "$#" -eq 0 ]; then
presets=(./packages/nextcloud/packages/nextcloud_test/docker/presets/*/*)
presets=(./packages/nextcloud/packages/nextcloud_test_presets/docker/presets/*/*)
else
presets=("$@")
fi
Expand All @@ -18,5 +18,5 @@ for preset in "${presets[@]}"; do
done < "$preset"

# shellcheck disable=SC2046,SC2086
docker buildx build --tag "$tag" $(cache_build_args "$tag") ${args[*]} -f - ./packages/nextcloud/packages/nextcloud_test/docker < packages/nextcloud/packages/nextcloud_test/docker/Dockerfile
docker buildx build --tag "$tag" $(cache_build_args "$tag") ${args[*]} -f - ./packages/nextcloud/packages/nextcloud_test_presets/docker < packages/nextcloud/packages/nextcloud_test_presets/docker/Dockerfile
done
2 changes: 1 addition & 1 deletion tool/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function cache_build_args() {
}

function preset_image_tag() {
path="$(realpath --relative-to ./packages/nextcloud/packages/nextcloud_test/docker/presets "$1")"
path="$(realpath --relative-to ./packages/nextcloud/packages/nextcloud_test_presets/docker/presets "$1")"
name="$(dirname "$path")"
version="$(basename "$path")"
image_tag "dev:$name-$version"
Expand Down
2 changes: 1 addition & 1 deletion tool/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source tool/common.sh
if [ "$#" -eq 1 ]; then
preset="$1"
else
preset="packages/nextcloud/packages/nextcloud_test/docker/presets/latest"
preset="packages/nextcloud/packages/nextcloud_test_presets/docker/presets/latest"
fi

./tool/build-dev-container.sh "$preset"
Expand Down
4 changes: 2 additions & 2 deletions tool/generate-nextcloud-test-presets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ set -euxo pipefail
cd "$(dirname "$0")/.."

(
cd packages/nextcloud/packages/nextcloud_test
fvm dart run nextcloud_test:generate_presets
cd packages/nextcloud/packages/nextcloud_test_presets
fvm dart run nextcloud_test_presets:generate_presets
)

0 comments on commit e4f4029

Please sign in to comment.