use<T> static method
Builds image, runs fn with it, and removes it afterwards.
The image is removed even if fn throws. This is the recommended way to
use a custom image in tests:
await DockerImage.use(
DockerImage(path: './fixtures/nginx', tag: 'test-nginx:latest'),
(image) async {
await DockerContainer.use(DockerContainer(image.tag!), (c) async {
// test against c
});
},
);
Implementation
static Future<T> use<T>(
DockerImage image,
Future<T> Function(DockerImage) fn,
) async {
await image.build();
try {
return await fn(image);
} finally {
await image.remove();
}
}