From 13916d35caf1d43b55051e50d825b249ca7d84a0 Mon Sep 17 00:00:00 2001 From: Deepanshu Vaid Date: Sat, 21 Dec 2024 19:18:11 +0530 Subject: [PATCH 1/3] Fixing metadata flow for the virtual client component from commandline --- src/VirtualClient/VirtualClient.Main/RunProfileCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VirtualClient/VirtualClient.Main/RunProfileCommand.cs b/src/VirtualClient/VirtualClient.Main/RunProfileCommand.cs index 50bc9dee9..3c9d40530 100644 --- a/src/VirtualClient/VirtualClient.Main/RunProfileCommand.cs +++ b/src/VirtualClient/VirtualClient.Main/RunProfileCommand.cs @@ -825,7 +825,7 @@ private void InitializeProfile(ExecutionProfile profile) if (this.Metadata?.Any() == true) { // Command-line metadata overrides metadata in the profile itself. - profile.Parameters.AddRange(this.Metadata, true); + profile.Metadata.AddRange(this.Metadata, true); } if (this.Parameters?.Any() == true) From 2a03cde817b1940372cc2638757b2ed8c82f4d9b Mon Sep 17 00:00:00 2001 From: Deepanshu Vaid Date: Sun, 22 Dec 2024 14:34:36 +0530 Subject: [PATCH 2/3] Adding Profile Command tests --- .../RunProfileCommandTests.cs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/VirtualClient/VirtualClient.UnitTests/RunProfileCommandTests.cs b/src/VirtualClient/VirtualClient.UnitTests/RunProfileCommandTests.cs index c0c09b6db..ad3a70bf3 100644 --- a/src/VirtualClient/VirtualClient.UnitTests/RunProfileCommandTests.cs +++ b/src/VirtualClient/VirtualClient.UnitTests/RunProfileCommandTests.cs @@ -186,6 +186,70 @@ public async Task RunProfileCommandCreatesTheExpectedProfile_DefaultScenario() profile.Monitors.Select(a => a.Parameters["Scenario"].ToString())); } + [Test] + public async Task RunProfileCommandAddsTheExpectedMetadataToProfile() + { + // Scenario: + // In the default scenario, a workload profile is supplied that only contains + // workloads (i.e. no specific monitors). + string profile1 = "TEST-WORKLOAD-PROFILE.json"; + string defaultMonitorProfile = "MONITORS-DEFAULT.json"; + List profiles = new List { this.mockFixture.GetProfilesPath(profile1) }; + this.command.Metadata = new Dictionary(); + this.command.Metadata.Add("MetadataKey1", "MetadataValue1"); + this.command.Metadata.Add("MetadataKey2", "MetadataValue2"); + + // Setup: + // Read the actual profile content from the local file system. + this.mockFixture.File + .Setup(file => file.ReadAllTextAsync(It.Is(file => file.EndsWith(profile1)), It.IsAny())) + .ReturnsAsync(File.ReadAllText(this.mockFixture.Combine(RunProfileCommandTests.ProfilesDirectory, profile1))); + + this.mockFixture.File + .Setup(file => file.ReadAllTextAsync(It.Is(file => file.EndsWith(defaultMonitorProfile)), It.IsAny())) + .ReturnsAsync(File.ReadAllText(this.mockFixture.Combine(RunProfileCommandTests.ProfilesDirectory, defaultMonitorProfile))); + + ExecutionProfile profile = await this.command.InitializeProfilesAsync(profiles, this.mockFixture.Dependencies, CancellationToken.None) + .ConfigureAwait(false); + + bool isCommandMetadataSubset = this.command.Metadata.All(kvp => + profile.Metadata.TryGetValue(kvp.Key, out var value) && value.Equals(kvp.Value)); + + Assert.IsTrue(isCommandMetadataSubset); + } + + [Test] + public async Task RunProfileCommandAddsTheExpectedParametersToProfile() + { + // Scenario: + // In the default scenario, a workload profile is supplied that only contains + // workloads (i.e. no specific monitors). + string profile1 = "TEST-WORKLOAD-PROFILE.json"; + string defaultMonitorProfile = "MONITORS-DEFAULT.json"; + List profiles = new List { this.mockFixture.GetProfilesPath(profile1) }; + this.command.Parameters = new Dictionary(); + this.command.Parameters.Add("ParameterKey1", "ParameterValue1"); + this.command.Parameters.Add("ParameterKey2", "ParameterValue2"); + + // Setup: + // Read the actual profile content from the local file system. + this.mockFixture.File + .Setup(file => file.ReadAllTextAsync(It.Is(file => file.EndsWith(profile1)), It.IsAny())) + .ReturnsAsync(File.ReadAllText(this.mockFixture.Combine(RunProfileCommandTests.ProfilesDirectory, profile1))); + + this.mockFixture.File + .Setup(file => file.ReadAllTextAsync(It.Is(file => file.EndsWith(defaultMonitorProfile)), It.IsAny())) + .ReturnsAsync(File.ReadAllText(this.mockFixture.Combine(RunProfileCommandTests.ProfilesDirectory, defaultMonitorProfile))); + + ExecutionProfile profile = await this.command.InitializeProfilesAsync(profiles, this.mockFixture.Dependencies, CancellationToken.None) + .ConfigureAwait(false); + + bool isCommandParametersSubset = this.command.Parameters.All(kvp => + profile.Parameters.TryGetValue(kvp.Key, out var value) && value.Equals(kvp.Value)); + + Assert.IsTrue(isCommandParametersSubset); + } + [Test] public async Task RunProfileCommandCreatesTheExpectedProfile_DefaultMonitorProfileExplicitlyDefinedScenario() { From 564853858c6fda19b63ad6e7b9ed4c434e8db274 Mon Sep 17 00:00:00 2001 From: Deepanshu Vaid Date: Sun, 22 Dec 2024 14:52:40 +0530 Subject: [PATCH 3/3] Bumping to new version --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index c44d09727..412185428 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.16.12 +1.16.13