Skip to content

Commit

Permalink
refactor(nextcloud_test): Abstract test targets
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Jul 28, 2024
1 parent 0aacd5d commit 3135832
Show file tree
Hide file tree
Showing 35 changed files with 362 additions and 281 deletions.
19 changes: 10 additions & 9 deletions packages/nextcloud/test/cookbook_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 8 additions & 5 deletions packages/nextcloud/test/core_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 7 additions & 4 deletions packages/nextcloud/test/dashboard_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"\}
\{"url":"http://.*/static/recipe\.html"\}
2 changes: 1 addition & 1 deletion packages/nextcloud/test/fixtures/news/add_feed.regexp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion packages/nextcloud/test/fixtures/news/delete_feed.regexp
Original file line number Diff line number Diff line change
@@ -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]+
Expand Down
2 changes: 1 addition & 1 deletion packages/nextcloud/test/fixtures/news/list_articles.regexp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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]+
Expand Down
2 changes: 1 addition & 1 deletion packages/nextcloud/test/fixtures/news/rename_feed.regexp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/nextcloud/test/fixtures/news/star_article.regexp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 12 additions & 9 deletions packages/nextcloud/test/news_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -34,12 +37,12 @@ void main() {
});

Future<DynamiteResponse<news.ListFeeds, void>> addWikipediaFeed([int? folderID]) async => client.news.addFeed(
url: 'http://localhost/static/wikipedia.xml',
url: '${target.targetURL}/static/wikipedia.xml',
folderId: folderID,
);

Future<DynamiteResponse<news.ListFeeds, void>> addNasaFeed() async => client.news.addFeed(
url: 'http://localhost/static/nasa.xml',
url: '${target.targetURL}/static/nasa.xml',
);

test('Is supported', () async {
Expand All @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 7 additions & 4 deletions packages/nextcloud/test/notes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 7 additions & 5 deletions packages/nextcloud/test/notifications_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> sendTestNotification() async {
Expand Down
12 changes: 7 additions & 5 deletions packages/nextcloud/test/provisioning_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down
12 changes: 7 additions & 5 deletions packages/nextcloud/test/settings_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down
Loading

0 comments on commit 3135832

Please sign in to comment.