diff --git a/packages/nextcloud/test/core_test.dart b/packages/nextcloud/test/core_test.dart index 0c874beb..dbe9954a 100644 --- a/packages/nextcloud/test/core_test.dart +++ b/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()); diff --git a/packages/nextcloud/test/dashboard_test.dart b/packages/nextcloud/test/dashboard_test.dart index ca18058a..97ba4f1a 100644 --- a/packages/nextcloud/test/dashboard_test.dart +++ b/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()); diff --git a/packages/nextcloud/test/helper.dart b/packages/nextcloud/test/helper.dart index 561494cb..20c93025 100644 --- a/packages/nextcloud/test/helper.dart +++ b/packages/nextcloud/test/helper.dart @@ -156,8 +156,24 @@ Future getTestClient( return client; } -Future getDockerContainer(final DockerImage image) async { - late ProcessResult result; +Future 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 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 getDockerContainer(final DockerImage image) async { ); } -typedef DockerImage = String; - -Future getDockerImage() async { - const dockerImageName = 'nextcloud-neon-dev'; - - final inputStream = StreamController>(); - 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, diff --git a/packages/nextcloud/test/news_test.dart b/packages/nextcloud/test/news_test.dart index ef2a8ec0..b3ef3fd1 100644 --- a/packages/nextcloud/test/news_test.dart +++ b/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()); diff --git a/packages/nextcloud/test/notes_test.dart b/packages/nextcloud/test/notes_test.dart index 1d49683e..bc80c6fb 100644 --- a/packages/nextcloud/test/notes_test.dart +++ b/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()); diff --git a/packages/nextcloud/test/notifications_test.dart b/packages/nextcloud/test/notifications_test.dart index 093423e3..0520bf84 100644 --- a/packages/nextcloud/test/notifications_test.dart +++ b/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', diff --git a/packages/nextcloud/test/provisioning_api_test.dart b/packages/nextcloud/test/provisioning_api_test.dart index 067b4446..6f175ced 100644 --- a/packages/nextcloud/test/provisioning_api_test.dart +++ b/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', diff --git a/packages/nextcloud/test/settings_test.dart b/packages/nextcloud/test/settings_test.dart index 4a60ef5c..9ad42508 100644 --- a/packages/nextcloud/test/settings_test.dart +++ b/packages/nextcloud/test/settings_test.dart @@ -5,29 +5,30 @@ import 'package:test/test.dart'; import 'helper.dart'; -Future main() async { - await run(await getDockerImage()); -} - -Future 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, + ); } diff --git a/packages/nextcloud/test/spreed_test.dart b/packages/nextcloud/test/spreed_test.dart index d9559464..2b88772e 100644 --- a/packages/nextcloud/test/spreed_test.dart +++ b/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()); diff --git a/packages/nextcloud/test/uppush_test.dart b/packages/nextcloud/test/uppush_test.dart index dd93f61f..2ecd3e7f 100644 --- a/packages/nextcloud/test/uppush_test.dart +++ b/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', diff --git a/packages/nextcloud/test/user_status_test.dart b/packages/nextcloud/test/user_status_test.dart index 279442dc..b53905f9 100644 --- a/packages/nextcloud/test/user_status_test.dart +++ b/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()); diff --git a/packages/nextcloud/test/webdav_test.dart b/packages/nextcloud/test/webdav_test.dart index bfc3eeea..523ddc40 100644 --- a/packages/nextcloud/test/webdav_test.dart +++ b/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());