Skip to content

Commit

Permalink
All hooks now calls dispose on exception.
Browse files Browse the repository at this point in the history
This completely fixes the issue #70. All unittests uses the new ```Fd``` static class since new Build() and new Hosts() will be removed in 3.0.0. Updated to version 2.6.3.
  • Loading branch information
Mario Toffia committed Oct 15, 2018
1 parent f131a71 commit 7138683
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 114 deletions.
4 changes: 2 additions & 2 deletions Ductus.FluentDocker.MsTest/Ductus.FluentDocker.MsTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netcoreapp1.1;netcoreapp2.0;net452</TargetFrameworks>
<VersionPrefix>2.6.2</VersionPrefix>
<VersionPrefix>2.6.3</VersionPrefix>
<AssemblyTitle>Ductus.FluentDocker.MsTest</AssemblyTitle>
<Authors>Mario Toffia</Authors>
<PackageLicenseUrl>https://github.com/mariotoffia/FluentDocker/blob/master/LICENSE</PackageLicenseUrl>
Expand All @@ -19,7 +19,7 @@ Documentation: https://github.com/mariotoffia/FluentDocker
<Copyright>© 2016, 2017, 2018 Mario Toffia</Copyright>
<DefineConstants Condition=" '$(TargetFramework)' == 'netcoreapp1.1' ">$(DefineConstants);COREFX</DefineConstants>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>2.6.2</Version>
<Version>2.6.3</Version>
<AssemblyOriginatorKeyFile>..\keypair.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void RunPostgresContainerAndCheckThatAllProcessesAreRunning()
Debug.WriteLine(proc.ToString());

IsTrue(proc.Rows.Any(x => x.Command == "bash /usr/local/bin/docker-entrypoint.sh postgres"));
IsTrue(proc.Rows.Any(x => x.Command == "/usr/local/bin/postgres -D /var/lib/postgresql/data -c listen_addresses="));
IsTrue(proc.Rows.Any(x => x.Command == "pg_ctl -D /var/lib/postgresql/data -m fast -w stop"));
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Ductus.FluentDocker.Builders;
using Ductus.FluentDocker.Common;
using Ductus.FluentDocker.Extensions;
using Ductus.FluentDocker.Model.Builders;
using Ductus.FluentDocker.Model.Common;
using Ductus.FluentDocker.Model.Containers;
using Ductus.FluentDocker.Services;
using Ductus.FluentDocker.Services.Extensions;
using Ductus.FluentDocker.Tests.Extensions;
Expand All @@ -32,7 +27,7 @@ public void BuildContainerRenderServiceInStoppedMode()
{
using (
var container =
new Builder().UseContainer()
Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
.Build())
Expand Down Expand Up @@ -60,11 +55,11 @@ public void UseStaticBuilderWillAlwaysRunDisposeOnContainer()
[TestMethod]
public void UseStaticBuilderAsExtension()
{
var build = Fd.Build(c => c.UseContainer()
var build = Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.ExposePort(5432)
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
.WaitForPort("5432/tcp", TimeSpan.FromSeconds(30)));
.WaitForPort("5432/tcp", TimeSpan.FromSeconds(30));

build.Container(svc =>
{
Expand All @@ -80,7 +75,7 @@ public void BuildAndStartContainerWithKeepContainerWillLeaveContainerInArchive()
string id;
using (
var container =
new Builder().UseContainer()
Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
.KeepContainer()
Expand All @@ -93,8 +88,7 @@ public void BuildAndStartContainerWithKeepContainerWillLeaveContainerInArchive()

// We shall have the container as stopped by now.
var cont =
new Hosts()
.Discover()
Fd.Discover()
.Select(host => host.GetContainers().FirstOrDefault(x => x.Id == id))
.FirstOrDefault(container => null != container);

Expand All @@ -107,7 +101,7 @@ public void BuildAndStartContainerWithCustomEnvironmentWillBeReflectedInGetConfi
{
using (
var container =
new Builder().UseContainer()
Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
.Build()
Expand All @@ -125,7 +119,7 @@ public void ExplicitPortMappingShouldWork()
{
using (
var container =
new Builder().UseContainer()
Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.ExposePort(40001, 5432)
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
Expand All @@ -142,7 +136,7 @@ public void ImplicitPortMappingShouldWork()
{
using (
var container =
new Builder().UseContainer()
Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.ExposePort(5432)
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
Expand All @@ -159,7 +153,7 @@ public void WaitForPortShallWork()
{
using (
var container =
new Builder().UseContainer()
Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.ExposePort(5432)
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
Expand All @@ -177,7 +171,7 @@ public void WaitForProcessShallWork()
{
using (
var container =
new Builder().UseContainer()
Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.ExposePort(5432)
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
Expand All @@ -199,7 +193,7 @@ public async Task VolumeMappingShallWork()

using (
var container =
new Builder().UseContainer()
Fd.UseContainer()
.UseImage("nginx:1.13.6-alpine")
.ExposePort(80)
.Mount(hostPath, "/usr/share/nginx/html", MountType.ReadOnly)
Expand All @@ -218,10 +212,7 @@ public async Task VolumeMappingShallWork()
}
finally
{
if (Directory.Exists(hostPath))
{
Directory.Delete(hostPath, true);
}
if (Directory.Exists(hostPath)) Directory.Delete(hostPath, true);
}
}
}
Expand All @@ -235,7 +226,7 @@ public async Task VolumeMappingWithSpacesShallWork()

using (
var container =
new Builder().UseContainer()
Fd.UseContainer()
.UseImage("nginx:1.13.6-alpine")
.ExposePort(80)
.Mount(hostPath, "/usr/share/nginx/html", MountType.ReadOnly)
Expand All @@ -254,10 +245,7 @@ public async Task VolumeMappingWithSpacesShallWork()
}
finally
{
if (Directory.Exists(hostPath))
{
Directory.Delete(hostPath, true);
}
if (Directory.Exists(hostPath)) Directory.Delete(hostPath, true);
}
}
}
Expand All @@ -269,7 +257,7 @@ public void CopyFromRunningContainerShallWork()
Directory.CreateDirectory(fullPath);
try
{
using (new Builder().UseContainer()
using (Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.ExposePort(5432)
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
Expand All @@ -283,10 +271,7 @@ public void CopyFromRunningContainerShallWork()
}
finally
{
if (Directory.Exists(fullPath))
{
Directory.Delete(fullPath, true);
}
if (Directory.Exists(fullPath)) Directory.Delete(fullPath, true);
}
}

Expand All @@ -297,7 +282,7 @@ public void CopyBeforeDisposeContainerShallWork()
Directory.CreateDirectory(fullPath);
try
{
using (new Builder().UseContainer()
using (Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.ExposePort(5432)
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
Expand All @@ -312,10 +297,7 @@ public void CopyBeforeDisposeContainerShallWork()
}
finally
{
if (Directory.Exists(fullPath))
{
Directory.Delete(fullPath, true);
}
if (Directory.Exists(fullPath)) Directory.Delete(fullPath, true);
}
}

Expand All @@ -327,7 +309,7 @@ public void ExportToTarFileWhenDisposeShallWork()
Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
try
{
using (new Builder().UseContainer()
using (Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.ExposePort(5432)
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
Expand All @@ -341,11 +323,7 @@ public void ExportToTarFileWhenDisposeShallWork()
}
finally
{
if (File.Exists(fullPath))
{
// ReSharper disable once AssignNullToNotNullAttribute
Directory.Delete(Path.GetDirectoryName(fullPath), true);
}
if (File.Exists(fullPath)) Directory.Delete(Path.GetDirectoryName(fullPath), true);
}
}

Expand All @@ -356,7 +334,7 @@ public void ExportExploadedWhenDisposeShallWork()
Directory.CreateDirectory(fullPath);
try
{
using (new Builder().UseContainer()
using (Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.ExposePort(5432)
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
Expand All @@ -373,10 +351,7 @@ public void ExportExploadedWhenDisposeShallWork()
}
finally
{
if (Directory.Exists(fullPath))
{
Directory.Delete(fullPath, true);
}
if (Directory.Exists(fullPath)) Directory.Delete(fullPath, true);
}
}

Expand All @@ -393,7 +368,7 @@ public void ExportWithConditionDisposeShallWork()
try
{
// ReSharper disable once AccessToModifiedClosure
using (new Builder().UseContainer()
using (Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.ExposePort(5432)
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
Expand All @@ -408,11 +383,7 @@ public void ExportWithConditionDisposeShallWork()
}
finally
{
if (File.Exists(fullPath))
{
// ReSharper disable once AssignNullToNotNullAttribute
Directory.Delete(Path.GetDirectoryName(fullPath), true);
}
if (File.Exists(fullPath)) Directory.Delete(Path.GetDirectoryName(fullPath), true);
}
}

Expand All @@ -427,17 +398,16 @@ public void CopyToRunningContainerShallWork()

try
{
IList<Diff> before;
using (
var container =
new Builder().UseContainer()
Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.ExposePort(5432)
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
.Build()
.Start()
.WaitForProcess("postgres", 30000 /*30s*/)
.Diff(out before)
.Diff(out var before)
.CopyTo("/bin", fullPath))
{
var after = container.Diff();
Expand All @@ -448,22 +418,19 @@ public void CopyToRunningContainerShallWork()
}
finally
{
if (Directory.Exists(fullPath))
{
Directory.Delete(fullPath, true);
}
if (Directory.Exists(fullPath)) Directory.Delete(fullPath, true);
}
}

[TestMethod]
public void ReuseOfExistingContainerShallWork()
{
using (new Builder()
using (Fd
.UseContainer()
.UseImage("postgres:9.6-alpine")
.WithName("reusable-name")
.Build())
using (new Builder()
using (Fd
.UseContainer()
.ReuseIfExists()
.UseImage("postgres:9.6-alpine")
Expand Down
Loading

0 comments on commit 7138683

Please sign in to comment.