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 { '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: {'B': '2', 'A': '1'}, labels: {'tier': 'backend', 'service': 'sample'}, ports: [PortBinding.publish(8080, 80)], mounts: [ MountBinding.bind( source: '/host/path', target: '/data', readOnly: true, ), ], command: ['echo', 'ok'], ); expect(options.toCreateBody(), const { 'Image': 'busybox:latest', 'Cmd': ['echo', 'ok'], 'Entrypoint': ['/bin/sh'], 'Env': ['A=1', 'B=2'], 'Labels': {'tier': 'backend', 'service': 'sample'}, 'Hostname': 'svc-1', 'User': '1000:1000', 'WorkingDir': '/workspace', 'ExposedPorts': {'80/tcp': {}}, 'HostConfig': { 'AutoRemove': true, 'NetworkMode': 'groupware', 'RestartPolicy': {'Name': 'on-failure'}, 'PortBindings': { '80/tcp': [ {'HostPort': '8080'}, ], }, 'Mounts': [ { '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 { '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 { '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 { '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 { 'Type': 'tmpfs', 'Target': '/tmp', 'ReadOnly': false, }); }); }); }