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. 17
      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( group(
'core', 'core',
() { () {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());
late DockerContainer container; late DockerContainer container;
late TestNextcloudClient client; late TestNextcloudClient client;
setUp(() async { setUp(() async {
container = await getDockerContainer(image); container = await getDockerContainer();
client = await getTestClient(container); client = await getTestClient(container);
}); });
tearDown(() => container.destroy()); tearDown(() => container.destroy());

5
packages/nextcloud/test/dashboard_test.dart

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

51
packages/nextcloud/test/helper.dart

@ -156,8 +156,24 @@ Future<TestNextcloudClient> getTestClient(
return client; return client;
} }
Future<DockerContainer> getDockerContainer(final DockerImage image) async { Future<DockerContainer> getDockerContainer() async {
late ProcessResult result; 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; late int port;
while (true) { while (true) {
port = randomPort(); port = randomPort();
@ -171,7 +187,7 @@ Future<DockerContainer> getDockerContainer(final DockerImage image) async {
'host.docker.internal:host-gateway', 'host.docker.internal:host-gateway',
'-p', '-p',
'$port:80', '$port:80',
image, dockerImageName,
], ],
); );
// 125 means the docker run command itself has failed which indicated the port is already used // 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 { class TestNextcloudUser {
TestNextcloudUser( TestNextcloudUser(
this.username, this.username,

7
packages/nextcloud/test/news_test.dart

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

5
packages/nextcloud/test/notes_test.dart

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

10
packages/nextcloud/test/notifications_test.dart

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

5
packages/nextcloud/test/provisioning_api_test.dart

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

17
packages/nextcloud/test/settings_test.dart

@ -5,16 +5,14 @@ import 'package:test/test.dart';
import 'helper.dart'; import 'helper.dart';
Future<void> main() async { void main() {
await run(await getDockerImage()); group(
} 'settings',
() {
Future<void> run(final DockerImage image) async {
group('settings', () {
late DockerContainer container; late DockerContainer container;
late TestNextcloudClient client; late TestNextcloudClient client;
setUp(() async { setUp(() async {
container = await getDockerContainer(image); container = await getDockerContainer();
client = await getTestClient( client = await getTestClient(
container, container,
username: 'admin', username: 'admin',
@ -29,5 +27,8 @@ Future<void> run(final DockerImage image) async {
expect(logs, await container.nextcloudLogs()); expect(logs, await container.nextcloudLogs());
}); });
}); });
}); },
retry: retryCount,
timeout: timeout,
);
} }

5
packages/nextcloud/test/spreed_test.dart

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

5
packages/nextcloud/test/uppush_test.dart

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

5
packages/nextcloud/test/user_status_test.dart

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

5
packages/nextcloud/test/webdav_test.dart

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

Loading…
Cancel
Save