Skip to content

Commit

Permalink
Clean envrionment variable after use it
Browse files Browse the repository at this point in the history
  • Loading branch information
ismayilov-ismayil committed Oct 27, 2024
1 parent c6b214f commit ab128f6
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions src/Test/L0/Worker/JobExtensionL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -787,35 +787,42 @@ public async Task JobExtensionTelemetryPublisherSecretValue()

hc.SetSingleton(new TaskRestrictionsChecker() as ITaskRestrictionsChecker);

Environment.SetEnvironmentVariable("http_proxy", "http://admin:[email protected]");

var expectedEvent = new Dictionary<string, object>()
try
{
{ "JobId", null },
{ "ProxyAddress-${http_proxy}", "http://admin:***@localhost.com"},
};
Environment.SetEnvironmentVariable("http_proxy", "http://admin:[email protected]");

var actualEvents = new List<CustomerIntelligenceEvent[]>();
var expectedEvent = new Dictionary<string, object>()
{
{ "JobId", null },
{ "ProxyAddress-${http_proxy}", "http://admin:***@localhost.com"},
};

_mockCiService.Setup(s => s.PublishEventsAsync(It.IsAny<CustomerIntelligenceEvent[]>()))
.Callback<CustomerIntelligenceEvent[]>(actualEvents.Add)
.Returns(Task.CompletedTask);
var actualEvents = new List<CustomerIntelligenceEvent[]>();

_mockCiService.Setup(s => s.PublishEventsAsync(It.IsAny<CustomerIntelligenceEvent[]>()))
.Callback<CustomerIntelligenceEvent[]>(actualEvents.Add)
.Returns(Task.CompletedTask);

TestJobExtension testExtension = new TestJobExtension();
testExtension.Initialize(hc);
await testExtension.InitializeJob(_jobEc, _message);

var result = actualEvents.Where(w => w[0].Properties.ContainsKey("ProxyAddress-${http_proxy}"));
TestJobExtension testExtension = new TestJobExtension();
testExtension.Initialize(hc);
await testExtension.InitializeJob(_jobEc, _message);

var result = actualEvents.Where(w => w[0].Properties.ContainsKey("ProxyAddress-${http_proxy}"));

Assert.True(result?.Count() == 1);
Assert.True(result?.Count() == 1);

Assert.True(
!expectedEvent.Except(result.First()[0].Properties).Any(),
$"Event does not match. " +
$"Expected:{JsonSerializer.Serialize(expectedEvent)};" +
$"Actual:{JsonSerializer.Serialize(result.First()[0].Properties)}"
);
Assert.True(
!expectedEvent.Except(result.First()[0].Properties).Any(),
$"Event does not match. " +
$"Expected:{JsonSerializer.Serialize(expectedEvent)};" +
$"Actual:{JsonSerializer.Serialize(result.First()[0].Properties)}"
);
}
finally
{
Environment.SetEnvironmentVariable("http_proxy", "");
}
}
}
}

0 comments on commit ab128f6

Please sign in to comment.