From 1aa6b304c0ea83887df0140bbf2f45e34cace136 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sat, 15 Jul 2023 19:26:39 +0200 Subject: [PATCH] feat(nextcloud): Allow using apache as web server for tests --- packages/nextcloud/test/helper.dart | 16 ++++++++++------ packages/nextcloud/test/news_test.dart | 10 +++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/nextcloud/test/helper.dart b/packages/nextcloud/test/helper.dart index f369abcf..19f01fe7 100644 --- a/packages/nextcloud/test/helper.dart +++ b/packages/nextcloud/test/helper.dart @@ -144,7 +144,7 @@ Future getTestClient( return client; } -Future getDockerContainer(final DockerImage image) async { +Future getDockerContainer(final DockerImage image, {final bool useApache = false}) async { late ProcessResult result; late int port; while (true) { @@ -155,12 +155,16 @@ Future getDockerContainer(final DockerImage image) async { 'run', '--rm', '-d', - '--net', - 'host', + '--add-host', + 'host.docker.internal:host-gateway', + '-p', + '$port:80', image, - 'php', - '-S', - '0.0.0.0:$port', + if (!useApache) ...[ + 'php', + '-S', + '0.0.0.0:80', + ], ], ); // 125 means the docker run command itself has failed which indicated the port is already used diff --git a/packages/nextcloud/test/news_test.dart b/packages/nextcloud/test/news_test.dart index 96b9b634..abf27e0b 100644 --- a/packages/nextcloud/test/news_test.dart +++ b/packages/nextcloud/test/news_test.dart @@ -25,12 +25,12 @@ Future run(final DockerImage image) async { tearDown(() => container.destroy()); Future addWikipediaFeed([final int? folderID]) => client.news.addFeed( - url: 'http://localhost:${rssServer.port}/wikipedia.xml', + url: 'http://host.docker.internal:${rssServer.port}/wikipedia.xml', folderId: folderID, ); Future addNasaFeed() => client.news.addFeed( - url: 'http://localhost:${rssServer.port}/nasa.xml', + url: 'http://host.docker.internal:${rssServer.port}/nasa.xml', ); test('Is supported', () async { @@ -48,13 +48,13 @@ Future run(final DockerImage image) async { expect(response.starredCount, null); expect(response.newestItemId, isNotNull); expect(response.feeds, hasLength(1)); - expect(response.feeds[0].url, 'http://localhost:${rssServer.port}/wikipedia.xml'); + expect(response.feeds[0].url, 'http://host.docker.internal:${rssServer.port}/wikipedia.xml'); response = await client.news.listFeeds(); expect(response.starredCount, 0); expect(response.newestItemId, isNotNull); expect(response.feeds, hasLength(1)); - expect(response.feeds[0].url, 'http://localhost:${rssServer.port}/wikipedia.xml'); + expect(response.feeds[0].url, 'http://host.docker.internal:${rssServer.port}/wikipedia.xml'); }); test('Rename feed', () async { @@ -247,7 +247,7 @@ Future run(final DockerImage image) async { expect(response.newestItemId, isNotNull); expect(response.feeds, hasLength(1)); expect(response.feeds[0].folderId, 1); - expect(response.feeds[0].url, 'http://localhost:${rssServer.port}/wikipedia.xml'); + expect(response.feeds[0].url, 'http://host.docker.internal:${rssServer.port}/wikipedia.xml'); }); test('Mark folder as read', () async {