Skip to content

Commit 5a11998

Browse files
Fixing metadata flow for the virtual client component from CommandLine (#418)
* Fixing metadata flow for the virtual client component from commandline * Adding Profile Command tests * Bumping to new version --------- Co-authored-by: Deepanshu Vaid <[email protected]>
1 parent 81f7761 commit 5a11998

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

Diff for: VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.16.12
1+
1.16.13

Diff for: src/VirtualClient/VirtualClient.Main/RunProfileCommand.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ private void InitializeProfile(ExecutionProfile profile)
825825
if (this.Metadata?.Any() == true)
826826
{
827827
// Command-line metadata overrides metadata in the profile itself.
828-
profile.Parameters.AddRange(this.Metadata, true);
828+
profile.Metadata.AddRange(this.Metadata, true);
829829
}
830830

831831
if (this.Parameters?.Any() == true)

Diff for: src/VirtualClient/VirtualClient.UnitTests/RunProfileCommandTests.cs

+64
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,70 @@ public async Task RunProfileCommandCreatesTheExpectedProfile_DefaultScenario()
186186
profile.Monitors.Select(a => a.Parameters["Scenario"].ToString()));
187187
}
188188

189+
[Test]
190+
public async Task RunProfileCommandAddsTheExpectedMetadataToProfile()
191+
{
192+
// Scenario:
193+
// In the default scenario, a workload profile is supplied that only contains
194+
// workloads (i.e. no specific monitors).
195+
string profile1 = "TEST-WORKLOAD-PROFILE.json";
196+
string defaultMonitorProfile = "MONITORS-DEFAULT.json";
197+
List<string> profiles = new List<string> { this.mockFixture.GetProfilesPath(profile1) };
198+
this.command.Metadata = new Dictionary<string, IConvertible>();
199+
this.command.Metadata.Add("MetadataKey1", "MetadataValue1");
200+
this.command.Metadata.Add("MetadataKey2", "MetadataValue2");
201+
202+
// Setup:
203+
// Read the actual profile content from the local file system.
204+
this.mockFixture.File
205+
.Setup(file => file.ReadAllTextAsync(It.Is<string>(file => file.EndsWith(profile1)), It.IsAny<CancellationToken>()))
206+
.ReturnsAsync(File.ReadAllText(this.mockFixture.Combine(RunProfileCommandTests.ProfilesDirectory, profile1)));
207+
208+
this.mockFixture.File
209+
.Setup(file => file.ReadAllTextAsync(It.Is<string>(file => file.EndsWith(defaultMonitorProfile)), It.IsAny<CancellationToken>()))
210+
.ReturnsAsync(File.ReadAllText(this.mockFixture.Combine(RunProfileCommandTests.ProfilesDirectory, defaultMonitorProfile)));
211+
212+
ExecutionProfile profile = await this.command.InitializeProfilesAsync(profiles, this.mockFixture.Dependencies, CancellationToken.None)
213+
.ConfigureAwait(false);
214+
215+
bool isCommandMetadataSubset = this.command.Metadata.All(kvp =>
216+
profile.Metadata.TryGetValue(kvp.Key, out var value) && value.Equals(kvp.Value));
217+
218+
Assert.IsTrue(isCommandMetadataSubset);
219+
}
220+
221+
[Test]
222+
public async Task RunProfileCommandAddsTheExpectedParametersToProfile()
223+
{
224+
// Scenario:
225+
// In the default scenario, a workload profile is supplied that only contains
226+
// workloads (i.e. no specific monitors).
227+
string profile1 = "TEST-WORKLOAD-PROFILE.json";
228+
string defaultMonitorProfile = "MONITORS-DEFAULT.json";
229+
List<string> profiles = new List<string> { this.mockFixture.GetProfilesPath(profile1) };
230+
this.command.Parameters = new Dictionary<string, IConvertible>();
231+
this.command.Parameters.Add("ParameterKey1", "ParameterValue1");
232+
this.command.Parameters.Add("ParameterKey2", "ParameterValue2");
233+
234+
// Setup:
235+
// Read the actual profile content from the local file system.
236+
this.mockFixture.File
237+
.Setup(file => file.ReadAllTextAsync(It.Is<string>(file => file.EndsWith(profile1)), It.IsAny<CancellationToken>()))
238+
.ReturnsAsync(File.ReadAllText(this.mockFixture.Combine(RunProfileCommandTests.ProfilesDirectory, profile1)));
239+
240+
this.mockFixture.File
241+
.Setup(file => file.ReadAllTextAsync(It.Is<string>(file => file.EndsWith(defaultMonitorProfile)), It.IsAny<CancellationToken>()))
242+
.ReturnsAsync(File.ReadAllText(this.mockFixture.Combine(RunProfileCommandTests.ProfilesDirectory, defaultMonitorProfile)));
243+
244+
ExecutionProfile profile = await this.command.InitializeProfilesAsync(profiles, this.mockFixture.Dependencies, CancellationToken.None)
245+
.ConfigureAwait(false);
246+
247+
bool isCommandParametersSubset = this.command.Parameters.All(kvp =>
248+
profile.Parameters.TryGetValue(kvp.Key, out var value) && value.Equals(kvp.Value));
249+
250+
Assert.IsTrue(isCommandParametersSubset);
251+
}
252+
189253
[Test]
190254
public async Task RunProfileCommandCreatesTheExpectedProfile_DefaultMonitorProfileExplicitlyDefinedScenario()
191255
{

0 commit comments

Comments
 (0)