Skip to content

Commit

Permalink
Merge pull request #206 from mariotoffia/feature-deleteif-exist
Browse files Browse the repository at this point in the history
Feature DeleteIfExists on ContainerBuilder
  • Loading branch information
mariotoffia authored Sep 14, 2021
2 parents c690224 + 4226315 commit 786c24a
Show file tree
Hide file tree
Showing 26 changed files with 818 additions and 12 deletions.
29 changes: 29 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,34 @@
"sudoer",
"typeof",
"wdlp"
],
"yaml.customTags": [
"!And",
"!And sequence",
"!If",
"!If sequence",
"!Not",
"!Not sequence",
"!Equals",
"!Equals sequence",
"!Or",
"!Or sequence",
"!FindInMap",
"!FindInMap sequence",
"!Base64",
"!Join",
"!Join sequence",
"!Cidr",
"!Ref",
"!Sub",
"!Sub sequence",
"!GetAtt",
"!GetAZs",
"!ImportValue",
"!ImportValue sequence",
"!Select",
"!Select sequence",
"!Split",
"!Split sequence"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Documentation: https://github.com/mariotoffia/FluentDocker
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GitVersionTask" Version="5.3.7" PrivateAssets="All" />
<!--<PackageReference Include="GitVersionTask" Version="5.3.7" PrivateAssets="All" />-->
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.1.11" />
<PackageReference Include="MSTest.TestFramework" Version="1.1.11" />
Expand Down
8 changes: 7 additions & 1 deletion Ductus.FluentDocker.Tests/Ductus.FluentDocker.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<EmbeddedResource Include="Compose\redis\Dockerfile" />
</ItemGroup>

<ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<None Update="Resources\ComposeTests\MongoDbAndNetwork\docker-compose.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -60,6 +60,12 @@
<None Update="Resources\Scripts\envtest.sh">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Model\Containers\inspect.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Model\Containers\inspect_no_create.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ public static void Initialize(TestContext ctx)
Utilities.EnsureImage("postgres:9.6-alpine", TimeSpan.FromMinutes(1.0));
}

[TestMethod]
[TestCategory("CI")]
public void VersionInfoShallBePossibleToRetrieve()
{
var v = Fd.Version();
Assert.IsTrue(v != null && v.Length > 0);
}
[TestMethod]
[TestCategory("CI")]
public void BuildContainerRenderServiceInStoppedMode()
Expand Down Expand Up @@ -500,6 +493,31 @@ public void ReuseOfExistingContainerShallWork()
}
}

[TestMethod]
[TestCategory("CI")]
public void DeleteIfExistsWithContainerShallWork()
{
var name = Guid.NewGuid().ToString();

var container = Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.WithName($"name-{name}")
.Build();

var id = container.Id;

using (var c = Fd
.UseContainer()
.DeleteIfExists()
.UseImage("postgres:9.6-alpine")
.WithName($"name-{name}")
.Build())
{
// Ids should not be equal - since deleted and then created.
AreNotEqual(id, c.Id);
}
}

[TestMethod]
[TestCategory("CI")]
public void PullContainerBeforeRunningShallWork()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,23 @@ public void Issue94()
Assert.AreEqual("1", zookeeper.InstanceId);
}
}

[TestMethod]
public void Issue190()
{
var file = Path.Combine(Directory.GetCurrentDirectory(),
(TemplateString)"Resources/hellotest/docker-compose.yml");

using (var svc = Fd.UseContainer()
.FromComposeFile(file)
.RemoveNonTaggedImages()
.ForceBuild()
.Build()
.Start())
{
}

// Now the custom build image should be removed!
}
}
}
22 changes: 22 additions & 0 deletions Ductus.FluentDocker.Tests/Model/Containers/ContainerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Ductus.FluentDocker.Model.Common;
using Ductus.FluentDocker.Extensions;
using Ductus.FluentDocker.Model.Containers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;

namespace Ductus.FluentDocker.Tests.Model.Containers
{
[TestClass]
public class ContainerTests
{
[TestMethod]
public void TestWithNoCreated()
{
var data = ((TemplateString)"Model/Containers/inspect_no_create.json").FromFile();
var obj = JsonConvert.DeserializeObject<Container>(data);

Assert.AreEqual(obj.Created, default(System.DateTime));
}

}
}
Loading

0 comments on commit 786c24a

Please sign in to comment.