-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1a5f2f
commit fbe8167
Showing
10 changed files
with
307 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Collections; | ||
|
||
namespace Cake.Docker.Tests | ||
{ | ||
public class DockerArgumentComparer : IComparer | ||
{ | ||
public int Compare(object x, object y) | ||
{ | ||
if (ReferenceEquals(x, null) || !(x is DockerArgument)) | ||
{ | ||
throw new ArgumentException(nameof(x)); | ||
} | ||
if (ReferenceEquals(y, null) ||!(y is DockerArgument)) | ||
{ | ||
throw new ArgumentNullException(nameof(y)); | ||
} | ||
var a = (DockerArgument)x; | ||
var b = (DockerArgument)y; | ||
int keyCompare = CompareStrings(a.Key, b.Key); | ||
if (keyCompare != 0) | ||
{ | ||
return keyCompare; | ||
} | ||
int valueCompare = CompareStrings(a.Value, b.Value); | ||
if (valueCompare != 0) | ||
{ | ||
return valueCompare; | ||
} | ||
return a.Quoting.CompareTo(b.Quoting); | ||
|
||
} | ||
static int CompareStrings(string a, string b) | ||
{ | ||
if (a == b) | ||
{ | ||
return 0; | ||
} | ||
if (a == null) | ||
{ | ||
return 1; | ||
} | ||
if (b == null) | ||
{ | ||
return -1; | ||
} | ||
return a.CompareTo(b); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Cake.Core.IO; | ||
using Cake.Docker.Tests.Build; | ||
using NUnit.Framework; | ||
|
||
namespace Cake.Docker.Tests.Registry.Login | ||
{ | ||
[TestFixture] | ||
public class DockerLoginTest | ||
{ | ||
[Test] | ||
public void WhenOnlyPathIsSet_CommandLineIsCorrect() | ||
{ | ||
var fixture = new DockerRegistryLoginFixture | ||
{ | ||
Settings = new DockerRegistryLoginSettings(), | ||
Path = "path" | ||
}; | ||
|
||
var actual = fixture.Run(); | ||
|
||
Assert.That(actual.Args, Is.EqualTo("login path")); | ||
} | ||
[Test] | ||
public void WhenOnlyUsernameIsSet_CommandLineIsCorrect() | ||
{ | ||
var fixture = new DockerRegistryLoginFixture | ||
{ | ||
Settings = new DockerRegistryLoginSettings { Username = "Tubo" }, | ||
Path = "path" | ||
}; | ||
|
||
var actual = fixture.Run(); | ||
|
||
Assert.That(actual.Args, Is.EqualTo("login --username \"Tubo\" path")); | ||
} | ||
[Test] | ||
public void WhenOnlyPasswordIsSet_ArgumentIsRedacted() | ||
{ | ||
var builder = new ProcessArgumentBuilder(); | ||
builder.AppendAll("login", new DockerRegistryLoginSettings { Password = "Tubo" }, new string[0]); | ||
|
||
var actual = builder.RenderSafe(); | ||
|
||
Assert.That(actual, Is.EqualTo("login --password \"[REDACTED]\"")); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Cake.Docker.Tests/Registry/Login/DockerRegistryLoginFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using Cake.Docker; | ||
using Cake.Testing.Fixtures; | ||
using Cake.Core; | ||
using Cake.Core.Diagnostics; | ||
using Cake.Core.IO; | ||
|
||
namespace Cake.Docker.Tests.Build | ||
{ | ||
public class DockerRegistryLoginFixture : ToolFixture<DockerRegistryLoginSettings>, ICakeContext | ||
{ | ||
public string Path { get; set; } | ||
|
||
IFileSystem ICakeContext.FileSystem => FileSystem; | ||
|
||
ICakeEnvironment ICakeContext.Environment => Environment; | ||
|
||
public ICakeLog Log => Log; | ||
|
||
ICakeArguments ICakeContext.Arguments => throw new NotImplementedException(); | ||
|
||
IProcessRunner ICakeContext.ProcessRunner => ProcessRunner; | ||
|
||
public IRegistry Registry => Registry; | ||
|
||
public DockerRegistryLoginFixture(): base("docker") | ||
{ | ||
ProcessRunner.Process.SetStandardOutput(new string[] { }); | ||
} | ||
protected override void RunTool() | ||
{ | ||
this.DockerLogin(Settings, Path); | ||
} | ||
} | ||
} |
Oops, something went wrong.