Skip to content

Commit

Permalink
Update PSDesiredStateConfiguration module min version (#3251)
Browse files Browse the repository at this point in the history
Update to PSDesiredStateConfiguration 2.0.7.

With this change, winget configure will download the 2.0.7 automatically.

This version contains a fix where Invoke-DSCResource failed when a class based resource is going to be invoke and it lives in a path with spaces on it. Bug details
  • Loading branch information
msftrubengu authored May 15, 2023
1 parent ced7e0a commit fa48fd8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal static class Variables
internal static class Modules
{
public const string PSDesiredStateConfiguration = "PSDesiredStateConfiguration";
public const string PSDesiredStateConfigurationMinVersion = "2.0.6";
public const string PSDesiredStateConfigurationMinVersion = "2.0.7";
public const string PowerShellGet = "PowerShellGet";
public const string PowerShellGetMinVersion = "2.2.5";
public const string PSDesiredStateConfigurationMaxVersion = "2.*";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Microsoft.Management.Configuration.Processor.DscModule
using static Microsoft.Management.Configuration.Processor.Constants.PowerShellConstants;

/// <summary>
/// PSDesiredStateConfiguration v2.0.6.
/// PSDesiredStateConfiguration v2.
/// </summary>
internal class DscModuleV2 : IDscModule
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public UnitTestFixture(IMessageSink messageSink)
/// <summary>
/// Creates a runspace adding the test module path.
/// </summary>
/// <param name="validate">Validate runspace.</param>
/// <returns>PowerShellRunspace.</returns>
internal IProcessorEnvironment PrepareTestProcessorEnvironment(bool validate = false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Microsoft.Management.Configuration.UnitTests.Tests
{
using System;
using System.IO;
using System.Management.Automation;
using Microsoft.Management.Configuration.Processor.DscModule;
Expand Down Expand Up @@ -99,7 +100,7 @@ public void GetDscResourcesInModule_VersionTest()

var dscModule = new DscModuleV2();

// This doesn't work on 2.0.6
// This doesn't work on v2
////var allResources = dscModule.GetDscResourcesInModule(
//// testEnvironment.Runspace,
//// PowerShellHelpers.CreateModuleSpecification(TestModule.SimpleTestResourceModuleName));
Expand Down Expand Up @@ -293,7 +294,7 @@ public void InvokeGetResource_ResourceThrows()
/// <summary>
/// Calls Invoke-DscResource Get. Resource writes error.
/// </summary>
[Fact(Skip = "Not supported in PSDesiredStateConfiguration 2.0.6")]
[Fact(Skip = "Not supported in PSDesiredStateConfiguration 2.0.7")]
public void InvokeGetResource_ResourceError()
{
var testEnvironment = this.fixture.PrepareTestProcessorEnvironment();
Expand Down Expand Up @@ -384,7 +385,7 @@ public void InvokeTestResource_Throws()
/// <summary>
/// Calls Invoke-DscResource Test. Resource writes error.
/// </summary>
[Fact(Skip = "Not supported in PSDesiredStateConfiguration 2.0.6")]
[Fact(Skip = "Not supported in PSDesiredStateConfiguration 2.0.7")]
public void InvokeTestResource_ResourceError()
{
var testEnvironment = this.fixture.PrepareTestProcessorEnvironment();
Expand Down Expand Up @@ -474,7 +475,7 @@ public void InvokeSetResource_Throws()
/// <summary>
/// Calls Invoke-DscResource Set. Resource writes error.
/// </summary>
[Fact(Skip = "Not supported in PSDesiredStateConfiguration 2.0.6")]
[Fact(Skip = "Not supported in PSDesiredStateConfiguration 2.0.7")]
public void InvokeSetResource_ResourceError()
{
var testEnvironment = this.fixture.PrepareTestProcessorEnvironment();
Expand Down Expand Up @@ -583,5 +584,39 @@ public void InvokeSetResource_InvalidArguments()
Assert.Contains("The property 'Fake' cannot be found on this object.", e.Message);
Assert.Equal(ConfigurationUnitResultSource.ConfigurationSet, e.ResultSource);
}

/// <summary>
/// Tests GetDscResourcesInModule with versions.
/// </summary>
[Fact]
public void InvokeSetResource_ModulePathSpaces()
{
// Copy test module to a directory with spaces.
using var tmpDir = new TempDirectory(directoryName: Path.Combine(Guid.NewGuid().ToString(), "Path With Spaces"));
tmpDir.CopyDirectory(this.fixture.TestModulesPath);
var manifestFile = Path.Combine(
tmpDir.FullDirectoryPath,
TestModule.SimpleTestResourceModuleName,
TestModule.SimpleTestResourceManifestFileName);

var testEnvironment = this.fixture.PrepareTestProcessorEnvironment();
testEnvironment.CleanupPSModulePath(this.fixture.TestModulesPath);
testEnvironment.AppendPSModulePath(tmpDir.FullDirectoryPath);

var dscModule = new DscModuleV2();

var settings = new ValueSet()
{
{ "secretCode", "4815162342" },
};

using PowerShell pwsh = PowerShell.Create(testEnvironment.Runspace);
var testResult = dscModule.InvokeSetResource(
pwsh,
settings,
TestModule.SimpleTestResourceName,
PowerShellHelpers.CreateModuleSpecification(
TestModule.SimpleTestResourceModuleName));
}
}
}

0 comments on commit fa48fd8

Please sign in to comment.