132 lines
3.8 KiB
Dart
132 lines
3.8 KiB
Dart
import 'package:podman/podman.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
void main() {
|
|
group('RunOptions', () {
|
|
test('builds minimal create body', () {
|
|
const options = RunOptions(image: 'hello-world:latest');
|
|
|
|
expect(options.toCreateBody(), const <String, Object?>{
|
|
'Image': 'hello-world:latest',
|
|
});
|
|
});
|
|
|
|
test('builds rich create body deterministically', () {
|
|
const options = RunOptions(
|
|
image: 'busybox:latest',
|
|
name: 'sample',
|
|
removeWhenStopped: true,
|
|
network: 'groupware',
|
|
hostname: 'svc-1',
|
|
entrypoint: '/bin/sh',
|
|
user: '1000:1000',
|
|
workingDirectory: '/workspace',
|
|
restartPolicy: 'on-failure',
|
|
environment: <String, String>{'B': '2', 'A': '1'},
|
|
labels: <String, String>{'tier': 'backend', 'service': 'sample'},
|
|
ports: <PortBinding>[PortBinding.publish(8080, 80)],
|
|
mounts: <MountBinding>[
|
|
MountBinding.bind(
|
|
source: '/host/path',
|
|
target: '/data',
|
|
readOnly: true,
|
|
),
|
|
],
|
|
command: <String>['echo', 'ok'],
|
|
);
|
|
|
|
expect(options.toCreateBody(), const <String, Object?>{
|
|
'Image': 'busybox:latest',
|
|
'Cmd': <String>['echo', 'ok'],
|
|
'Entrypoint': <String>['/bin/sh'],
|
|
'Env': <String>['A=1', 'B=2'],
|
|
'Labels': <String, String>{'tier': 'backend', 'service': 'sample'},
|
|
'Hostname': 'svc-1',
|
|
'User': '1000:1000',
|
|
'WorkingDir': '/workspace',
|
|
'ExposedPorts': <String, Object?>{'80/tcp': <String, Object?>{}},
|
|
'HostConfig': <String, Object?>{
|
|
'AutoRemove': true,
|
|
'NetworkMode': 'groupware',
|
|
'RestartPolicy': <String, Object?>{'Name': 'on-failure'},
|
|
'PortBindings': <String, Object?>{
|
|
'80/tcp': <Object?>[
|
|
<String, String>{'HostPort': '8080'},
|
|
],
|
|
},
|
|
'Mounts': <Object?>[
|
|
<String, Object?>{
|
|
'Type': 'bind',
|
|
'Source': '/host/path',
|
|
'Target': '/data',
|
|
'ReadOnly': true,
|
|
},
|
|
],
|
|
},
|
|
});
|
|
});
|
|
});
|
|
|
|
group('PortBinding', () {
|
|
test('apiKey serializes container port + protocol', () {
|
|
const binding = PortBinding.expose(443, protocol: 'tcp');
|
|
expect(binding.apiKey, '443/tcp');
|
|
expect(binding.hasHostBinding, isFalse);
|
|
});
|
|
|
|
test('serializes host binding entry', () {
|
|
const binding = PortBinding.publish(
|
|
8443,
|
|
443,
|
|
protocol: 'tcp',
|
|
hostIp: '127.0.0.1',
|
|
);
|
|
|
|
expect(binding.apiKey, '443/tcp');
|
|
expect(binding.hasHostBinding, isTrue);
|
|
expect(binding.toApiBindingJson(), const <String, String>{
|
|
'HostIp': '127.0.0.1',
|
|
'HostPort': '8443',
|
|
});
|
|
});
|
|
});
|
|
|
|
group('MountBinding', () {
|
|
test('serializes bind mount to API payload', () {
|
|
const mount = MountBinding.bind(
|
|
source: '/srv/data',
|
|
target: '/data',
|
|
readOnly: true,
|
|
);
|
|
|
|
expect(mount.toApiJson(), const <String, Object?>{
|
|
'Type': 'bind',
|
|
'Source': '/srv/data',
|
|
'Target': '/data',
|
|
'ReadOnly': true,
|
|
});
|
|
});
|
|
|
|
test('serializes volume mount to API payload', () {
|
|
const mount = MountBinding.volume(
|
|
source: 'named-volume',
|
|
target: '/data',
|
|
);
|
|
expect(mount.toApiJson(), const <String, Object?>{
|
|
'Type': 'volume',
|
|
'Source': 'named-volume',
|
|
'Target': '/data',
|
|
'ReadOnly': false,
|
|
});
|
|
});
|
|
|
|
test('serializes tmpfs mount to API payload', () {
|
|
const mount = MountBinding.tmpfs(target: '/tmp');
|
|
expect(mount.toApiJson(), const <String, Object?>{
|
|
'Type': 'tmpfs',
|
|
'Target': '/tmp',
|
|
'ReadOnly': false,
|
|
});
|
|
});
|
|
});
|
|
}
|