New Features on Docker Compose Fluent API
This release adds a new Wait method called WaitForHttp. It uses one of HTTP POST, GET, PUT, DELETE with or without body to perform it's wait. In addition it is possible to add a lambda to determine if e.g. responses are OK or if it should abandon wait.
In addition compose fluent API now supports:
- ExportOnDispose
- ExportExploadedOnDispose
- CopyOnStart
- CopyOnDispose
- WaitForPort
- WaitForProcess
- ExecuteOnRunning
- ExecuteOnDisposing
In order to use those functions, you have to name the container name and therefore it is possible to address several containers in same compose project. For example it is possible to do e.g. this:
var file = Path.Combine(Directory.GetCurrentDirectory(),
(TemplateString) "Resources/ComposeTests/WordPress/docker-compose.yml");
// @formatter:off
using (new Builder()
.UseContainer()
.UseCompose()
.FromFile(file)
.RemoveOrphans()
.WaitForHttp("wordpress", "http://localhost:8000/wp-admin/install.php", continuation: (resp, cnt) =>
resp.Body.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1 ? 0 : 500)
.Build().Start())
// @formatter:on
{
// Since we have waited - this shall now always work.
var installPage = await "http://localhost:8000/wp-admin/install.php".Wget();
Assert.IsTrue(installPage.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1);
}
This example waits until it gets a specific response from the wordpress container. There are a few more in the unit test section.