Skip to content

Commit

Permalink
Adds initial corrected and generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaMarkic committed Feb 8, 2024
1 parent 4377b0d commit f07b464
Show file tree
Hide file tree
Showing 73 changed files with 687 additions and 613 deletions.
18 changes: 9 additions & 9 deletions args-parser-2.linq
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Query Kind="Statements" />

string path = @"Compose\Cp";
string path = @"Compose\Run";
string file = Path.Combine(Path.GetDirectoryName(Util.CurrentQueryPath)!, $@"src\Cake.Docker\{path}\args.txt");
//string file = @"D:\GitProjects\Righthand\Cake\Cake.Docker\src\Cake.Docker\Compose\Up\args.txt";
string[] lines = File.ReadAllLines(file);
Expand Down Expand Up @@ -34,7 +34,7 @@ string className = path.Replace(@"\", "");
"/// <summary>".Dump();
$"/// Settings for docker {string.Join(" ", path.Split('\\').Select(p => p.ToLower()))}.".Dump();
"/// </summary>".Dump();
$"public sealed class Docker{className}Settings : AutoToolSettings".Dump();
$"public sealed class Docker{className}Settings : DockerComposeSettings".Dump();
"{".Dump();
foreach (var pair in data)
{
Expand Down Expand Up @@ -92,29 +92,29 @@ foreach (var pair in data)
case "int?":
case "int":
case "uint":
netType = "int";
netType = "int?";
break;
case "value":
if (info.EndsWith("[])"))
{
netType = "string[]";
netType = "string[]?";
}
else
{
netType = "string";
netType = "string=";
}
break;
case "string":
netType = "string";
netType = "string?";
break;
case "strings":
netType = "string[]";
netType = "string[]?";
break;
case "stringArray":
netType = "string[]";
netType = "string[]?";
break;
default:
netType = "bool";
netType = "bool?";
break;
}
if (type == "stringArray")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DockerComposeBuildFixture : ToolFixture<DockerComposeBuildSettings>

ICakeConfiguration ICakeContext.Configuration => throw new NotImplementedException();

public DockerComposeBuildFixture(): base("docker-compose")
public DockerComposeBuildFixture(): base("docker")
{
ProcessRunner.Process.SetStandardOutput(Array.Empty<string>());
}
Expand Down
33 changes: 29 additions & 4 deletions src/Cake.Docker.Tests/Compose/Build/DockerComposeBuildTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,50 @@ public void WhenParallelFlagIsSet_CommandLineIsCorrect()
{
var fixture = new DockerComposeBuildFixture
{
Settings = new DockerComposeBuildSettings { Parallel = true },
Settings = new DockerComposeBuildSettings { Parallel = 2 },
};

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("build --parallel"));
Assert.That(actual.Args, Is.EqualTo("compose build --parallel 2"));
}

[Test]
public void WhenParallelFlagIsSetToFalse_CommandLineDoesNotHaveRm()
{
var fixture = new DockerComposeBuildFixture
{
Settings = new DockerComposeBuildSettings { Parallel = false },
Settings = new DockerComposeBuildSettings { Parallel = null },
};

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("build"));
Assert.That(actual.Args, Is.EqualTo("compose build"));
}

[Test]
public void WhenFilesFlagIsUsed_CommandLineIncludesIt()
{
var fixture = new DockerComposeBuildFixture
{
Settings = new DockerComposeBuildSettings { File = ["alfa.yaml"] },
};

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("compose build --file \"alfa.yaml\""));
}
[Test]
public void WhenTwoFilesAreProvided_CommandLineIncludesThem()
{
var fixture = new DockerComposeBuildFixture
{
Settings = new DockerComposeBuildSettings { File = ["alfa.yaml", "beta.yaml"] },
};

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("compose build --file \"alfa.yaml\" --file \"beta.yaml\""));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class DockerComposeExecFixture : ToolFixture<DockerComposeExecSettings>,

ICakeConfiguration ICakeContext.Configuration => throw new NotImplementedException();

public DockerComposeExecFixture() : base("docker-compose")
public DockerComposeExecFixture() : base("docker")
{
ProcessRunner.Process.SetStandardOutput(Array.Empty<string>());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void WhenDisablePseudoTtyIsSet_AddsItsArgument()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("exec service command"));
Assert.That(actual.Args, Is.EqualTo("compose exec service command"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class DockerComposePortFixture : ToolFixture<DockerComposePortSettings>,

ICakeConfiguration ICakeContext.Configuration => throw new NotImplementedException();

public DockerComposePortFixture(): base("docker-compose")
public DockerComposePortFixture(): base("docker")
{
ProcessRunner.Process.SetStandardOutput(Array.Empty<string>());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Cake.Docker.Tests/Compose/Port/DockerComposePortTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void WhenServiceAndPortAreSet_CommandLineIsCorrect()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("port serviceA 8080"));
Assert.That(actual.Args, Is.EqualTo("compose port serviceA 8080"));
}

[Test]
Expand All @@ -32,7 +32,7 @@ public void WhenServiceAndPortAndIndexAreSet_CommandLineIsCorrect()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("port --index=2 serviceA 8080"));
Assert.That(actual.Args, Is.EqualTo("compose port --index 2 serviceA 8080"));
}
}
}
2 changes: 1 addition & 1 deletion src/Cake.Docker.Tests/Compose/Ps/DockerComposePsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DockerComposePsFixture : ToolFixture<DockerComposePsSettings>, ICak

ICakeConfiguration ICakeContext.Configuration => throw new NotImplementedException();

public DockerComposePsFixture(): base("docker-compose")
public DockerComposePsFixture(): base("docker")
{
ProcessRunner.Process.SetStandardOutput(Array.Empty<string>());
}
Expand Down
8 changes: 4 additions & 4 deletions src/Cake.Docker.Tests/Compose/Ps/DockerComposePsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void WhenNoServiceAreSet_CommandLineIsCorrect()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("ps --filter filter"));
Assert.That(actual.Args, Is.EqualTo("compose ps --filter filter"));
}

[Test]
Expand All @@ -29,7 +29,7 @@ public void WhenSingleFilterIsSet_CommandLineIsCorrect()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("ps --filter filter serviceA serviceB"));
Assert.That(actual.Args, Is.EqualTo("compose ps --filter filter serviceA serviceB"));
}

[Test]
Expand All @@ -43,7 +43,7 @@ public void WhenMultipleFilterIsSet_CommandLineIsCorrect()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("ps --filter filter1 --filter filter2 serviceA serviceB"));
Assert.That(actual.Args, Is.EqualTo("compose ps --filter filter1 --filter filter2 serviceA serviceB"));
}

[Test]
Expand All @@ -57,7 +57,7 @@ public void WhenQuietIsSet_CommandLineIsCorrect()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("ps --quiet serviceA serviceB serviceC"));
Assert.That(actual.Args, Is.EqualTo("compose ps --quiet serviceA serviceB serviceC"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DockerComposeRunFixture : ToolFixture<DockerComposeRunSettings>, IC

ICakeConfiguration ICakeContext.Configuration => throw new NotImplementedException();

public DockerComposeRunFixture(): base("docker-compose")
public DockerComposeRunFixture(): base("docker")
{
ProcessRunner.Process.SetStandardOutput(Array.Empty<string>());
}
Expand Down
6 changes: 3 additions & 3 deletions src/Cake.Docker.Tests/Compose/Run/DockerComposeRunTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void WhenEntrypointIsSet_CommandLineIsCorrect()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("run --entrypoint \"somepoint\" cmd"));
Assert.That(actual.Args, Is.EqualTo("compose run --entrypoint \"somepoint\" cmd"));
}

[Test]
Expand All @@ -30,7 +30,7 @@ public void WhenVolumeIsSet_CommandLineIsCorrect()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("run --volume \"host:guest\" cmd"));
Assert.That(actual.Args, Is.EqualTo("compose run --volume \"host:guest\" cmd"));
}
[Test]
public void WhenTwoVolumesAreSet_CommandLineIsCorrect()
Expand All @@ -43,7 +43,7 @@ public void WhenTwoVolumesAreSet_CommandLineIsCorrect()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("run --volume \"host:guest\" --volume \"host2:guest2\" cmd"));
Assert.That(actual.Args, Is.EqualTo("compose run --volume \"host:guest\" --volume \"host2:guest2\" cmd"));
}
}
}
2 changes: 1 addition & 1 deletion src/Cake.Docker.Tests/Compose/Up/DockerComposeUpFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DockerComposeUpFixture : ToolFixture<DockerComposeUpSettings>, ICak

ICakeConfiguration ICakeContext.Configuration => throw new NotImplementedException();

public DockerComposeUpFixture(): base("docker-compose")
public DockerComposeUpFixture(): base("docker")
{
ProcessRunner.Process.SetStandardOutput(Array.Empty<string>());
}
Expand Down
10 changes: 5 additions & 5 deletions src/Cake.Docker.Tests/Compose/Up/DockerComposeUpTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void WhenDetachedIsSet_CommandLineIsCorrect()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("up --detach service"));
Assert.That(actual.Args, Is.EqualTo("compose up --detach service"));
}

[Test]
Expand All @@ -30,7 +30,7 @@ public void WhenNoColorIsSet_CommandLineIsCorrect()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("up --no-color service"));
Assert.That(actual.Args, Is.EqualTo("compose up --no-color service"));
}
[Test]
public void WhenWaitIsSet_CommandLineIsCorrect()
Expand All @@ -43,7 +43,7 @@ public void WhenWaitIsSet_CommandLineIsCorrect()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("up --wait service"));
Assert.That(actual.Args, Is.EqualTo("compose up --wait service"));
}

[Test]
Expand All @@ -56,7 +56,7 @@ public void WhenNoServiceIsSet_CommandLineIsCorrect()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("up --abort-on-container-exit --remove-orphans"));
Assert.That(actual.Args, Is.EqualTo("compose up --abort-on-container-exit --remove-orphans"));
}
[Test]
public void WhenWaitTimeoutIsSet_CommandLineIsCorrect()
Expand All @@ -68,7 +68,7 @@ public void WhenWaitTimeoutIsSet_CommandLineIsCorrect()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("up --wait-timeout 1"));
Assert.That(actual.Args, Is.EqualTo("compose up --wait-timeout 1"));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NUnit.Framework;

namespace Cake.Docker.Tests.Build
namespace Cake.Docker.Tests.Image.Build
{
[TestFixture]
public class DockerBuildTest
Expand All @@ -16,20 +16,20 @@ public void WhenOnlyPathIsSet_CommandLineIsCorrect()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("build \"path\""));
Assert.That(actual.Args, Is.EqualTo("image build \"path\""));
}
[Test]
public void WhenRmFlagIsSet_CommandLineIsCorrect()
{
var fixture = new DockerBuildFixture
{
Settings = new DockerImageBuildSettings { Rm = true },
Settings = new DockerImageBuildSettings { Rm = true },
Path = "path"
};

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("build --rm=True \"path\""));
Assert.That(actual.Args, Is.EqualTo("image build --rm=True \"path\""));
}

[Test]
Expand All @@ -43,7 +43,7 @@ public void WhenRmFlagIsSetToFalse_CommandLineDoesNotHaveRm()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("build --rm=False \"path\""));
Assert.That(actual.Args, Is.EqualTo("image build --rm=False \"path\""));
}

[Test]
Expand All @@ -57,7 +57,7 @@ public void WhenForceRmFlagIsSetToFalse_CommandLineDoesNotHaveForceRm()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("build \"path\""));
Assert.That(actual.Args, Is.EqualTo("image build \"path\""));
}

[Test]
Expand All @@ -71,7 +71,7 @@ public void WhenPullFlagIsSetToFalse_CommandLineDoesNotHavePull()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("build \"path\""));
Assert.That(actual.Args, Is.EqualTo("image build \"path\""));
}

[Test]
Expand All @@ -85,7 +85,7 @@ public void WhenPullFlagIsSetToTrue_CommandLineDoesHavePull()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo("build --pull \"path\""));
Assert.That(actual.Args, Is.EqualTo("image build --pull \"path\""));
}
[Test]
public void WhenPathHasSpaces_ArgumentIsQuoted()
Expand All @@ -98,7 +98,7 @@ public void WhenPathHasSpaces_ArgumentIsQuoted()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo(@"build ""C:\Some where"""));
Assert.That(actual.Args, Is.EqualTo(@"image build ""C:\Some where"""));
}
[Test]
public void WhenPathHasSingleQuote_ArgumentIsQuoted()
Expand All @@ -111,7 +111,7 @@ public void WhenPathHasSingleQuote_ArgumentIsQuoted()

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo(@"build """""""));
Assert.That(actual.Args, Is.EqualTo(@"image build """""""));
}
[TestCase("\"test\"")]
[TestCase(" \"test\"")]
Expand All @@ -127,7 +127,7 @@ public void WhenPathIsQuoted_ArgumentIsNotDoubleQuoted(string path)

var actual = fixture.Run();

Assert.That(actual.Args, Is.EqualTo($"build {path}"));
Assert.That(actual.Args, Is.EqualTo($"image build {path}"));
}
}
}
Loading

0 comments on commit f07b464

Please sign in to comment.