138 lines
4.4 KiB
Dart
138 lines
4.4 KiB
Dart
import 'package:podman/podman.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'support/fake_podman_transport.dart';
|
|
|
|
void main() {
|
|
group('PodmanClient container admin API', () {
|
|
test('supports container admin endpoints', () async {
|
|
final transport = FakePodmanTransport()
|
|
..enqueue(
|
|
method: HttpMethod.get,
|
|
path: '/v5.0.0/libpod/containers/showmounted',
|
|
responseBody: const <String, Object?>{
|
|
'ctr-1': '/var/lib/containers/storage/overlay/ctr-1/merged',
|
|
},
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/containers/ctr-1/pause',
|
|
statusCode: 204,
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/containers/ctr-1/unpause',
|
|
statusCode: 204,
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/containers/ctr-1/kill',
|
|
queryParameters: const <String, List<String>>{
|
|
'signal': <String>['SIGTERM'],
|
|
},
|
|
statusCode: 204,
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.get,
|
|
path: '/v5.0.0/libpod/containers/ctr-1/top',
|
|
queryParameters: const <String, List<String>>{
|
|
'ps_args': <String>['aux', '--sort', 'pid'],
|
|
},
|
|
responseBody: const <String, Object?>{
|
|
'Titles': <String>['PID', 'USER', 'COMMAND'],
|
|
'Processes': <Object?>[
|
|
<Object?>['1', 'root', '/pause'],
|
|
],
|
|
},
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/containers/ctr-1/init',
|
|
statusCode: 304,
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/containers/ctr-1/rename',
|
|
queryParameters: const <String, List<String>>{
|
|
'name': <String>['orchestrator'],
|
|
},
|
|
statusCode: 204,
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/containers/orchestrator/update',
|
|
queryParameters: const <String, List<String>>{
|
|
'restartPolicy': <String>['on-failure'],
|
|
'restartRetries': <String>['3'],
|
|
},
|
|
body: const <String, Object?>{
|
|
'resources': <String, Object?>{'memory': 268435456},
|
|
},
|
|
statusCode: 201,
|
|
responseBody: 'ctr-1',
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/containers/orchestrator/mount',
|
|
statusCode: 200,
|
|
responseBody:
|
|
'/var/lib/containers/storage/overlay/orchestrator/merged',
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/containers/orchestrator/unmount',
|
|
statusCode: 204,
|
|
);
|
|
|
|
final client = PodmanClient(transport: transport);
|
|
|
|
final mounted = await client.showMountedContainers();
|
|
expect(
|
|
mounted['ctr-1'],
|
|
'/var/lib/containers/storage/overlay/ctr-1/merged',
|
|
);
|
|
|
|
await client.pauseContainer('ctr-1');
|
|
await client.unpauseContainer('ctr-1');
|
|
await client.killContainer('ctr-1', signal: 'SIGTERM');
|
|
|
|
final top = await client.topContainer(
|
|
'ctr-1',
|
|
options: const ContainerTopOptions(
|
|
psArgs: <String>['aux', '--sort', 'pid'],
|
|
),
|
|
);
|
|
expect(top.titles, <String>['PID', 'USER', 'COMMAND']);
|
|
expect(top.processes.first, <String>['1', 'root', '/pause']);
|
|
|
|
await client.initContainer('ctr-1');
|
|
await client.renameContainer('ctr-1', name: 'orchestrator');
|
|
|
|
final updatedId = await client.updateContainer(
|
|
'orchestrator',
|
|
const ContainerUpdateOptions(
|
|
restartPolicy: 'on-failure',
|
|
restartRetries: 3,
|
|
config: <String, Object?>{
|
|
'resources': <String, Object?>{'memory': 268435456},
|
|
},
|
|
),
|
|
);
|
|
expect(updatedId, 'ctr-1');
|
|
|
|
final mountPoint = await client.mountContainer('orchestrator');
|
|
expect(
|
|
mountPoint,
|
|
'/var/lib/containers/storage/overlay/orchestrator/merged',
|
|
);
|
|
await client.unmountContainer('orchestrator');
|
|
|
|
transport.expectNoPending();
|
|
});
|
|
|
|
test('validates restartRetries requires restartPolicy', () {
|
|
const options = ContainerUpdateOptions(restartRetries: 2);
|
|
expect(options.toQueryParameters, throwsArgumentError);
|
|
});
|
|
});
|
|
}
|