-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean envrionment variable after use it
- Loading branch information
1 parent
c6b214f
commit ab128f6
Showing
1 changed file
with
28 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", ""); | ||
} | ||
} | ||
} | ||
} |