diff --git a/packages/nextcloud/test/cookbook_test.dart b/packages/nextcloud/test/cookbook_test.dart index 5182b033c11..aa61c48ca45 100644 --- a/packages/nextcloud/test/cookbook_test.dart +++ b/packages/nextcloud/test/cookbook_test.dart @@ -6,20 +6,21 @@ import 'package:nextcloud_test/nextcloud_test.dart'; import 'package:test/test.dart'; void main() { + final targetFactory = TestTargetFactory.create(); + presets( + targetFactory, 'cookbook', 'cookbook', (preset) { - late DockerContainer container; + late TestTargetInstance target; late NextcloudClient client; - - setUp(() async { - container = await DockerContainer.create(preset); - client = await TestNextcloudClient.create(container); + setUpAll(() async { + target = await targetFactory.spawn(preset); + client = await target.createClient(); }); - - tearDown(() async { - await container.destroy(); + tearDownAll(() async { + await target.destroy(); }); group('CookbookVersionCheck', () { @@ -115,7 +116,7 @@ void main() { group('recipes', () { test('callImport', () async { - final url = cookbook.UrlBuilder()..url = 'http://localhost/static/recipe.html'; + final url = cookbook.UrlBuilder()..url = '${target.targetURL}/static/recipe.html'; final response = await client.cookbook.recipes.$import($body: url.build()); addTearDown(() async { closeFixture(); diff --git a/packages/nextcloud/test/core_test.dart b/packages/nextcloud/test/core_test.dart index 805ee457cf0..a4f3defb367 100644 --- a/packages/nextcloud/test/core_test.dart +++ b/packages/nextcloud/test/core_test.dart @@ -7,18 +7,21 @@ import 'package:nextcloud_test/nextcloud_test.dart'; import 'package:test/test.dart'; void main() { + final targetFactory = TestTargetFactory.create(); + presets( + targetFactory, 'server', 'core', (preset) { - late DockerContainer container; + late TestTargetInstance target; late NextcloudClient client; setUpAll(() async { - container = await DockerContainer.create(preset); - client = await TestNextcloudClient.create(container); + target = await targetFactory.spawn(preset); + client = await target.createClient(); }); tearDownAll(() async { - await container.destroy(); + await target.destroy(); }); test('Is supported from capabilities', () async { @@ -166,7 +169,7 @@ void main() { group('App password', () { test('Delete', () async { // Separate client to not break other tests - final client = await TestNextcloudClient.create(container); + final client = await target.createClient(); await client.core.appPassword.deleteAppPassword(); await expectLater( diff --git a/packages/nextcloud/test/dashboard_test.dart b/packages/nextcloud/test/dashboard_test.dart index 340458866c1..1690c85e9a3 100644 --- a/packages/nextcloud/test/dashboard_test.dart +++ b/packages/nextcloud/test/dashboard_test.dart @@ -4,18 +4,21 @@ import 'package:nextcloud_test/nextcloud_test.dart'; import 'package:test/test.dart'; void main() { + final targetFactory = TestTargetFactory.create(); + presets( + targetFactory, 'server', 'dashboard', (preset) { - late DockerContainer container; + late TestTargetInstance target; late NextcloudClient client; setUpAll(() async { - container = await DockerContainer.create(preset); - client = await TestNextcloudClient.create(container); + target = await targetFactory.spawn(preset); + client = await target.createClient(); }); tearDownAll(() async { - await container.destroy(); + await target.destroy(); }); test('Get widgets', () async { diff --git a/packages/nextcloud/test/fixtures/cookbook/recipes/callimport.regexp b/packages/nextcloud/test/fixtures/cookbook/recipes/callimport.regexp index 8c76767b471..f4af4cee37b 100644 --- a/packages/nextcloud/test/fixtures/cookbook/recipes/callimport.regexp +++ b/packages/nextcloud/test/fixtures/cookbook/recipes/callimport.regexp @@ -2,4 +2,4 @@ POST http://localhost/index\.php/apps/cookbook/api/v1/import accept: application/json authorization: Basic mock content-type: application/json; charset=utf-8 -\{"url":"http://localhost/static/recipe\.html"\} \ No newline at end of file +\{"url":"http://.*/static/recipe\.html"\} \ No newline at end of file diff --git a/packages/nextcloud/test/fixtures/news/add_feed.regexp b/packages/nextcloud/test/fixtures/news/add_feed.regexp index 0cec60895d4..a225ed7c358 100644 --- a/packages/nextcloud/test/fixtures/news/add_feed.regexp +++ b/packages/nextcloud/test/fixtures/news/add_feed.regexp @@ -1,7 +1,7 @@ GET http://localhost/index\.php/apps/news/api/v1-3/feeds accept: application/json authorization: Basic mock -POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml +POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml accept: application/json authorization: Basic mock GET http://localhost/index\.php/apps/news/api/v1-3/feeds diff --git a/packages/nextcloud/test/fixtures/news/add_feed_to_folder.regexp b/packages/nextcloud/test/fixtures/news/add_feed_to_folder.regexp index b3a5a4f8909..a0c4f11ee0e 100644 --- a/packages/nextcloud/test/fixtures/news/add_feed_to_folder.regexp +++ b/packages/nextcloud/test/fixtures/news/add_feed_to_folder.regexp @@ -1,6 +1,6 @@ POST http://localhost/index\.php/apps/news/api/v1-3/folders\?name=test1 accept: application/json authorization: Basic mock -POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml&folderId=[0-9]+ +POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml&folderId=[0-9]+ accept: application/json authorization: Basic mock \ No newline at end of file diff --git a/packages/nextcloud/test/fixtures/news/delete_feed.regexp b/packages/nextcloud/test/fixtures/news/delete_feed.regexp index 2a2cfc00598..1d2eb0d0d1d 100644 --- a/packages/nextcloud/test/fixtures/news/delete_feed.regexp +++ b/packages/nextcloud/test/fixtures/news/delete_feed.regexp @@ -1,4 +1,4 @@ -POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml +POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml accept: application/json authorization: Basic mock DELETE http://localhost/index\.php/apps/news/api/v1-3/feeds/[0-9]+ diff --git a/packages/nextcloud/test/fixtures/news/list_articles.regexp b/packages/nextcloud/test/fixtures/news/list_articles.regexp index ff990b31a97..9b98b67b713 100644 --- a/packages/nextcloud/test/fixtures/news/list_articles.regexp +++ b/packages/nextcloud/test/fixtures/news/list_articles.regexp @@ -1,7 +1,7 @@ GET http://localhost/index\.php/apps/news/api/v1-3/items\?type=3&id=0&getRead=1&batchSize=-1&offset=0&oldestFirst=0 accept: application/json authorization: Basic mock -POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml +POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml accept: application/json authorization: Basic mock GET http://localhost/index\.php/apps/news/api/v1-3/items\?type=3&id=0&getRead=1&batchSize=-1&offset=0&oldestFirst=0 diff --git a/packages/nextcloud/test/fixtures/news/list_updated_articles.regexp b/packages/nextcloud/test/fixtures/news/list_updated_articles.regexp index 1216d0fab46..948ff2c1659 100644 --- a/packages/nextcloud/test/fixtures/news/list_updated_articles.regexp +++ b/packages/nextcloud/test/fixtures/news/list_updated_articles.regexp @@ -1,10 +1,10 @@ -POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml +POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml accept: application/json authorization: Basic mock GET http://localhost/index\.php/apps/news/api/v1-3/items\?type=3&id=0&getRead=1&batchSize=-1&offset=0&oldestFirst=0 accept: application/json authorization: Basic mock -POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fnasa\.xml +POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fnasa\.xml accept: application/json authorization: Basic mock GET http://localhost/index\.php/apps/news/api/v1-3/items\?type=3&id=0&getRead=1&batchSize=-1&offset=0&oldestFirst=0 diff --git a/packages/nextcloud/test/fixtures/news/mark_article_as_read.regexp b/packages/nextcloud/test/fixtures/news/mark_article_as_read.regexp index 14305be4fad..83016b835a6 100644 --- a/packages/nextcloud/test/fixtures/news/mark_article_as_read.regexp +++ b/packages/nextcloud/test/fixtures/news/mark_article_as_read.regexp @@ -1,4 +1,4 @@ -POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml +POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml accept: application/json authorization: Basic mock GET http://localhost/index\.php/apps/news/api/v1-3/items\?type=6&id=0&getRead=1&batchSize=-1&offset=0&oldestFirst=0 diff --git a/packages/nextcloud/test/fixtures/news/mark_article_as_unread.regexp b/packages/nextcloud/test/fixtures/news/mark_article_as_unread.regexp index a84bf1938ed..a371d5ca861 100644 --- a/packages/nextcloud/test/fixtures/news/mark_article_as_unread.regexp +++ b/packages/nextcloud/test/fixtures/news/mark_article_as_unread.regexp @@ -1,4 +1,4 @@ -POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml +POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml accept: application/json authorization: Basic mock GET http://localhost/index\.php/apps/news/api/v1-3/items\?type=6&id=0&getRead=1&batchSize=-1&offset=0&oldestFirst=0 diff --git a/packages/nextcloud/test/fixtures/news/mark_feed_as_read.regexp b/packages/nextcloud/test/fixtures/news/mark_feed_as_read.regexp index 0177263bf8c..08792f8e845 100644 --- a/packages/nextcloud/test/fixtures/news/mark_feed_as_read.regexp +++ b/packages/nextcloud/test/fixtures/news/mark_feed_as_read.regexp @@ -1,4 +1,4 @@ -POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml +POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml accept: application/json authorization: Basic mock GET http://localhost/index\.php/apps/news/api/v1-3/items\?type=6&id=0&getRead=1&batchSize=-1&offset=0&oldestFirst=0 diff --git a/packages/nextcloud/test/fixtures/news/mark_folder_as_read.regexp b/packages/nextcloud/test/fixtures/news/mark_folder_as_read.regexp index 7dd03e9a2e1..5af621b1b06 100644 --- a/packages/nextcloud/test/fixtures/news/mark_folder_as_read.regexp +++ b/packages/nextcloud/test/fixtures/news/mark_folder_as_read.regexp @@ -1,7 +1,7 @@ POST http://localhost/index\.php/apps/news/api/v1-3/folders\?name=test1 accept: application/json authorization: Basic mock -POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml&folderId=[0-9]+ +POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml&folderId=[0-9]+ accept: application/json authorization: Basic mock GET http://localhost/index\.php/apps/news/api/v1-3/items\?type=6&id=0&getRead=1&batchSize=-1&offset=0&oldestFirst=0 diff --git a/packages/nextcloud/test/fixtures/news/move_feed_to_folder.regexp b/packages/nextcloud/test/fixtures/news/move_feed_to_folder.regexp index 484eb7d1c4a..8c52ff7dc20 100644 --- a/packages/nextcloud/test/fixtures/news/move_feed_to_folder.regexp +++ b/packages/nextcloud/test/fixtures/news/move_feed_to_folder.regexp @@ -1,7 +1,7 @@ POST http://localhost/index\.php/apps/news/api/v1-3/folders\?name=test1 accept: application/json authorization: Basic mock -POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml +POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml accept: application/json authorization: Basic mock POST http://localhost/index\.php/apps/news/api/v1-3/feeds/[0-9]+/move\?folderId=[0-9]+ diff --git a/packages/nextcloud/test/fixtures/news/rename_feed.regexp b/packages/nextcloud/test/fixtures/news/rename_feed.regexp index 6fd7c826f8c..e27ddcde29a 100644 --- a/packages/nextcloud/test/fixtures/news/rename_feed.regexp +++ b/packages/nextcloud/test/fixtures/news/rename_feed.regexp @@ -1,4 +1,4 @@ -POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml +POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml accept: application/json authorization: Basic mock POST http://localhost/index\.php/apps/news/api/v1-3/feeds/[0-9]+/rename\?feedTitle=test1 diff --git a/packages/nextcloud/test/fixtures/news/star_article.regexp b/packages/nextcloud/test/fixtures/news/star_article.regexp index 289f34c18aa..0cf3d50ce98 100644 --- a/packages/nextcloud/test/fixtures/news/star_article.regexp +++ b/packages/nextcloud/test/fixtures/news/star_article.regexp @@ -1,4 +1,4 @@ -POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml +POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml accept: application/json authorization: Basic mock GET http://localhost/index\.php/apps/news/api/v1-3/items\?type=2&id=0&getRead=1&batchSize=-1&offset=0&oldestFirst=0 diff --git a/packages/nextcloud/test/fixtures/news/unstar_article.regexp b/packages/nextcloud/test/fixtures/news/unstar_article.regexp index 758735e912a..b30d5d1dffb 100644 --- a/packages/nextcloud/test/fixtures/news/unstar_article.regexp +++ b/packages/nextcloud/test/fixtures/news/unstar_article.regexp @@ -1,4 +1,4 @@ -POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml +POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2F.*%2Fstatic%2Fwikipedia\.xml accept: application/json authorization: Basic mock GET http://localhost/index\.php/apps/news/api/v1-3/items\?type=3&id=0&getRead=1&batchSize=-1&offset=0&oldestFirst=0 diff --git a/packages/nextcloud/test/news_test.dart b/packages/nextcloud/test/news_test.dart index fb7c6ea056c..5df6f301833 100644 --- a/packages/nextcloud/test/news_test.dart +++ b/packages/nextcloud/test/news_test.dart @@ -6,18 +6,21 @@ import 'package:nextcloud_test/nextcloud_test.dart'; import 'package:test/test.dart'; void main() { + final targetFactory = TestTargetFactory.create(); + presets( + targetFactory, 'news', 'news', (preset) { - late DockerContainer container; + late TestTargetInstance target; late NextcloudClient client; setUpAll(() async { - container = await DockerContainer.create(preset); - client = await TestNextcloudClient.create(container); + target = await targetFactory.spawn(preset); + client = await target.createClient(); }); tearDownAll(() async { - await container.destroy(); + await target.destroy(); }); tearDown(() async { closeFixture(); @@ -34,12 +37,12 @@ void main() { }); Future> addWikipediaFeed([int? folderID]) async => client.news.addFeed( - url: 'http://localhost/static/wikipedia.xml', + url: '${target.targetURL}/static/wikipedia.xml', folderId: folderID, ); Future> addNasaFeed() async => client.news.addFeed( - url: 'http://localhost/static/nasa.xml', + url: '${target.targetURL}/static/nasa.xml', ); test('Is supported', () async { @@ -65,7 +68,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://localhost/static/wikipedia.xml'); + expect(response.body.feeds[0].url, '${target.targetURL}/static/wikipedia.xml'); response = await client.news.listFeeds(); expect(response.statusCode, 200); @@ -74,7 +77,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://localhost/static/wikipedia.xml'); + expect(response.body.feeds[0].url, '${target.targetURL}/static/wikipedia.xml'); }); test('Delete feed', () async { @@ -423,7 +426,7 @@ void main() { expect(response.body.newestItemId, isNotNull); expect(response.body.feeds, hasLength(1)); expect(response.body.feeds[0].folderId, isPositive); - expect(response.body.feeds[0].url, 'http://localhost/static/wikipedia.xml'); + expect(response.body.feeds[0].url, '${target.targetURL}/static/wikipedia.xml'); }); test('Mark folder as read', () async { diff --git a/packages/nextcloud/test/notes_test.dart b/packages/nextcloud/test/notes_test.dart index b3461d9aefd..8082ac64ea7 100644 --- a/packages/nextcloud/test/notes_test.dart +++ b/packages/nextcloud/test/notes_test.dart @@ -6,18 +6,21 @@ import 'package:nextcloud_test/nextcloud_test.dart'; import 'package:test/test.dart'; void main() { + final targetFactory = TestTargetFactory.create(); + presets( + targetFactory, 'notes', 'notes', (preset) { - late DockerContainer container; + late TestTargetInstance target; late NextcloudClient client; setUpAll(() async { - container = await DockerContainer.create(preset); - client = await TestNextcloudClient.create(container); + target = await targetFactory.spawn(preset); + client = await target.createClient(); }); tearDownAll(() async { - await container.destroy(); + await target.destroy(); }); tearDown(() async { closeFixture(); diff --git a/packages/nextcloud/test/notifications_test.dart b/packages/nextcloud/test/notifications_test.dart index 690f31dfa95..39615f2f41c 100644 --- a/packages/nextcloud/test/notifications_test.dart +++ b/packages/nextcloud/test/notifications_test.dart @@ -8,21 +8,23 @@ import 'package:nextcloud_test/nextcloud_test.dart'; import 'package:test/test.dart'; void main() { + final targetFactory = TestTargetFactory.create(); + presets( + targetFactory, 'server', 'notifications', (preset) { - late DockerContainer container; + late TestTargetInstance target; late NextcloudClient client; setUpAll(() async { - container = await DockerContainer.create(preset); - client = await TestNextcloudClient.create( - container, + target = await targetFactory.spawn(preset); + client = await target.createClient( username: 'admin', ); }); tearDownAll(() async { - await container.destroy(); + await target.destroy(); }); Future sendTestNotification() async { diff --git a/packages/nextcloud/test/provisioning_api_test.dart b/packages/nextcloud/test/provisioning_api_test.dart index c564f124006..5b209977bb4 100644 --- a/packages/nextcloud/test/provisioning_api_test.dart +++ b/packages/nextcloud/test/provisioning_api_test.dart @@ -5,21 +5,23 @@ import 'package:nextcloud_test/nextcloud_test.dart'; import 'package:test/test.dart'; void main() { + final targetFactory = TestTargetFactory.create(); + presets( + targetFactory, 'server', 'provisioning_api', (preset) { - late DockerContainer container; + late TestTargetInstance target; late NextcloudClient client; setUpAll(() async { - container = await DockerContainer.create(preset); - client = await TestNextcloudClient.create( - container, + target = await targetFactory.spawn(preset); + client = await target.createClient( username: 'admin', ); }); tearDownAll(() async { - await container.destroy(); + await target.destroy(); }); group('Users', () { diff --git a/packages/nextcloud/test/settings_test.dart b/packages/nextcloud/test/settings_test.dart index 0967cfb88bd..e119974f647 100644 --- a/packages/nextcloud/test/settings_test.dart +++ b/packages/nextcloud/test/settings_test.dart @@ -6,21 +6,23 @@ import 'package:nextcloud_test/nextcloud_test.dart'; import 'package:test/test.dart'; void main() { + final targetFactory = TestTargetFactory.create(); + presets( + targetFactory, 'server', 'settings', (preset) { - late DockerContainer container; + late TestTargetInstance target; late NextcloudClient client; setUpAll(() async { - container = await DockerContainer.create(preset); - client = await TestNextcloudClient.create( - container, + target = await targetFactory.spawn(preset); + client = await target.createClient( username: 'admin', ); }); tearDownAll(() async { - await container.destroy(); + await target.destroy(); }); group('Logs', () { diff --git a/packages/nextcloud/test/spreed_test.dart b/packages/nextcloud/test/spreed_test.dart index 3fa8481b334..3c9e98c51b8 100644 --- a/packages/nextcloud/test/spreed_test.dart +++ b/packages/nextcloud/test/spreed_test.dart @@ -11,18 +11,21 @@ import 'package:test/test.dart'; import 'package:version/version.dart'; void main() { + final targetFactory = TestTargetFactory.create(); + presets( + targetFactory, 'spreed', 'spreed', (preset) { - late DockerContainer container; + late TestTargetInstance target; late NextcloudClient client1; setUpAll(() async { - container = await DockerContainer.create(preset); - client1 = await TestNextcloudClient.create(container); + target = await targetFactory.spawn(preset); + client1 = await target.createClient(); }); tearDownAll(() async { - await container.destroy(); + await target.destroy(); }); Future createTestRoom() async => (await client1.spreed.room.createRoom( @@ -551,8 +554,7 @@ void main() { final room1 = (await client1.spreed.room.joinRoom(token: room.token)).body.ocs.data; await client1.spreed.call.joinCall(token: room.token); - final client2 = await TestNextcloudClient.create( - container, + final client2 = await target.createClient( username: 'user2', ); diff --git a/packages/nextcloud/test/tables_test.dart b/packages/nextcloud/test/tables_test.dart index ea6d69fd8d5..755fb5f449c 100644 --- a/packages/nextcloud/test/tables_test.dart +++ b/packages/nextcloud/test/tables_test.dart @@ -7,18 +7,21 @@ import 'package:timezone/timezone.dart' as tz; import 'package:version/version.dart'; void main() { + final targetFactory = TestTargetFactory.create(); + presets( + targetFactory, 'tables', 'tables', (preset) { - late DockerContainer container; + late TestTargetInstance target; late NextcloudClient client; setUpAll(() async { - container = await DockerContainer.create(preset); - client = await TestNextcloudClient.create(container); + target = await targetFactory.spawn(preset); + client = await target.createClient(); }); tearDownAll(() async { - await container.destroy(); + await target.destroy(); }); test('Is supported', () async { diff --git a/packages/nextcloud/test/uppush_test.dart b/packages/nextcloud/test/uppush_test.dart index 27cfdef462a..472aa90ea10 100644 --- a/packages/nextcloud/test/uppush_test.dart +++ b/packages/nextcloud/test/uppush_test.dart @@ -4,21 +4,23 @@ import 'package:nextcloud_test/nextcloud_test.dart'; import 'package:test/test.dart'; void main() { + final targetFactory = TestTargetFactory.create(); + presets( + targetFactory, 'uppush', 'uppush', (preset) { - late DockerContainer container; + late TestTargetInstance target; late NextcloudClient client; setUpAll(() async { - container = await DockerContainer.create(preset); - client = await TestNextcloudClient.create( - container, + target = await targetFactory.spawn(preset); + client = await target.createClient( username: 'admin', ); }); tearDownAll(() async { - await container.destroy(); + await target.destroy(); }); test('Is installed', () async { diff --git a/packages/nextcloud/test/user_status_test.dart b/packages/nextcloud/test/user_status_test.dart index f690cae9cd8..4a14ac35865 100644 --- a/packages/nextcloud/test/user_status_test.dart +++ b/packages/nextcloud/test/user_status_test.dart @@ -6,18 +6,21 @@ import 'package:nextcloud_test/nextcloud_test.dart'; import 'package:test/test.dart'; void main() { + final targetFactory = TestTargetFactory.create(); + presets( + targetFactory, 'server', 'user_status', (preset) { - late DockerContainer container; + late TestTargetInstance target; late NextcloudClient client; setUpAll(() async { - container = await DockerContainer.create(preset); - client = await TestNextcloudClient.create(container); + target = await targetFactory.spawn(preset); + client = await target.createClient(); }); tearDownAll(() async { - await container.destroy(); + await target.destroy(); }); setUp(() async { diff --git a/packages/nextcloud/test/weather_status_test.dart b/packages/nextcloud/test/weather_status_test.dart index 381a81015e8..6eddbf24522 100644 --- a/packages/nextcloud/test/weather_status_test.dart +++ b/packages/nextcloud/test/weather_status_test.dart @@ -7,18 +7,21 @@ import 'package:test/test.dart'; import 'package:version/version.dart'; void main() { + final targetFactory = TestTargetFactory.create(); + presets( + targetFactory, 'server', 'weather_status', (preset) { - late DockerContainer container; + late TestTargetInstance target; late NextcloudClient client; setUpAll(() async { - container = await DockerContainer.create(preset); - client = await TestNextcloudClient.create(container); + target = await targetFactory.spawn(preset); + client = await target.createClient(); }); tearDownAll(() async { - await container.destroy(); + await target.destroy(); }); test('Set mode', () async { diff --git a/packages/nextcloud/test/webdav_test.dart b/packages/nextcloud/test/webdav_test.dart index 86df0eb5d52..d38ca045e2f 100644 --- a/packages/nextcloud/test/webdav_test.dart +++ b/packages/nextcloud/test/webdav_test.dart @@ -191,16 +191,19 @@ void main() { }); }); + final targetFactory = TestTargetFactory.create(); + presets( + targetFactory, 'server', 'webdav', (preset) { - late DockerContainer container; + late TestTargetInstance target; late NextcloudClient client; setUpAll(() async { - container = await DockerContainer.create(preset); - client = await TestNextcloudClient.create(container); + target = await targetFactory.spawn(preset); + client = await target.createClient(); await client.webdav.mkcol(PathUri.parse('test')); resetFixture(); @@ -209,7 +212,7 @@ void main() { closeFixture(); await client.webdav.delete(PathUri.parse('test')); - await container.destroy(); + await target.destroy(); }); test('List directory', () async { diff --git a/packages/nextcloud_test/lib/nextcloud_test.dart b/packages/nextcloud_test/lib/nextcloud_test.dart index 2d0eff6c47a..bb8856958f8 100644 --- a/packages/nextcloud_test/lib/nextcloud_test.dart +++ b/packages/nextcloud_test/lib/nextcloud_test.dart @@ -1,5 +1,4 @@ export 'src/defaults.dart'; -export 'src/docker_container.dart'; export 'src/fixtures.dart' hide appendFixture; export 'src/presets.dart'; -export 'src/test_client.dart'; +export 'src/test_target/test_target.dart'; diff --git a/packages/nextcloud_test/lib/src/docker_container.dart b/packages/nextcloud_test/lib/src/docker_container.dart deleted file mode 100644 index d4a2b4c6666..00000000000 --- a/packages/nextcloud_test/lib/src/docker_container.dart +++ /dev/null @@ -1,81 +0,0 @@ -import 'dart:async'; -import 'dart:math'; - -import 'package:nextcloud_test/src/presets.dart'; -import 'package:process_run/process_run.dart'; - -int _randomPort() => 1024 + Random().nextInt(65535 - 1024); - -/// Represents a docker container on the system. -class DockerContainer { - DockerContainer._({ - required this.id, - required this.port, - }); - - /// Creates a new docker container and returns its representation. - static Future create(Preset preset) async { - final dockerImageName = 'ghcr.io/nextcloud/neon/dev:${preset.name}-${preset.version.major}.${preset.version.minor}'; - - 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(); - result = await runExecutableArguments( - 'docker', - [ - 'run', - '--rm', - '-d', - '--add-host', - 'host.docker.internal:host-gateway', - '-p', - '$port:80', - dockerImageName, - ], - ); - // 125 means the docker run command itself has failed which indicated the port is already used - if (result.exitCode != 125) { - break; - } - } - - if (result.exitCode != 0) { - throw Exception('Failed to run docker container: ${result.stderr}'); - } - - return DockerContainer._( - id: result.stdout.toString().replaceAll('\n', ''), - port: port, - ); - } - - /// ID of the docker container. - final String id; - - /// Assigned port of docker container. - final int port; - - /// Removes the docker container from the system. - Future destroy() => runExecutableArguments( - 'docker', - [ - 'kill', - id, - ], - ); -} diff --git a/packages/nextcloud_test/lib/src/fixtures.dart b/packages/nextcloud_test/lib/src/fixtures.dart index 1c2911216c4..1d314c21afd 100644 --- a/packages/nextcloud_test/lib/src/fixtures.dart +++ b/packages/nextcloud_test/lib/src/fixtures.dart @@ -30,7 +30,7 @@ void resetFixture() { /// Validates that the requests match the stored fixtures. /// /// If there is no stored fixture a new one is created. -void validateFixture(Preset preset) { +void validateFixture(Preset? preset) { if (_fixture.isEmpty) { return; } @@ -46,20 +46,17 @@ void validateFixture(Preset preset) { groups.add(group.name.replaceFirst('${groups.join(' ')} ', '')); } - // Remove the groups that are the preset name and the preset version and the app is kept. - for (var i = 0; i <= 2; i++) { - if (groups[i] == '${preset.version.major}.${preset.version.minor}') { - if (i == 1) { - // Remove preset version - groups.removeAt(1); - } else { - groups - // Remove preset version - ..removeAt(2) - // Remove preset group - ..removeAt(0); + if (groups.isNotEmpty && groups[0] == 'server') { + groups.removeAt(0); + } + + if (preset != null) { + // Remove the groups that are the preset name and the preset version and the app is kept. + for (var i = 0; i <= 2; i++) { + if (groups[i] == '${preset.version.major}.${preset.version.minor}') { + groups.removeAt(i); + break; } - break; } } diff --git a/packages/nextcloud_test/lib/src/presets.dart b/packages/nextcloud_test/lib/src/presets.dart index b86496a30ba..1b4e28cf14e 100644 --- a/packages/nextcloud_test/lib/src/presets.dart +++ b/packages/nextcloud_test/lib/src/presets.dart @@ -1,46 +1,26 @@ -import 'package:nextcloud/webdav.dart'; import 'package:nextcloud_test/nextcloud_test.dart'; import 'package:test/test.dart'; -import 'package:universal_io/io.dart'; import 'package:version/version.dart'; /// Combination of preset `name` and preset `version`. typedef Preset = ({String name, Version version}); -final Map> _presets = () { - final presets = >{}; - - final presetGroups = Directory('../nextcloud_test/docker/presets') - .listSync(followLinks: false) - .whereType() - .map((d) => PathUri.parse(d.path).name); - - for (final presetGroup in presetGroups) { - final presetVersions = Directory('../nextcloud_test/docker/presets/$presetGroup') - .listSync(followLinks: false) - .whereType() - .map((f) => Version.parse(PathUri.parse(f.path).name)); - - presets[presetGroup] = presetVersions.toList(); - } - - return presets; -}(); - /// All tests for apps that depend on the server version must be wrapped with this method and pass along the preset. void presets( + TestTargetFactory targetFactory, String presetGroup, String app, dynamic Function(Preset preset) body, { int? retry, Timeout? timeout, }) { - if (!_presets.containsKey(presetGroup)) { + final presets = targetFactory.getPresets(); + if (!presets.containsKey(presetGroup)) { throw Exception('Unknown preset type "$presetGroup"'); } void innerBody() { - for (final presetVersion in _presets[presetGroup]!) { + for (final presetVersion in presets[presetGroup]!) { group('${presetVersion.major}.${presetVersion.minor}', () { final preset = (name: presetGroup, version: presetVersion); @@ -48,7 +28,7 @@ void presets( validateFixture(preset); }); - return body(preset); + body(preset); }); } } diff --git a/packages/nextcloud_test/lib/src/test_client.dart b/packages/nextcloud_test/lib/src/test_client.dart deleted file mode 100644 index 2b845d21193..00000000000 --- a/packages/nextcloud_test/lib/src/test_client.dart +++ /dev/null @@ -1,71 +0,0 @@ -import 'dart:async'; -import 'dart:convert'; - -import 'package:cookie_store/cookie_store.dart'; -import 'package:neon_http_client/neon_http_client.dart'; -import 'package:nextcloud/nextcloud.dart'; -import 'package:nextcloud_test/src/docker_container.dart'; -import 'package:nextcloud_test/src/fixtures.dart'; -import 'package:nextcloud_test/src/proxy_http_client.dart'; -import 'package:process_run/process_run.dart'; - -/// An extension for creating [NextcloudClient]s based on [DockerContainer]s. -extension TestNextcloudClient on NextcloudClient { - /// Creates a new [NextcloudClient] for a given [container] and [username]. - /// - /// It is expected that the password of the user matches the its [username]. - /// This is the case for the available test docker containers. - static Future create( - DockerContainer container, { - String? username = 'user1', - }) async { - String? appPassword; - if (username != null) { - final inputStream = StreamController>(); - final process = runExecutableArguments( - 'docker', - [ - 'exec', - '-i', - container.id, - 'php', - '-f', - 'occ', - 'user:add-app-password', - username, - ], - stdin: inputStream.stream, - ); - inputStream.add(utf8.encode(username)); - await inputStream.close(); - - final result = await process; - if (result.exitCode != 0) { - throw Exception('Failed to run generate app password command\n${result.stderr}\n${result.stdout}'); - } - appPassword = (result.stdout as String).split('\n')[1]; - } - - final url = Uri( - scheme: 'http', - host: 'localhost', - port: container.port, - ); - - final httpClient = NeonHttpClient( - baseURL: url, - cookieStore: CookieStore(), - client: getProxyHttpClient( - onRequest: appendFixture, - ), - ); - - return NextcloudClient( - url, - loginName: username, - password: username, - appPassword: appPassword, - httpClient: httpClient, - ); - } -} diff --git a/packages/nextcloud_test/lib/src/test_target/docker_container.dart b/packages/nextcloud_test/lib/src/test_target/docker_container.dart new file mode 100644 index 00000000000..14221f916b0 --- /dev/null +++ b/packages/nextcloud_test/lib/src/test_target/docker_container.dart @@ -0,0 +1,155 @@ +import 'dart:async'; +import 'dart:convert'; +import 'dart:io'; +import 'dart:math'; + +import 'package:nextcloud/webdav.dart'; +import 'package:nextcloud_test/src/presets.dart'; +import 'package:nextcloud_test/src/test_target/test_target.dart'; +import 'package:process_run/process_run.dart'; +import 'package:version/version.dart'; + +int _randomPort() => 1024 + Random().nextInt(65535 - 1024); + +/// Factory for spawning docker containers as test targets. +class DockerContainerFactory implements TestTargetFactory { + /// Creates a new docker container and returns its representation. + @override + Future spawn(Preset? preset) async { + final dockerImageName = + 'ghcr.io/nextcloud/neon/dev:${preset!.name}-${preset.version.major}.${preset.version.minor}'; + + 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(); + result = await runExecutableArguments( + 'docker', + [ + 'run', + '--rm', + '-d', + '--add-host', + 'host.docker.internal:host-gateway', + '-p', + '$port:80', + dockerImageName, + ], + ); + // 125 means the docker run command itself has failed which indicated the port is already used + if (result.exitCode != 125) { + break; + } + } + + if (result.exitCode != 0) { + throw Exception('Failed to run docker container: ${result.stderr}'); + } + + return DockerContainerInstance( + id: result.stdout.toString().replaceAll('\n', ''), + port: port, + ); + } + + @override + Map> getPresets() { + final presets = >{}; + + final presetGroups = Directory('../nextcloud_test/docker/presets') + .listSync(followLinks: false) + .whereType() + .map((d) => PathUri.parse(d.path).name); + + for (final presetGroup in presetGroups) { + final presetVersions = Directory('../nextcloud_test/docker/presets/$presetGroup') + .listSync(followLinks: false) + .whereType() + .map((f) => Version.parse(PathUri.parse(f.path).name)); + + presets[presetGroup] = presetVersions.toList(); + } + + return presets; + } +} + +/// Test target representing a docker container. +class DockerContainerInstance extends TestTargetInstance { + /// Creates a new Docker container instance. + DockerContainerInstance({ + required this.id, + required this.port, + }); + + /// ID of the docker container. + final String id; + + /// Assigned port of docker container. + final int port; + + /// Removes the docker container from the system. + @override + Future destroy() => runExecutableArguments( + 'docker', + [ + 'kill', + id, + ], + ); + + @override + late Uri hostURL = Uri( + scheme: 'http', + host: 'localhost', + port: port, + ); + + @override + Uri targetURL = Uri( + scheme: 'http', + host: 'localhost', + ); + + @override + Future createAppPassword(String username) async { + final inputStream = StreamController>(); + final process = runExecutableArguments( + 'docker', + [ + 'exec', + '-i', + id, + 'php', + '-f', + 'occ', + 'user:add-app-password', + username, + ], + stdin: inputStream.stream, + ); + inputStream.add(utf8.encode(username)); + await inputStream.close(); + + final result = await process; + if (result.exitCode != 0) { + throw Exception('Failed to run generate app password command\n${result.stderr}\n${result.stdout}'); + } + + return (result.stdout as String).split('\n')[1]; + } +} diff --git a/packages/nextcloud_test/lib/src/test_target/test_target.dart b/packages/nextcloud_test/lib/src/test_target/test_target.dart new file mode 100644 index 00000000000..311fe6c549e --- /dev/null +++ b/packages/nextcloud_test/lib/src/test_target/test_target.dart @@ -0,0 +1,67 @@ +import 'dart:async'; + +import 'package:cookie_store/cookie_store.dart'; +import 'package:neon_http_client/neon_http_client.dart'; +import 'package:nextcloud/nextcloud.dart'; +import 'package:nextcloud_test/nextcloud_test.dart'; +import 'package:nextcloud_test/src/fixtures.dart'; +import 'package:nextcloud_test/src/proxy_http_client.dart'; +import 'package:nextcloud_test/src/test_target/docker_container.dart'; +import 'package:version/version.dart'; + +/// Factory for creating [TestTargetInstance]s. +abstract interface class TestTargetFactory { + /// Creates a new [TestTargetFactory]. + static TestTargetFactory create() { + return DockerContainerFactory(); + } + + /// Spawns a new [T]. + FutureOr spawn(Preset? preset); + + /// Returns the available presets for the factory. + Map> getPresets(); +} + +/// Instance of a test target. +abstract class TestTargetInstance { + /// Destroys the instance. + FutureOr destroy(); + + /// URL where the target is available from the host side. + Uri get hostURL; + + /// URL where the target is available from itself. + Uri get targetURL; + + /// Creates an app password for [username] on the instance. + FutureOr createAppPassword(String username); + + /// Creates a new [NextcloudClient] for a given [username]. + /// + /// It is expected that the password of the user matches the its [username]. + FutureOr createClient({ + String? username = 'user1', + }) async { + String? appPassword; + if (username != null) { + appPassword = await createAppPassword(username); + } + + final httpClient = NeonHttpClient( + baseURL: hostURL, + cookieStore: CookieStore(), + client: getProxyHttpClient( + onRequest: appendFixture, + ), + ); + + return NextcloudClient( + hostURL, + loginName: username, + password: username, + appPassword: appPassword, + httpClient: httpClient, + ); + } +}