Skip to content

Commit

Permalink
fix: ServiceDiscoveryIPv4 should return null if string is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
romanov.ah committed Aug 30, 2024
1 parent 9226e7f commit 1a7f393
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Vostok.Commons.Environment.Tests/EnvironmentInfo_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public void FQDN_should_not_be_null_or_empty()
}

[Test]
public void ServiceDiscoveryIPv4_should_be_null_or_empty_if_environment_variable_is_not_set()
public void ServiceDiscoveryIPv4_should_be_null_if_environment_variable_is_not_set()
{
EnvironmentInfo.ServiceDiscoveryIPv4.Should().BeNullOrEmpty();
EnvironmentInfo.ServiceDiscoveryIPv4.Should().BeNull();

Console.Out.WriteLine(EnvironmentInfo.ServiceDiscoveryIPv4);
}
Expand Down
6 changes: 5 additions & 1 deletion Vostok.Commons.Environment/EnvironmentInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ private static string ObtainServiceDiscoveryIPv4()
{
try
{
return System.Environment.GetEnvironmentVariable(LocalServiceDiscoveryIPv4Variable);
var localIPv4 = System.Environment.GetEnvironmentVariable(LocalServiceDiscoveryIPv4Variable);
if (!string.IsNullOrEmpty(localIPv4))
return localIPv4;

return null;
}
catch
{
Expand Down

0 comments on commit 1a7f393

Please sign in to comment.