From 0d8aeeb180b7be40b211074e01a3dfb58adb389c Mon Sep 17 00:00:00 2001 From: jld3103 Date: Wed, 1 Nov 2023 09:46:42 +0100 Subject: [PATCH] refactor(tool,nextcloud): Use dev container to serve static test files Signed-off-by: jld3103 --- cspell.json | 2 +- packages/nextcloud/test/news_test.dart | 39 +++---------------- tool/Dockerfile.dev | 2 +- .../test/files => tool/dev/static}/nasa.xml | 0 .../files => tool/dev/static}/wikipedia.xml | 0 tool/overlay/.gitkeep | 0 6 files changed, 7 insertions(+), 36 deletions(-) rename {packages/nextcloud/test/files => tool/dev/static}/nasa.xml (100%) rename {packages/nextcloud/test/files => tool/dev/static}/wikipedia.xml (100%) delete mode 100644 tool/overlay/.gitkeep diff --git a/cspell.json b/cspell.json index 7dbd722e..13b05dd0 100644 --- a/cspell.json +++ b/cspell.json @@ -13,7 +13,7 @@ "external", "packages/file_icons/lib/src/data.dart", "packages/neon_lints/lib", - "packages/nextcloud/test/files" + "tool/dev/static" ], "dictionaries": [ "bash", diff --git a/packages/nextcloud/test/news_test.dart b/packages/nextcloud/test/news_test.dart index ece64797..ef2a8ec0 100644 --- a/packages/nextcloud/test/news_test.dart +++ b/packages/nextcloud/test/news_test.dart @@ -3,7 +3,6 @@ import 'dart:async'; import 'package:nextcloud/news.dart' as news; import 'package:nextcloud/nextcloud.dart'; import 'package:test/test.dart'; -import 'package:universal_io/io.dart'; import 'helper.dart'; @@ -12,12 +11,9 @@ void main() { 'news', () { late DockerImage image; - late HttpServer rssServer; setUpAll(() async { image = await getDockerImage(); - rssServer = await getRssServer(); }); - tearDownAll(() async => rssServer.close(force: true)); late DockerContainer container; late TestNextcloudClient client; @@ -29,12 +25,12 @@ void main() { Future> addWikipediaFeed([final int? folderID]) async => client.news.addFeed( - url: 'http://host.docker.internal:${rssServer.port}/wikipedia.xml', + url: 'http://localhost/static/wikipedia.xml', folderId: folderID, ); Future> addNasaFeed() async => client.news.addFeed( - url: 'http://host.docker.internal:${rssServer.port}/nasa.xml', + url: 'http://localhost/static/nasa.xml', ); test('Is supported', () async { @@ -58,7 +54,7 @@ void main() { expect(response.body.starredCount, null); expect(response.body.newestItemId, isNotNull); expect(response.body.feeds, hasLength(1)); - expect(response.body.feeds[0].url, 'http://host.docker.internal:${rssServer.port}/wikipedia.xml'); + expect(response.body.feeds[0].url, 'http://localhost/static/wikipedia.xml'); response = await client.news.listFeeds(); expect(response.statusCode, 200); @@ -67,7 +63,7 @@ void main() { expect(response.body.starredCount, 0); expect(response.body.newestItemId, isNotNull); expect(response.body.feeds, hasLength(1)); - expect(response.body.feeds[0].url, 'http://host.docker.internal:${rssServer.port}/wikipedia.xml'); + expect(response.body.feeds[0].url, 'http://localhost/static/wikipedia.xml'); }); test('Delete feed', () async { @@ -401,7 +397,7 @@ void main() { expect(response.body.newestItemId, isNotNull); expect(response.body.feeds, hasLength(1)); expect(response.body.feeds[0].folderId, 1); - expect(response.body.feeds[0].url, 'http://host.docker.internal:${rssServer.port}/wikipedia.xml'); + expect(response.body.feeds[0].url, 'http://localhost/static/wikipedia.xml'); }); test('Mark folder as read', () async { @@ -430,28 +426,3 @@ void main() { timeout: timeout, ); } - -Future getRssServer() async { - final wikipediaRss = File('test/files/wikipedia.xml').readAsStringSync(); - final nasaRss = File('test/files/nasa.xml').readAsStringSync(); - while (true) { - try { - final port = randomPort(); - final server = await HttpServer.bind(InternetAddress.anyIPv6, port); - unawaited( - server.forEach((final request) async { - switch (request.uri.path) { - case '/wikipedia.xml': - request.response.write(wikipediaRss); - case '/nasa.xml': - request.response.write(nasaRss); - default: - request.response.statusCode = HttpStatus.badRequest; - } - await request.response.close(); - }), - ); - return server; - } catch (_) {} - } -} diff --git a/tool/Dockerfile.dev b/tool/Dockerfile.dev index d44e6d1a..7f818d19 100644 --- a/tool/Dockerfile.dev +++ b/tool/Dockerfile.dev @@ -32,7 +32,7 @@ RUN (sh /entrypoint.sh php -S 0.0.0.0:80 &) && \ until curl -s -o /dev/null http://localhost/status.php; do true; done && \ # Do not setup the demo user here for user in admin user1 user2; do curl -u "$user:$user" -H "ocs-apirequest: true" -s -o /dev/null http://localhost/ocs/v2.php/cloud/user; done -COPY --chown=www-data:www-data overlay /usr/src/nextcloud/ +COPY --chown=www-data:www-data dev/static /usr/src/nextcloud/static ENV PHP_CLI_SERVER_WORKERS=10 CMD ["php", "-S", "0.0.0.0:80"] diff --git a/packages/nextcloud/test/files/nasa.xml b/tool/dev/static/nasa.xml similarity index 100% rename from packages/nextcloud/test/files/nasa.xml rename to tool/dev/static/nasa.xml diff --git a/packages/nextcloud/test/files/wikipedia.xml b/tool/dev/static/wikipedia.xml similarity index 100% rename from packages/nextcloud/test/files/wikipedia.xml rename to tool/dev/static/wikipedia.xml diff --git a/tool/overlay/.gitkeep b/tool/overlay/.gitkeep deleted file mode 100644 index e69de29b..00000000