218 lines
6.5 KiB
Dart
218 lines
6.5 KiB
Dart
import 'package:podman/podman.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'support/fake_podman_transport.dart';
|
|
|
|
void main() {
|
|
group('PodmanClient network API', () {
|
|
test('checks whether a network exists', () async {
|
|
final transport = FakePodmanTransport()
|
|
..enqueue(
|
|
method: HttpMethod.get,
|
|
path: '/v5.0.0/libpod/networks/groupware/exists',
|
|
statusCode: 204,
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.get,
|
|
path: '/v5.0.0/libpod/networks/missing/exists',
|
|
statusCode: 404,
|
|
);
|
|
|
|
final client = PodmanClient(transport: transport);
|
|
|
|
expect(await client.networkExists('groupware'), isTrue);
|
|
expect(await client.networkExists('missing'), isFalse);
|
|
transport.expectNoPending();
|
|
});
|
|
|
|
test('lists networks', () async {
|
|
final transport = FakePodmanTransport()
|
|
..enqueue(
|
|
method: HttpMethod.get,
|
|
path: '/v5.0.0/libpod/networks/json',
|
|
responseBody: <Object?>[
|
|
<String, Object?>{
|
|
'id': 'net-1',
|
|
'name': 'groupware',
|
|
'driver': 'bridge',
|
|
'internal': false,
|
|
'dns_enabled': true,
|
|
'subnets': <Object?>[
|
|
<String, Object?>{
|
|
'subnet': '10.40.0.0/24',
|
|
'gateway': '10.40.0.1',
|
|
},
|
|
],
|
|
'labels': <String, String>{'stack': 'groupware'},
|
|
},
|
|
],
|
|
);
|
|
|
|
final client = PodmanClient(transport: transport);
|
|
final networks = await client.listNetworks();
|
|
|
|
expect(networks, hasLength(1));
|
|
expect(networks.first.id, 'net-1');
|
|
expect(networks.first.name, 'groupware');
|
|
expect(networks.first.driver, 'bridge');
|
|
expect(networks.first.labels['stack'], 'groupware');
|
|
expect(networks.first.subnets.first.subnet, '10.40.0.0/24');
|
|
transport.expectNoPending();
|
|
});
|
|
|
|
test('supports create, inspect, connect, disconnect, and remove', () async {
|
|
final transport = FakePodmanTransport()
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/networks/create',
|
|
body: const <String, Object?>{
|
|
'name': 'groupware',
|
|
'driver': 'bridge',
|
|
'internal': false,
|
|
'dns_enabled': true,
|
|
'labels': <String, String>{'stack': 'groupware'},
|
|
'subnets': <Object?>[
|
|
<String, Object?>{
|
|
'subnet': '10.40.0.0/24',
|
|
'gateway': '10.40.0.1',
|
|
},
|
|
],
|
|
},
|
|
statusCode: 200,
|
|
responseBody: <String, Object?>{
|
|
'id': 'net-1',
|
|
'name': 'groupware',
|
|
'driver': 'bridge',
|
|
'internal': false,
|
|
'dns_enabled': true,
|
|
'labels': <String, String>{'stack': 'groupware'},
|
|
'subnets': <Object?>[
|
|
<String, Object?>{
|
|
'subnet': '10.40.0.0/24',
|
|
'gateway': '10.40.0.1',
|
|
},
|
|
],
|
|
},
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.get,
|
|
path: '/v5.0.0/libpod/networks/groupware/json',
|
|
responseBody: <String, Object?>{
|
|
'id': 'net-1',
|
|
'name': 'groupware',
|
|
'driver': 'bridge',
|
|
'internal': false,
|
|
'dns_enabled': true,
|
|
},
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/networks/groupware/connect',
|
|
body: const <String, Object?>{
|
|
'Container': 'orchestrator',
|
|
'Aliases': <String>['orch'],
|
|
},
|
|
statusCode: 200,
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/networks/groupware/disconnect',
|
|
body: const <String, Object?>{
|
|
'Container': 'orchestrator',
|
|
'Force': true,
|
|
},
|
|
statusCode: 200,
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.delete,
|
|
path: '/v5.0.0/libpod/networks/groupware',
|
|
statusCode: 200,
|
|
);
|
|
|
|
final client = PodmanClient(transport: transport);
|
|
|
|
final created = await client.createNetwork(
|
|
const NetworkCreateOptions(
|
|
name: 'groupware',
|
|
internal: false,
|
|
dnsEnabled: true,
|
|
labels: <String, String>{'stack': 'groupware'},
|
|
subnet: '10.40.0.0/24',
|
|
gateway: '10.40.0.1',
|
|
),
|
|
);
|
|
expect(created.id, 'net-1');
|
|
|
|
final inspected = await client.inspectNetwork('groupware');
|
|
expect(inspected.name, 'groupware');
|
|
|
|
await client.connectNetwork(
|
|
'groupware',
|
|
const NetworkConnectOptions(
|
|
container: 'orchestrator',
|
|
aliases: <String>['orch'],
|
|
),
|
|
);
|
|
|
|
await client.disconnectNetwork(
|
|
'groupware',
|
|
container: 'orchestrator',
|
|
force: true,
|
|
);
|
|
|
|
await client.removeNetwork('groupware');
|
|
transport.expectNoPending();
|
|
});
|
|
|
|
test('supports network update and prune endpoints', () async {
|
|
final transport = FakePodmanTransport()
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/networks/groupware/update',
|
|
body: const <String, Object?>{
|
|
'adddnsservers': <String>['1.1.1.1'],
|
|
'removednsservers': <String>['9.9.9.9'],
|
|
},
|
|
statusCode: 204,
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/networks/prune',
|
|
queryParameters: const <String, List<String>>{
|
|
'filters': <String>['{"until":["24h"]}'],
|
|
},
|
|
responseBody: const <Object?>[
|
|
<String, Object?>{'Name': 'groupware-old'},
|
|
<String, Object?>{
|
|
'Name': 'groupware-in-use',
|
|
'Error': 'network is in use',
|
|
},
|
|
],
|
|
);
|
|
|
|
final client = PodmanClient(transport: transport);
|
|
|
|
await client.updateNetwork(
|
|
'groupware',
|
|
const NetworkUpdateOptions(
|
|
addDnsServers: <String>['1.1.1.1'],
|
|
removeDnsServers: <String>['9.9.9.9'],
|
|
),
|
|
);
|
|
|
|
final reports = await client.pruneNetworks(
|
|
options: const NetworkPruneOptions(
|
|
filters: <String, List<String>>{
|
|
'until': <String>['24h'],
|
|
},
|
|
),
|
|
);
|
|
|
|
expect(reports, hasLength(2));
|
|
expect(reports.first.name, 'groupware-old');
|
|
expect(reports.last.error, contains('in use'));
|
|
|
|
transport.expectNoPending();
|
|
});
|
|
});
|
|
}
|