diff --git a/Ductus.FluentDocker.Tests/Model/Builders/FileBuilder/CopyCommandTests.cs b/Ductus.FluentDocker.Tests/Model/Builders/FileBuilder/CopyCommandTests.cs new file mode 100644 index 0000000..3092511 --- /dev/null +++ b/Ductus.FluentDocker.Tests/Model/Builders/FileBuilder/CopyCommandTests.cs @@ -0,0 +1,30 @@ +using Ductus.FluentDocker.Model.Builders.FileBuilder; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Ductus.FluentDocker.Tests.Model.Builders.FileBuilder +{ + [TestClass] + public class CopyCommandTests + { + [TestMethod] + public void CopyCommandShallDoubleQuoteWrapAllArguments() + { + var cp = new CopyCommand("entrypoint.sh", "/worker/entrypoint.sh"); + Assert.AreEqual("COPY [\"entrypoint.sh\",\"/worker/entrypoint.sh\"]", cp.ToString()); + } + + [TestMethod] + public void CopyCommandShallNotAddDoubleQuoteWrapForArgumentsWithDoubleQote() + { + var cp = new CopyCommand("entrypoint.sh", "\"/worker/entrypoint.sh\""); + Assert.AreEqual("COPY [\"entrypoint.sh\",\"/worker/entrypoint.sh\"]", cp.ToString()); + } + + [TestMethod] + public void CopyCommandShallEnsureBothSidesAreDoubleQotedEvenIfArgumentHasOnlyOneSide() + { + var cp = new CopyCommand("entrypoint.sh", "\"/worker/entrypoint.sh"); + Assert.AreEqual("COPY [\"entrypoint.sh\",\"/worker/entrypoint.sh\"]", cp.ToString()); + } + } +} \ No newline at end of file diff --git a/Ductus.FluentDocker/Builders/FileBuilder.cs b/Ductus.FluentDocker/Builders/FileBuilder.cs index 4a558af..9dd2590 100644 --- a/Ductus.FluentDocker/Builders/FileBuilder.cs +++ b/Ductus.FluentDocker/Builders/FileBuilder.cs @@ -326,7 +326,7 @@ private void CopyToWorkDir(TemplateString workingFolder) private void RenderDockerfile(TemplateString workingFolder) { - if (Directory.Exists(workingFolder)) + if (!Directory.Exists(workingFolder)) { Directory.CreateDirectory(workingFolder); } diff --git a/Ductus.FluentDocker/Model/Builders/FileBuilder/CopyCommand.cs b/Ductus.FluentDocker/Model/Builders/FileBuilder/CopyCommand.cs index a3ece07..1bc2901 100644 --- a/Ductus.FluentDocker/Model/Builders/FileBuilder/CopyCommand.cs +++ b/Ductus.FluentDocker/Model/Builders/FileBuilder/CopyCommand.cs @@ -19,8 +19,8 @@ public class CopyCommand : ICommand public CopyCommand(TemplateString from, TemplateString to, TemplateString chownUserAndGroup = null, TemplateString fromAlias = null) { - From = from.Rendered; - To = to.Rendered; + From = from.Rendered.WrapWithChar("\""); + To = to.Rendered.WrapWithChar("\""); if (null != chownUserAndGroup && !string.IsNullOrEmpty(chownUserAndGroup.Rendered)) { Chown = chownUserAndGroup.Rendered;