169 lines
5.4 KiB
Dart
169 lines
5.4 KiB
Dart
import 'package:podman/podman.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'support/fake_podman_transport.dart';
|
|
|
|
void main() {
|
|
group('PodmanClient volume API', () {
|
|
test('lists volumes', () async {
|
|
final transport = FakePodmanTransport()
|
|
..enqueue(
|
|
method: HttpMethod.get,
|
|
path: '/v5.0.0/libpod/volumes/json',
|
|
responseBody: <Object?>[
|
|
<String, Object?>{
|
|
'Name': 'data',
|
|
'Driver': 'local',
|
|
'Mountpoint': '/var/lib/containers/storage/volumes/data/_data',
|
|
'CreatedAt': '2026-01-01T00:00:00Z',
|
|
'Scope': 'local',
|
|
'MountCount': 1,
|
|
'Labels': <String, String>{'service': 'storage'},
|
|
'Options': <String, String>{'o': 'uid=1000'},
|
|
},
|
|
],
|
|
);
|
|
|
|
final client = PodmanClient(transport: transport);
|
|
final volumes = await client.listVolumes();
|
|
|
|
expect(volumes, hasLength(1));
|
|
expect(volumes.first.name, 'data');
|
|
expect(volumes.first.mountCount, 1);
|
|
expect(volumes.first.labels['service'], 'storage');
|
|
transport.expectNoPending();
|
|
});
|
|
|
|
test('supports filtered list and exists', () async {
|
|
final transport = FakePodmanTransport()
|
|
..enqueue(
|
|
method: HttpMethod.get,
|
|
path: '/v5.0.0/libpod/volumes/json',
|
|
queryParameters: const <String, List<String>>{
|
|
'filters': <String>['{"label":["stack=groupware"]}'],
|
|
},
|
|
responseBody: const <Object?>[],
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.get,
|
|
path: '/v5.0.0/libpod/volumes/groupware-data/exists',
|
|
statusCode: 204,
|
|
);
|
|
|
|
final client = PodmanClient(transport: transport);
|
|
final volumes = await client.listVolumes(
|
|
options: const VolumeListOptions(
|
|
filters: <String, List<String>>{
|
|
'label': <String>['stack=groupware'],
|
|
},
|
|
),
|
|
);
|
|
final exists = await client.volumeExists('groupware-data');
|
|
|
|
expect(volumes, isEmpty);
|
|
expect(exists, isTrue);
|
|
transport.expectNoPending();
|
|
});
|
|
|
|
test('supports create, inspect, remove, and prune', () async {
|
|
final archiveBytes = <int>[1, 2, 3];
|
|
final exportedBytes = <int>[9, 8, 7];
|
|
|
|
final transport = FakePodmanTransport()
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/volumes/create',
|
|
body: const <String, Object?>{
|
|
'Name': 'groupware-data',
|
|
'Driver': 'local',
|
|
'Labels': <String, String>{'stack': 'groupware'},
|
|
'Options': <String, String>{'o': 'uid=1000'},
|
|
},
|
|
statusCode: 201,
|
|
responseBody: const <String, Object?>{
|
|
'Name': 'groupware-data',
|
|
'Driver': 'local',
|
|
'Mountpoint': '/volumes/groupware-data',
|
|
'Scope': 'local',
|
|
'MountCount': 0,
|
|
'Labels': <String, String>{'stack': 'groupware'},
|
|
'Options': <String, String>{'o': 'uid=1000'},
|
|
},
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.get,
|
|
path: '/v5.0.0/libpod/volumes/groupware-data/json',
|
|
responseBody: const <String, Object?>{
|
|
'Name': 'groupware-data',
|
|
'Driver': 'local',
|
|
'Mountpoint': '/volumes/groupware-data',
|
|
'Scope': 'local',
|
|
'MountCount': 0,
|
|
},
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.delete,
|
|
path: '/v5.0.0/libpod/volumes/groupware-data',
|
|
queryParameters: const <String, List<String>>{
|
|
'force': <String>['true'],
|
|
},
|
|
statusCode: 204,
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/volumes/prune',
|
|
queryParameters: const <String, List<String>>{
|
|
'filters': <String>['{"label":["stack=groupware"]}'],
|
|
},
|
|
statusCode: 200,
|
|
responseBody: const <Object?>[
|
|
<String, Object?>{'Id': 'groupware-data', 'Size': 1024},
|
|
],
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.get,
|
|
path: '/v5.0.0/libpod/volumes/groupware-data/export',
|
|
statusCode: 200,
|
|
responseBody: exportedBytes,
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/volumes/groupware-data/import',
|
|
statusCode: 204,
|
|
body: archiveBytes,
|
|
);
|
|
|
|
final client = PodmanClient(transport: transport);
|
|
|
|
final created = await client.createVolume(
|
|
const VolumeCreateOptions(
|
|
name: 'groupware-data',
|
|
labels: <String, String>{'stack': 'groupware'},
|
|
options: <String, String>{'o': 'uid=1000'},
|
|
),
|
|
);
|
|
expect(created.name, 'groupware-data');
|
|
|
|
final inspected = await client.inspectVolume('groupware-data');
|
|
expect(inspected.driver, 'local');
|
|
|
|
await client.removeVolume('groupware-data', force: true);
|
|
final pruned = await client.pruneVolumes(
|
|
options: const VolumePruneOptions(
|
|
filters: <String, List<String>>{
|
|
'label': <String>['stack=groupware'],
|
|
},
|
|
),
|
|
);
|
|
expect(pruned, hasLength(1));
|
|
expect(pruned.first.size, 1024);
|
|
|
|
final exported = await client.exportVolume('groupware-data');
|
|
expect(exported, exportedBytes);
|
|
|
|
await client.importVolume('groupware-data', archiveBytes: archiveBytes);
|
|
|
|
transport.expectNoPending();
|
|
});
|
|
});
|
|
}
|