diff --git a/VERSION b/VERSION index c44d09727c..412185428a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.16.12 +1.16.13 diff --git a/src/VirtualClient/VirtualClient.Main/RunProfileCommand.cs b/src/VirtualClient/VirtualClient.Main/RunProfileCommand.cs index 50bc9dee95..3c9d40530b 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) diff --git a/src/VirtualClient/VirtualClient.UnitTests/RunProfileCommandTests.cs b/src/VirtualClient/VirtualClient.UnitTests/RunProfileCommandTests.cs index c0c09b6db9..ad3a70bf36 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() {