Skip to content

Commit

Permalink
Fix RegistryCredentials equality (#1313) (#1352)
Browse files Browse the repository at this point in the history
  • Loading branch information
varunpuranik authored Jun 18, 2019
1 parent 95a657a commit c6b0ba9
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.Azure.Devices.Edge.Util;
using Newtonsoft.Json;

public class DockerRuntimeConfig : IEquatable<DockerRuntimeConfig>
{
static readonly DictionaryComparer<string, RegistryCredentials> RegistryCredentialsDictionaryComparer = new DictionaryComparer<string, RegistryCredentials>();

public DockerRuntimeConfig(string minDockerVersion, string loggingOptions)
: this(minDockerVersion, null, loggingOptions)
{
Expand Down Expand Up @@ -38,7 +41,7 @@ public DockerRuntimeConfig(string minDockerVersion, IDictionary<string, Registry

public bool Equals(DockerRuntimeConfig other) =>
other != null && this.MinDockerVersion == other.MinDockerVersion && this.LoggingOptions == other.LoggingOptions &&
EqualityComparer<IDictionary<string, RegistryCredentials>>.Default.Equals(this.RegistryCredentials, other.RegistryCredentials);
RegistryCredentialsDictionaryComparer.Equals(this.RegistryCredentials, other.RegistryCredentials);

public override int GetHashCode()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public RegistryCredentials(string address, string username, string password)
public override bool Equals(object obj) => this.Equals(obj as RegistryCredentials);

public bool Equals(RegistryCredentials other) =>
other != null &&
this.Address == other.Address &&
this.Username == other.Username &&
this.Password == other.Password;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft. All rights reserved.
namespace Microsoft.Azure.Devices.Edge.Agent.Docker.Test
{
using System.Collections.Generic;
using Microsoft.Azure.Devices.Edge.Util.Test.Common;
using Xunit;

[Unit]
public class DockerRuntimeConfigTest
{
[Fact]
public void EqualityTest()
{
var drc1 = new DockerRuntimeConfig(
"1.0",
new Dictionary<string, RegistryCredentials>
{
["r1"] = new RegistryCredentials("foo.azurecr.io", "foo", "foo")
});

var drc2 = new DockerRuntimeConfig(
"1.0",
new Dictionary<string, RegistryCredentials>
{
["r1"] = new RegistryCredentials("foo.azurecr.io", "foo", "foo")
});

Assert.Equal(drc1, drc2);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Microsoft. All rights reserved.
namespace Microsoft.Azure.Devices.Edge.Agent.Docker.Test
{
using System.Collections.Generic;
using Microsoft.Azure.Devices.Edge.Util.Test.Common;
using Xunit;

[Unit]
public class DockerRuntimeInfoTest
{
[Fact]
public void EqualityTest()
{
var dri1 = new DockerRuntimeInfo(
"docker",
new DockerRuntimeConfig(
"1.0",
new Dictionary<string, RegistryCredentials>
{
["r1"] = new RegistryCredentials("foo.azurecr.io", "foo", "foo")
}));

var dri2 = new DockerRuntimeInfo(
"docker",
new DockerRuntimeConfig(
"1.0",
new Dictionary<string, RegistryCredentials>
{
["r1"] = new RegistryCredentials("foo.azurecr.io", "foo", "foo")
}));

Assert.Equal(dri1, dri2);
}
}
}

0 comments on commit c6b0ba9

Please sign in to comment.