Browse Source

refactor(tool,nextcloud): Use dev container to serve static test files

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/1067/head
jld3103 1 year ago
parent
commit
0d8aeeb180
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 2
      cspell.json
  2. 39
      packages/nextcloud/test/news_test.dart
  3. 2
      tool/Dockerfile.dev
  4. 0
      tool/dev/static/nasa.xml
  5. 0
      tool/dev/static/wikipedia.xml
  6. 0
      tool/overlay/.gitkeep

2
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",

39
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<DynamiteResponse<news.ListFeeds, void>> 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<DynamiteResponse<news.ListFeeds, void>> 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<HttpServer> 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 (_) {}
}
}

2
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"]

0
packages/nextcloud/test/files/nasa.xml → tool/dev/static/nasa.xml

0
packages/nextcloud/test/files/wikipedia.xml → tool/dev/static/wikipedia.xml

0
tool/overlay/.gitkeep

Loading…
Cancel
Save