Browse Source

refactor(nextcloud): Rely on prebuilt docker image for testing

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/1067/head
jld3103 1 year ago
parent
commit
eefcdf810f
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 5
      packages/nextcloud/test/core_test.dart
  2. 5
      packages/nextcloud/test/dashboard_test.dart
  3. 51
      packages/nextcloud/test/helper.dart
  4. 7
      packages/nextcloud/test/news_test.dart
  5. 5
      packages/nextcloud/test/notes_test.dart
  6. 10
      packages/nextcloud/test/notifications_test.dart
  7. 5
      packages/nextcloud/test/provisioning_api_test.dart
  8. 47
      packages/nextcloud/test/settings_test.dart
  9. 5
      packages/nextcloud/test/spreed_test.dart
  10. 5
      packages/nextcloud/test/uppush_test.dart
  11. 5
      packages/nextcloud/test/user_status_test.dart
  12. 5
      packages/nextcloud/test/webdav_test.dart

5
packages/nextcloud/test/core_test.dart

@ -8,13 +8,10 @@ void main() {
group(
'core',
() {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());
late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(container);
});
tearDown(() => container.destroy());

5
packages/nextcloud/test/dashboard_test.dart

@ -7,13 +7,10 @@ void main() {
group(
'dashboard',
() {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());
late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(container);
});
tearDown(() => container.destroy());

51
packages/nextcloud/test/helper.dart

@ -156,8 +156,24 @@ Future<TestNextcloudClient> getTestClient(
return client;
}
Future<DockerContainer> getDockerContainer(final DockerImage image) async {
late ProcessResult result;
Future<DockerContainer> getDockerContainer() async {
const dockerImageName = 'ghcr.io/nextcloud/neon/dev';
var result = await runExecutableArguments(
'docker',
[
'images',
'-q',
dockerImageName,
],
);
if (result.exitCode != 0) {
throw Exception('Querying docker image failed: ${result.stderr}');
}
if (result.stdout.toString().isEmpty) {
throw Exception('Missing docker image $dockerImageName. Please build it using ./tool/build-dev-container.sh');
}
late int port;
while (true) {
port = randomPort();
@ -171,7 +187,7 @@ Future<DockerContainer> getDockerContainer(final DockerImage image) async {
'host.docker.internal:host-gateway',
'-p',
'$port:80',
image,
dockerImageName,
],
);
// 125 means the docker run command itself has failed which indicated the port is already used
@ -190,35 +206,6 @@ Future<DockerContainer> getDockerContainer(final DockerImage image) async {
);
}
typedef DockerImage = String;
Future<DockerImage> getDockerImage() async {
const dockerImageName = 'nextcloud-neon-dev';
final inputStream = StreamController<List<int>>();
final process = runExecutableArguments(
'docker',
[
'build',
'-t',
dockerImageName,
'-f',
'-',
'../../tool',
],
stdin: inputStream.stream,
);
inputStream.add(utf8.encode(File('../../tool/Dockerfile.dev').readAsStringSync()));
await inputStream.close();
final result = await process;
if (result.exitCode != 0) {
throw Exception('Failed to build docker image');
}
return dockerImageName;
}
class TestNextcloudUser {
TestNextcloudUser(
this.username,

7
packages/nextcloud/test/news_test.dart

@ -10,15 +10,10 @@ void main() {
group(
'news',
() {
late DockerImage image;
setUpAll(() async {
image = await getDockerImage();
});
late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(container);
});
tearDown(() => container.destroy());

5
packages/nextcloud/test/notes_test.dart

@ -9,13 +9,10 @@ void main() {
group(
'notes',
() {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());
late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(container);
});
tearDown(() => container.destroy());

10
packages/nextcloud/test/notifications_test.dart

@ -7,13 +7,10 @@ import 'helper.dart';
void main() {
group('notifications', () {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());
late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(
container,
username: 'admin',
@ -103,13 +100,10 @@ void main() {
});
group('Push', () {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());
late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(
container,
username: 'admin',

5
packages/nextcloud/test/provisioning_api_test.dart

@ -7,13 +7,10 @@ void main() {
group(
'provisioning_api',
() {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());
late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(
container,
username: 'admin',

47
packages/nextcloud/test/settings_test.dart

@ -5,29 +5,30 @@ import 'package:test/test.dart';
import 'helper.dart';
Future<void> main() async {
await run(await getDockerImage());
}
Future<void> run(final DockerImage image) async {
group('settings', () {
late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
client = await getTestClient(
container,
username: 'admin',
);
});
tearDown(() => container.destroy());
void main() {
group(
'settings',
() {
late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer();
client = await getTestClient(
container,
username: 'admin',
);
});
tearDown(() => container.destroy());
group('Logs', () {
test('Download', () async {
final response = await client.settings.logSettings.download();
final logs = utf8.decode(response.body);
expect(logs, await container.nextcloudLogs());
group('Logs', () {
test('Download', () async {
final response = await client.settings.logSettings.download();
final logs = utf8.decode(response.body);
expect(logs, await container.nextcloudLogs());
});
});
});
});
},
retry: retryCount,
timeout: timeout,
);
}

5
packages/nextcloud/test/spreed_test.dart

@ -12,13 +12,10 @@ void main() {
group(
'spreed',
() {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());
late DockerContainer container;
late TestNextcloudClient client1;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client1 = await getTestClient(container);
});
tearDown(() => container.destroy());

5
packages/nextcloud/test/uppush_test.dart

@ -7,13 +7,10 @@ void main() {
group(
'uppush',
() {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());
late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(
container,
username: 'admin',

5
packages/nextcloud/test/user_status_test.dart

@ -7,13 +7,10 @@ void main() {
group(
'user_status',
() {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());
late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(container);
});
tearDown(() => container.destroy());

5
packages/nextcloud/test/webdav_test.dart

@ -26,14 +26,11 @@ void main() {
group(
'webdav',
() {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());
late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(container);
});
tearDown(() => container.destroy());

Loading…
Cancel
Save