Skip to content

Commit

Permalink
refactor(nextcloud): Rely on prebuilt docker image for testing
Browse files Browse the repository at this point in the history
Signed-off-by: jld3103 <[email protected]>
  • Loading branch information
provokateurin committed Nov 1, 2023
1 parent 0d8aeeb commit 5051ce1
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 100 deletions.
5 changes: 1 addition & 4 deletions packages/nextcloud/test/core_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ void main() {
group(
'core',
() {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());

late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(container);
});
tearDown(() => container.destroy());
Expand Down
5 changes: 1 addition & 4 deletions packages/nextcloud/test/dashboard_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ void main() {
group(
'dashboard',
() {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());

late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(container);
});
tearDown(() => container.destroy());
Expand Down
50 changes: 19 additions & 31 deletions packages/nextcloud/test/helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,25 @@ Future<TestNextcloudClient> getTestClient(
return client;
}

Future<DockerContainer> getDockerContainer(final DockerImage image) async {
Future<DockerContainer> getDockerContainer() async {
const dockerImageName = 'ghcr.io/nextcloud/neon/dev';

late ProcessResult result;
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();
Expand All @@ -171,7 +188,7 @@ Future<DockerContainer> getDockerContainer(final DockerImage image) async {
'host.docker.internal:host-gateway',
'-p',
'$port:80',
image,
dockerImageName,
],
);
// 125 means the docker run command itself has failed which indicated the port is already used
Expand All @@ -190,35 +207,6 @@ Future<DockerContainer> getDockerContainer(final DockerImage image) async {
);
}

typedef DockerImage = String;

Future<DockerImage> getDockerImage() async {
const dockerImageName = 'nextcloud-neon-dev';

final inputStream = StreamController<List<int>>();
final process = runExecutableArguments(
'docker',
[
'build',
'-t',
dockerImageName,
'-f',
'-',
'../../tool',
],
stdin: inputStream.stream,
);
inputStream.add(utf8.encode(File('../../tool/Dockerfile.dev').readAsStringSync()));
await inputStream.close();

final result = await process;
if (result.exitCode != 0) {
throw Exception('Failed to build docker image');
}

return dockerImageName;
}

class TestNextcloudUser {
TestNextcloudUser(
this.username,
Expand Down
7 changes: 1 addition & 6 deletions packages/nextcloud/test/news_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@ void main() {
group(
'news',
() {
late DockerImage image;
setUpAll(() async {
image = await getDockerImage();
});

late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(container);
});
tearDown(() => container.destroy());
Expand Down
5 changes: 1 addition & 4 deletions packages/nextcloud/test/notes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ void main() {
group(
'notes',
() {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());

late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(container);
});
tearDown(() => container.destroy());
Expand Down
10 changes: 2 additions & 8 deletions packages/nextcloud/test/notifications_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import 'helper.dart';

void main() {
group('notifications', () {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());

late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(
container,
username: 'admin',
Expand Down Expand Up @@ -103,13 +100,10 @@ void main() {
});

group('Push', () {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());

late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(
container,
username: 'admin',
Expand Down
5 changes: 1 addition & 4 deletions packages/nextcloud/test/provisioning_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ void main() {
group(
'provisioning_api',
() {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());

late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(
container,
username: 'admin',
Expand Down
47 changes: 24 additions & 23 deletions packages/nextcloud/test/settings_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@ import 'package:test/test.dart';

import 'helper.dart';

Future<void> main() async {
await run(await getDockerImage());
}

Future<void> run(final DockerImage image) async {
group('settings', () {
late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
client = await getTestClient(
container,
username: 'admin',
);
});
tearDown(() => container.destroy());
void main() {
group(
'settings',
() {
late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer();
client = await getTestClient(
container,
username: 'admin',
);
});
tearDown(() => container.destroy());

group('Logs', () {
test('Download', () async {
final response = await client.settings.logSettings.download();
final logs = utf8.decode(response.body);
expect(logs, await container.nextcloudLogs());
group('Logs', () {
test('Download', () async {
final response = await client.settings.logSettings.download();
final logs = utf8.decode(response.body);
expect(logs, await container.nextcloudLogs());
});
});
});
});
},
retry: retryCount,
timeout: timeout,
);
}
5 changes: 1 addition & 4 deletions packages/nextcloud/test/spreed_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ void main() {
group(
'spreed',
() {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());

late DockerContainer container;
late TestNextcloudClient client1;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client1 = await getTestClient(container);
});
tearDown(() => container.destroy());
Expand Down
5 changes: 1 addition & 4 deletions packages/nextcloud/test/uppush_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ void main() {
group(
'uppush',
() {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());

late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(
container,
username: 'admin',
Expand Down
5 changes: 1 addition & 4 deletions packages/nextcloud/test/user_status_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ void main() {
group(
'user_status',
() {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());

late DockerContainer container;
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(container);
});
tearDown(() => container.destroy());
Expand Down
5 changes: 1 addition & 4 deletions packages/nextcloud/test/webdav_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ void main() {
group(
'webdav',
() {
late DockerImage image;
setUpAll(() async => image = await getDockerImage());

late DockerContainer container;
late TestNextcloudClient client;

setUp(() async {
container = await getDockerContainer(image);
container = await getDockerContainer();
client = await getTestClient(container);
});
tearDown(() => container.destroy());
Expand Down

0 comments on commit 5051ce1

Please sign in to comment.