Skip to content

Commit

Permalink
Allow empty configuration values in Service Fabric overrides
Browse files Browse the repository at this point in the history
Fixes #97
  • Loading branch information
karolz-ms committed Jul 7, 2017
1 parent 24e2c30 commit 0a713b9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Description>Provides types that simplify the use of EventFlow library by Microsoft Service Fabric services.</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<VersionPrefix>1.1.3</VersionPrefix>
<VersionPrefix>1.1.4</VersionPrefix>
<Authors>Microsoft</Authors>
<TargetFramework>net451</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ internal static IConfigurationRoot ApplyFabricConfigurationOverrides(
{
string valueReferencePath = ConfigurationPath.Combine(valueReferenceMatch.Groups["section"].Value, valueReferenceMatch.Groups["name"].Value);
string newValue = configurationRoot[valueReferencePath];
if (string.IsNullOrEmpty(newValue))
if (newValue == null)
{
healthReporter.ReportWarning(
$"Configuration value reference '{kvp.Value}' was encountered but no corresponding configuration value was found using path '{valueReferencePath}'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,31 @@ public void ConfigurationUpdatedWithValueReferences()
Assert.True(isOK, verificationError);
}

[Fact]
public void ReferencedValueCanBeEmpty()
{
var healthReporterMock = new Mock<IHealthReporter>();
var configurationSource = new Dictionary<string, string>()
{
["alpha"] = "Alpha",
["bravo:charlie"] = "",
["delta"] = "servicefabric:/bravo/charlie"
};

IConfigurationRoot configuration = (new ConfigurationBuilder()).AddInMemoryCollection(configurationSource).Build();
ServiceFabricDiagnosticPipelineFactory.ApplyFabricConfigurationOverrides(configuration, "unused-configuration-package-path", healthReporterMock.Object);
healthReporterMock.Verify(o => o.ReportProblem(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
healthReporterMock.Verify(o => o.ReportWarning(It.IsAny<string>(), It.IsAny<string>()), Times.Never());

string verificationError;
bool isOK = VerifyConfguration(configuration.AsEnumerable(), configurationSource, out verificationError);
Assert.False(isOK, verificationError);

configurationSource["delta"] = "";
isOK = VerifyConfguration(configuration.AsEnumerable(), configurationSource, out verificationError);
Assert.True(isOK, verificationError);
}

[Fact]
public void ConfigurationIsNotChangedIfFileReferenceIsEmpty()
{
Expand Down Expand Up @@ -152,7 +177,7 @@ private bool VerifyConfguration<TKey, TValue>(

if (!valueComparer.Equals(kvp.Value, correspondingPair.Value.Value))
{
verificationError = $"The value for key '{kvp.Key}' was expected to be '{kvp.Value}' but instead it is '{correspondingPair.Value.Value}')";
verificationError = $"The value for key '{kvp.Key}' was expected to be '{kvp.Value}' but instead it is '{correspondingPair.Value.Value}'";
return false;
}
}
Expand Down

0 comments on commit 0a713b9

Please sign in to comment.