Skip to content

Commit

Permalink
Fixes CopyCommand, closes issue #187
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotoffia committed Apr 20, 2021
1 parent 3267291 commit 6b204f4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
2 changes: 1 addition & 1 deletion Ductus.FluentDocker/Builders/FileBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions Ductus.FluentDocker/Model/Builders/FileBuilder/CopyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6b204f4

Please sign in to comment.