191 lines
6.4 KiB
Dart
191 lines
6.4 KiB
Dart
import 'package:podman/podman.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'support/fake_podman_transport.dart';
|
|
|
|
void main() {
|
|
group('PodmanClient artifacts API', () {
|
|
test('supports list, inspect, pull, add, push, extract, and remove', () async {
|
|
final blobBytes = <int>[1, 2, 3, 4];
|
|
final extractBytes = <int>[9, 8, 7];
|
|
|
|
final transport = FakePodmanTransport()
|
|
..enqueue(
|
|
method: HttpMethod.get,
|
|
path: '/v5.0.0/libpod/artifacts/json',
|
|
responseBody: <Object?>[
|
|
<String, Object?>{
|
|
'Name': 'quay.io/groupware/policy:latest',
|
|
'Digest': 'sha256:abc',
|
|
'Manifest': <String, Object?>{'schemaVersion': 2},
|
|
},
|
|
],
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.get,
|
|
path:
|
|
'/v5.0.0/libpod/artifacts/quay.io%2Fgroupware%2Fpolicy%3Alatest/json',
|
|
responseBody: const <String, Object?>{
|
|
'Name': 'quay.io/groupware/policy:latest',
|
|
'Digest': 'sha256:abc',
|
|
'Manifest': <String, Object?>{'schemaVersion': 2},
|
|
},
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/artifacts/pull',
|
|
queryParameters: const <String, List<String>>{
|
|
'name': <String>['quay.io/groupware/policy:latest'],
|
|
'retry': <String>['5'],
|
|
'retryDelay': <String>['2s'],
|
|
'tlsVerify': <String>['true'],
|
|
},
|
|
statusCode: 200,
|
|
responseBody: const <String, Object?>{'ArtifactDigest': 'sha256:abc'},
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/artifacts/add',
|
|
queryParameters: const <String, List<String>>{
|
|
'name': <String>['quay.io/groupware/policy:latest'],
|
|
'fileName': <String>['policy.json'],
|
|
'fileMIMEType': <String>['application/json'],
|
|
'annotations': <String>['purpose=policy'],
|
|
'append': <String>['true'],
|
|
},
|
|
body: blobBytes,
|
|
statusCode: 201,
|
|
responseBody: const <String, Object?>{'ArtifactDigest': 'sha256:add'},
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path: '/v5.0.0/libpod/artifacts/local/add',
|
|
queryParameters: const <String, List<String>>{
|
|
'name': <String>['quay.io/groupware/policy:latest'],
|
|
'fileName': <String>['policy.json'],
|
|
'path': <String>['/tmp/policy.json'],
|
|
'replace': <String>['true'],
|
|
},
|
|
statusCode: 201,
|
|
responseBody: const <String, Object?>{
|
|
'ArtifactDigest': 'sha256:localadd',
|
|
},
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.post,
|
|
path:
|
|
'/v5.0.0/libpod/artifacts/quay.io%2Fgroupware%2Fpolicy%3Alatest/push',
|
|
queryParameters: const <String, List<String>>{
|
|
'retry': <String>['3'],
|
|
'retrydelay': <String>['1s'],
|
|
'tlsVerify': <String>['false'],
|
|
},
|
|
statusCode: 200,
|
|
responseBody: const <String, Object?>{'ArtifactDigest': 'sha256:abc'},
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.get,
|
|
path:
|
|
'/v5.0.0/libpod/artifacts/quay.io%2Fgroupware%2Fpolicy%3Alatest/extract',
|
|
queryParameters: const <String, List<String>>{
|
|
'title': <String>['policy.json'],
|
|
},
|
|
statusCode: 200,
|
|
responseBody: extractBytes,
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.delete,
|
|
path:
|
|
'/v5.0.0/libpod/artifacts/quay.io%2Fgroupware%2Fpolicy%3Alatest',
|
|
statusCode: 200,
|
|
responseBody: const <String, Object?>{
|
|
'ArtifactDigests': <String>['sha256:abc'],
|
|
},
|
|
)
|
|
..enqueue(
|
|
method: HttpMethod.delete,
|
|
path: '/v5.0.0/libpod/artifacts/remove',
|
|
queryParameters: const <String, List<String>>{
|
|
'artifacts': <String>['quay.io/groupware/policy:latest'],
|
|
'ignore': <String>['true'],
|
|
},
|
|
statusCode: 200,
|
|
responseBody: const <String, Object?>{
|
|
'ArtifactDigests': <String>['sha256:abc'],
|
|
},
|
|
);
|
|
|
|
final client = PodmanClient(transport: transport);
|
|
|
|
final list = await client.listArtifacts();
|
|
expect(list, hasLength(1));
|
|
expect(list.first.digest, 'sha256:abc');
|
|
|
|
final inspected = await client.inspectArtifact(
|
|
'quay.io/groupware/policy:latest',
|
|
);
|
|
expect(inspected.name, 'quay.io/groupware/policy:latest');
|
|
|
|
final pulled = await client.pullArtifact(
|
|
'quay.io/groupware/policy:latest',
|
|
options: const ArtifactPullOptions(
|
|
retry: 5,
|
|
retryDelay: '2s',
|
|
tlsVerify: true,
|
|
),
|
|
);
|
|
expect(pulled.artifactDigest, 'sha256:abc');
|
|
|
|
final added = await client.addArtifact(
|
|
'quay.io/groupware/policy:latest',
|
|
fileName: 'policy.json',
|
|
fileBytes: blobBytes,
|
|
options: const ArtifactAddOptions(
|
|
fileMimeType: 'application/json',
|
|
annotations: <String>['purpose=policy'],
|
|
append: true,
|
|
),
|
|
);
|
|
expect(added.artifactDigest, 'sha256:add');
|
|
|
|
final localAdded = await client.addLocalArtifact(
|
|
'quay.io/groupware/policy:latest',
|
|
path: '/tmp/policy.json',
|
|
fileName: 'policy.json',
|
|
options: const ArtifactAddOptions(replace: true),
|
|
);
|
|
expect(localAdded.artifactDigest, 'sha256:localadd');
|
|
|
|
final pushed = await client.pushArtifact(
|
|
'quay.io/groupware/policy:latest',
|
|
options: const ArtifactPushOptions(
|
|
retry: 3,
|
|
retryDelay: '1s',
|
|
tlsVerify: false,
|
|
),
|
|
);
|
|
expect(pushed.artifactDigest, 'sha256:abc');
|
|
|
|
final extracted = await client.extractArtifact(
|
|
'quay.io/groupware/policy:latest',
|
|
title: 'policy.json',
|
|
);
|
|
expect(extracted, extractBytes);
|
|
|
|
final removed = await client.removeArtifact(
|
|
'quay.io/groupware/policy:latest',
|
|
);
|
|
expect(removed.artifactDigests, contains('sha256:abc'));
|
|
|
|
final batchRemoved = await client.removeArtifacts(
|
|
const ArtifactRemoveOptions(
|
|
artifacts: <String>['quay.io/groupware/policy:latest'],
|
|
ignore: true,
|
|
),
|
|
);
|
|
expect(batchRemoved.artifactDigests, contains('sha256:abc'));
|
|
|
|
transport.expectNoPending();
|
|
});
|
|
});
|
|
}
|