111 lines
3.2 KiB
Dart
111 lines
3.2 KiB
Dart
import 'package:podman/podman.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'support/fake_podman_transport.dart';
|
|
|
|
void main() {
|
|
group('PodmanClient kube/generate API', () {
|
|
test('supports play kube up/down', () async {
|
|
const yaml = '''
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
name: gw
|
|
spec:
|
|
containers:
|
|
- name: app
|
|
image: docker.io/library/hello-world:latest
|
|
''';
|
|
|
|
final transport = FakePodmanTransport()
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/play/kube',
|
|
queryParameters: const <String, List<String>>{
|
|
'replace': <String>['true'],
|
|
'start': <String>['true'],
|
|
'tlsVerify': <String>['false'],
|
|
},
|
|
body: yaml,
|
|
statusCode: 200,
|
|
responseBody: const <String, Object?>{
|
|
'Pods': <String>['gw'],
|
|
'Volumes': <String>[],
|
|
'Secrets': <String>[],
|
|
'ServiceContainerID': 'svc-1',
|
|
},
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.delete,
|
|
path: '/v5.0.0/libpod/play/kube',
|
|
queryParameters: const <String, List<String>>{
|
|
'force': <String>['true'],
|
|
},
|
|
body: yaml,
|
|
statusCode: 200,
|
|
responseBody: const <String, Object?>{
|
|
'Pods': <String>['gw'],
|
|
'Volumes': <String>[],
|
|
'Secrets': <String>[],
|
|
'ServiceContainerID': '',
|
|
},
|
|
);
|
|
|
|
final client = PodmanClient(transport: transport);
|
|
|
|
final upReport = await client.playKube(
|
|
yaml,
|
|
options: const PlayKubeOptions(
|
|
replace: true,
|
|
start: true,
|
|
tlsVerify: false,
|
|
),
|
|
);
|
|
expect(upReport.pods, contains('gw'));
|
|
|
|
final downReport = await client.playKubeDown(yaml, force: true);
|
|
expect(downReport.pods, contains('gw'));
|
|
|
|
transport.expectNoPending();
|
|
});
|
|
|
|
test('supports generate kube and generate systemd', () async {
|
|
final transport = FakePodmanTransport()
|
|
..enqueue(
|
|
method: HttpMethod.get,
|
|
path: '/v5.0.0/libpod/generate/kube',
|
|
queryParameters: const <String, List<String>>{
|
|
'names': <String>['gw'],
|
|
'service': <String>['true'],
|
|
},
|
|
statusCode: 200,
|
|
responseBody: 'apiVersion: v1\nkind: Pod\nmetadata:\n name: gw\n',
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.get,
|
|
path: '/v5.0.0/libpod/generate/gw/systemd',
|
|
queryParameters: const <String, List<String>>{
|
|
'useName': <String>['true'],
|
|
},
|
|
statusCode: 200,
|
|
responseBody: const <String, Object?>{
|
|
'container-gw.service': '[Unit]\nDescription=gw\n',
|
|
},
|
|
);
|
|
|
|
final client = PodmanClient(transport: transport);
|
|
|
|
final kubeYaml = await client.generateKube(
|
|
const GenerateKubeOptions(names: <String>['gw'], service: true),
|
|
);
|
|
expect(kubeYaml, contains('kind: Pod'));
|
|
|
|
final systemd = await client.generateSystemd(
|
|
'gw',
|
|
options: const GenerateSystemdOptions(useName: true),
|
|
);
|
|
expect(systemd.units.keys, contains('container-gw.service'));
|
|
transport.expectNoPending();
|
|
});
|
|
});
|
|
}
|