Skip to content

Commit

Permalink
Fixes #44 re-command arguments are also inserted as post-command argu…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
MihaMarkic committed Jul 25, 2018
1 parent 8ff3d86 commit 28f0730
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/Cake.Docker.Tests/ArgumentsBuilderExtensionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ArgumentsBuilderExtensionTest
public static PropertyInfo DecoratedStringProperty => GetProperty(nameof(TestSettings.DecoratedString));
public static PropertyInfo DecoratedBoolProperty => GetProperty(nameof(TestSettings.DecoratedBool));
public static PropertyInfo DecoratedStringsProperty => GetProperty(nameof(TestSettings.DecoratedStrings));
public static PropertyInfo PreCommandValueProperty => GetProperty(nameof(TestSettings.PreCommandValue));
public static PropertyInfo GetProperty(string name)
{
return typeof(TestSettings).GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
Expand Down Expand Up @@ -340,6 +341,26 @@ public void WhenDecoratedStrings_FormatsProperly()
Assert.That(actual, Is.EqualTo("-e One=1 -e Two=2"));
}
}
[TestFixture]
public class GetArgumentFromProperty: ArgumentsBuilderExtensionTest
{
[Test]
public void WhenPreCommand_DoesNotAppearInNormalCommands()
{
TestSettings input = new TestSettings { PreCommandValue = "preCommand" };
var actual = ArgumentsBuilderExtension.GetArgumentFromProperty(PreCommandValueProperty, input, preCommand: false, isSecret: false);

Assert.That(actual.Count(), Is.Zero);
}
[Test]
public void WhenPreCommand_ItAppearsInPreCommands()
{
TestSettings input = new TestSettings { PreCommandValue = "preCommand" };
var actual = ArgumentsBuilderExtension.GetArgumentFromProperty(PreCommandValueProperty, input, preCommand: true, isSecret: false);

Assert.That(actual.Count(), Is.EqualTo(1));
}
}

public class TestSettings: AutoToolSettings
{
Expand All @@ -359,6 +380,8 @@ public class TestSettings: AutoToolSettings
public bool DecoratedBool { get; set; }
[AutoProperty(Format = "-e {1}")]
public string[] DecoratedStrings { get; set; }
[AutoProperty(PreCommand = true)]
public string PreCommandValue { get; set; }
protected override string[] CollectSecretProperties()
{
return new[] { nameof(Password) };
Expand Down
3 changes: 2 additions & 1 deletion src/Cake.Docker/ArgumentsBuilderExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ where a.HasValue
yield return new DockerArgument(null, GetArgumentFromAutoProperty(autoPropertyAttribute, property, property.GetValue(settings)), DockerArgumentQuoting.Unquoted);
}
}
else if (!preCommand || (autoPropertyAttribute != null && autoPropertyAttribute.PreCommand && preCommand))
else if (!preCommand && (autoPropertyAttribute == null || !autoPropertyAttribute.PreCommand)
|| (autoPropertyAttribute != null && autoPropertyAttribute.PreCommand && preCommand))
{
if (property.PropertyType == typeof(bool))
{
Expand Down

0 comments on commit 28f0730

Please sign in to comment.