From a42a1c5714fb4e95f1bd506712fc8f506df9e501 Mon Sep 17 00:00:00 2001 From: Gijs Reijn Date: Thu, 24 Oct 2024 10:35:03 +0200 Subject: [PATCH 1/5] Delete powershell-helpers directory --- powershell-helpers/README.md | 13 - powershell-helpers/dscCfgMigMod.psd1 | 47 --- powershell-helpers/dscCfgMigMod.psm1 | 384 ------------------ .../tests/dscCfgMigMod.tests.ps1 | 24 -- 4 files changed, 468 deletions(-) delete mode 100644 powershell-helpers/README.md delete mode 100644 powershell-helpers/dscCfgMigMod.psd1 delete mode 100644 powershell-helpers/dscCfgMigMod.psm1 delete mode 100644 powershell-helpers/tests/dscCfgMigMod.tests.ps1 diff --git a/powershell-helpers/README.md b/powershell-helpers/README.md deleted file mode 100644 index d48f4e87..00000000 --- a/powershell-helpers/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Introduction - -The `powershell-adapters` folder contains helper modules that can be loaded into your PowerShell session to assist you in familiarizing yourself with new DSC concepts. To see the availability of helper modules, see the following list: - -- **DSC Configuration Migration Module**: - Aids in the assistance of grabbing configuration documents written in PowerShell code and transform them to valid configuration documents for the DSC version 3 core engine (e.g. YAML or JSON). - -## Getting started - -To get started using the helper modules, you can follow the below steps. This example uses the _DSC Configuration Migration Tool_ to be loaded into the session: - -1. Open a PowerShell terminal session -2. Execute the following command: `Import-Module "powershell-helpers\dscConfigurationMigrationTool.psm1"` -3. Discover examples using: `Get-Help ConvertTo-DscYaml` diff --git a/powershell-helpers/dscCfgMigMod.psd1 b/powershell-helpers/dscCfgMigMod.psd1 deleted file mode 100644 index 83d1ac09..00000000 --- a/powershell-helpers/dscCfgMigMod.psd1 +++ /dev/null @@ -1,47 +0,0 @@ -@{ - - # Script module or binary module file associated with this manifest. - RootModule = 'dscCfgMigMod.psm1' - - # Version number of this module. - moduleVersion = '0.0.1' - - # ID used to uniquely identify this module - GUID = '42bf8cb0-210c-4dac-8614-319d9287c6dc' - - # Author of this module - Author = 'Microsoft Corporation' - - # Company or vendor of this module - CompanyName = 'Microsoft Corporation' - - # Copyright statement for this module - Copyright = '(c) Microsoft Corporation. All rights reserved.' - - # Description of the functionality provided by this module - Description = 'PowerShell Desired State Configuration Migration Module helper' - - # Modules that must be imported into the global environment prior to importing this module - RequiredModules = @('powershell-yaml') - - # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. - FunctionsToExport = @( - 'ConvertTo-DscJson' - 'ConvertTo-DscYaml' - ) - - # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. - CmdletsToExport = @() - - # Variables to export from this module - VariablesToExport = @() - - # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. - AliasesToExport = @() - - PrivateData = @{ - PSData = @{ - ProjectUri = 'https://github.com/PowerShell/dsc' - } - } -} diff --git a/powershell-helpers/dscCfgMigMod.psm1 b/powershell-helpers/dscCfgMigMod.psm1 deleted file mode 100644 index c61ff4bf..00000000 --- a/powershell-helpers/dscCfgMigMod.psm1 +++ /dev/null @@ -1,384 +0,0 @@ -#region Main functions -function ConvertTo-DscJson -{ - <# - .SYNOPSIS - Convert a PowerShell DSC configuration document to DSC version 3 JSON format. - - .DESCRIPTION - The function ConvertTo-DscJson converts a PowerShell DSC configuration document to DSC version 3 JSON format from a path. - - .PARAMETER Path - The path to valid PowerShell DSC configuration document - - .EXAMPLE - PS C:\> $configuration = @' - Configuration TestResource { - Import-DscResource -ModuleName TestResource - Node localhost { - TestResource 'Configure test resource' { - Ensure = 'Absent' - Name = 'MyTestResource' - } - } - } - '@ - PS C:\> $Path = Join-Path -Path $env:TEMP -ChildPath 'configuration.ps1' - PS C:\> $configuration | Out-File -FilePath $Path - PS C:\> ConvertTo-DscJson -Path $Path - - Returns: - { - "$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json", - "resources": { - "name": "TestResource", - "type": "Microsoft.DSC/PowerShell", - "properties": { - "resources": [ - { - "name": "Configure test resource", - "type": "TestResource/TestResource", - "properties": { - "Name": "MyTestResource", - "Ensure": "Absent" - } - } - ] - } - } - } - - .NOTES - Tags: DSC, Migration, JSON - #> - [CmdletBinding()] - Param - ( - [System.String] - $Path - ) - - begin - { - Write-Verbose ("Starting: {0}" -f $MyInvocation.MyCommand.Name) - } - - process - { - $inputObject = BuildConfigurationDocument -Path $Path - } - end - { - Write-Verbose ("Ended: {0}" -f $MyInvocation.MyCommand.Name) - return $inputObject - } -} - -function ConvertTo-DscYaml -{ - <# - .SYNOPSIS - Convert a PowerShell DSC configuration document to DSC version 3 YAML format. - - .DESCRIPTION - The function ConvertTo-DscYaml converts a PowerShell DSC configuration document to DSC version 3 YAML format from a path. - - .PARAMETER Path - The path to valid PowerShell DSC configuration document - - .EXAMPLE - PS C:\> $configuration = @' - Configuration TestResource { - Import-DscResource -ModuleName TestResource - Node localhost { - TestResource 'Configure test resource' { - Ensure = 'Absent' - Name = 'MyTestResource' - } - } - } - '@ - PS C:\> $Path = Join-Path -Path $env:TEMP -ChildPath 'configuration.ps1' - PS C:\> $configuration | Out-File -FilePath $Path - PS C:\> ConvertTo-DscYaml -Path $Path - - Returns: - $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json - resources: - name: TestResource - type: Microsoft.DSC/PowerShell - properties: - resources: - - name: Configure test resource - type: TestResource/TestResource - properties: - Name: MyTestResource - Ensure: Absent - - .NOTES - Tags: DSC, Migration, YAML - #> - [CmdletBinding()] - Param - ( - [System.String] - $Path - ) - - begin - { - Write-Verbose ("Starting: {0}" -f $MyInvocation.MyCommand.Name) - } - - process - { - $inputObject = BuildConfigurationDocument -Path $Path -Format YAML - } - end - { - Write-Verbose ("Ended: {0}" -f $MyInvocation.MyCommand.Name) - return $inputObject - } -} -#endRegion Main functions - -#region Helper functions -function FindAndExtractConfigurationDocument -{ - [CmdletBinding()] - Param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Path - ) - - if (-not (TestPathExtension $Path)) - { - return @{} - } - - # Parse the abstract syntax tree to get all hash table values representing the configuration resources - [System.Management.Automation.Language.Token[]] $tokens = $null - [System.Management.Automation.Language.ParseError[]] $errors = $null - $ast = [System.Management.Automation.Language.Parser]::ParseFile($Path, [ref]$tokens, [ref]$errors) - $configurations = $ast.FindAll({$args[0].GetType().Name -like 'HashtableAst'}, $true) - - # Create configuration document resource class (can be re-used) - $configurationDocument = [DscConfigurationResource]::new() - - # Build simple regex - $regex = [regex]::new('Configuration\s+(\w+)') - $configValue = $regex.Matches($ast.Extent.Text).Value - - if (-not $configValue) - { - return - } - - $documentConfigurationName = $configValue.TrimStart('Configuration').Trim(" ") - - # Start to build the outer basic format - $configurationDocument.name = $documentConfigurationName - $configurationDocument.type = 'Microsoft.DSC/PowerShell' # TODO: Add functions later to valid the adapter type - - # Bag to hold resources - $resourceProps = [System.Collections.Generic.List[object]]::new() - - foreach ($configuration in $configurations) - { - # Get parent configuration details - $resourceName = ($configuration.Parent.CommandElements.Value | Select-Object -Last 1 ) - $resourceConfigurationName = ($configuration.Parent.CommandElements.Value | Select-Object -First 1) - - # Get module details - $module = Get-DscResource -Name $resourceConfigurationName -ErrorAction SilentlyContinue - - # Build the module - $resource = [DscConfigurationResource]::new() - $resource.properties = $configuration.SafeGetValue() - $resource.name = $resourceName - $resource.type = ("{0}/{1}" -f $module.ModuleName, $resourceConfigurationName) - # TODO: Might have to change because it takes time. If there is only one Import-DscResource statement, we can simply RegEx it out, else use Get-DscResource - # $document.ModuleName = $module.ModuleName - - Write-Verbose ("Adding document with data") - Write-Verbose ($resource | ConvertTo-Json | Out-String) - $resourceProps.Add($resource) - } - - # Add all the resources - $configurationDocument.properties = @{ - resources = $resourceProps - } - - return $configurationDocument -} - -function BuildConfigurationDocument -{ - [CmdletBinding()] - Param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Path, - - [ValidateSet('JSON', 'YAML')] - [System.String] - $Format = 'JSON' - ) - - $configurationDocument = [ordered]@{ - "`$schema" = "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json" # TODO: Figure out how to extract latest document.json from schemas folder - resources = FindAndExtractConfigurationDocument -Path $Path - } - - switch ($Format) - { - "JSON" { - $inputObject = ($configurationDocument | ConvertTo-Json -Depth 10) - } - "YAML" { - if (TestYamlModule) - { - $inputObject = ($configurationDocument | ConvertTo-Yaml) - } - else - { - $inputObject = @{} - } - } - default { - $inputObject = $configurationDocument - } - } - - return $inputObject -} - -function TestPathExtension -{ - [CmdletBinding()] - Param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Path - ) - - $res = $true - - if (-not (Test-Path $Path)) - { - $res = $false - } - - if (([System.IO.Path]::GetExtension($Path) -ne ".ps1")) - { - $res = $false - } - - return $res -} - -function TestYamlModule -{ - if (-not (Get-Command -Name 'ConvertTo-Yaml' -ErrorAction SilentlyContinue)) - { - return $false - } - - return $true -} - -function GetPowerShellPath -{ - param - ( - $Path - ) - - $knownPath = @( - "$env:USERPROFILE\Documents\PowerShell\Modules", - "$env:ProgramFiles\PowerShell\Modules", - "$env:ProgramFiles\PowerShell\7\Modules" - ) - - foreach ($known in $knownPath) - { - if ($Path.StartsWith($known)) - { - return $true - } - } - - return $false -} - -function GetWindowsPowerShellPath -{ - param - ( - $Path - ) - - $knownPath = @( - "$env:USERPROFILE\Documents\WindowsPowerShell\Modules", - "$env:ProgramFiles\WindowsPowerShell\Modules", - "$env:SystemRoot\System32\WindowsPowerShell\v1.0\Modules" - ) - - foreach ($known in $knownPath) - { - if ($Path.StartsWith($known)) - { - return $true - } - } - - return $false -} - -function ResolvePowerShellPath -{ - [CmdletBinding()] - Param - ( - [System.String] - $Path - ) - - if (-not (Test-Path $Path)) - { - return - } - - if (([System.IO.Path]::GetExtension($Path) -ne ".psm1")) - { - return - } - - if (GetPowerShellPath -Path $Path) - { - return "Microsoft.DSC/PowerShell" - } - - if (GetWindowsPowerShellPath -Path $Path) - { - return "Microsoft.Windows/WindowsPowerShell" - } - - return $null # TODO: Or default Microsoft.DSC/PowerShell -} - -#endRegion Helper functions - -#region Classes -class DscConfigurationResource -{ - [string] $name - [string] $type - [hashtable] $properties -} -#endRegion classes \ No newline at end of file diff --git a/powershell-helpers/tests/dscCfgMigMod.tests.ps1 b/powershell-helpers/tests/dscCfgMigMod.tests.ps1 deleted file mode 100644 index b966993a..00000000 --- a/powershell-helpers/tests/dscCfgMigMod.tests.ps1 +++ /dev/null @@ -1,24 +0,0 @@ -Describe "DSC Configuration Migration Module tests" { - BeforeAll { - $modPath = (Resolve-Path -Path "$PSScriptRoot\..\dscCfgMigMod.psd1").Path - $modLoad = Import-Module $modPath -Force -PassThru - } - - Context "ConvertTo-DscYaml" { - It "Should create an empty resource block" { - $res = (ConvertTo-DscYaml -Path 'idonotexist' | ConvertFrom-Yaml) - $res.resources | Should -BeNullOrEmpty - } - } - - Context "ConvertTo-DscJson" { - It "Should create an empty resource block" { - $res = (ConvertTo-DscJson -Path 'idonotexist' | ConvertFrom-Json) - $res.resources | Should -BeNullOrEmpty - } - } - - AfterAll { - Remove-Module -Name $modLoad.Name -Force - } -} From 658147571615fc756bd9fb2838e6a79e82172e7c Mon Sep 17 00:00:00 2001 From: "G.Reijn" Date: Sat, 1 Feb 2025 12:39:04 +0100 Subject: [PATCH 2/5] Addresses spelling after PR --- .../schemas/config/functions/overview.md | 12 +++--- dsc/locales/en-us.toml | 6 +-- dsc/src/main.rs | 2 +- dsc/tests/dsc_resource_test.tests.ps1 | 17 +++++--- dsc/tests/dsc_variables.tests.ps1 | 42 +++++++++---------- dsc_lib/src/dscresources/dscresource.rs | 2 +- registry/src/main.rs | 2 +- runcommandonset/locales/en-us.toml | 2 +- 8 files changed, 46 insertions(+), 39 deletions(-) diff --git a/docs/reference/schemas/config/functions/overview.md b/docs/reference/schemas/config/functions/overview.md index fa27a628..e0343644 100644 --- a/docs/reference/schemas/config/functions/overview.md +++ b/docs/reference/schemas/config/functions/overview.md @@ -308,7 +308,7 @@ parameters: list: { type: array } resources: - - name: Acess the properties of an object + - name: Access the properties of an object type: Test/Echo properties: output: @@ -394,7 +394,7 @@ results: - metadata: Microsoft.DSC: duration: PT0.0760186S - name: Acess the properties of an object + name: Access the properties of an object type: Test/Echo result: actualState: @@ -417,7 +417,7 @@ parameters: list: { type: array } resources: - - name: Acess items in an array + - name: Access items in an array type: Test/Echo properties: output: @@ -441,7 +441,7 @@ results: - metadata: Microsoft.DSC: duration: PT0.0750682S - name: Acess items in an array + name: Access items in an array type: Test/Echo result: actualState: @@ -476,7 +476,7 @@ parameters: list: { type: array } resources: - - name: Acess items in a nested array + - name: Access items in a nested array type: Test/Echo properties: output: @@ -496,7 +496,7 @@ results: - metadata: Microsoft.DSC: duration: PT0.1349442S - name: Acess items in a nested array + name: Access items in a nested array type: Test/Echo result: actualState: diff --git a/dsc/locales/en-us.toml b/dsc/locales/en-us.toml index baa687b6..aca7372d 100644 --- a/dsc/locales/en-us.toml +++ b/dsc/locales/en-us.toml @@ -58,7 +58,7 @@ failedToOpenFile = "Failed to open included file" invalidFileContent = "Invalid UTF-8 sequence in included file" invalidFile = "Failed to read the configuration file as YAML or JSON" resolvingParameters = "Resolving parameters from file" -failedParseParametersFile = "Failed to parse parameters file or conetnt to JSON" +failedParseParametersFile = "Failed to parse parameters file or content to JSON" couldNotReadParametersFile = "Could not read parameters file" invalidPath = "Include path must not contain '..'" failedGetCurrentDirectory = "Failed to get current directory" @@ -79,7 +79,7 @@ currentDirectory = "current directory" noParameters = "No parameters specified" parameters = "Parameters specified" failedConvertJson = "Failed to convert YAML to JSON" -invalidParamters = "Parameters are not valid JSON or YAML" +invalidParameters = "Parameters are not valid JSON or YAML" invalidPath = "Target path does not exist" failedSetParameters = "Parameter input failure" invalidInclude = "Failed to deserialize Include input" @@ -109,7 +109,7 @@ invalidManifest = "Error in manifest for" failedToConvertJsonToString = "Failed to convert JSON to string" failedToReadTracingSetting = "Could not read 'tracing' setting" invalidTraceLevel = "Default to 'warn', invalid DSC_TRACE_LEVEL value" -failedToSetTracing = "Unable to set global default tracing subscriber. Tracing is diabled." +failedToSetTracing = "Unable to set global default tracing subscriber. Tracing is disabled." validatingSchema = "Validating against schema" failedToCompileSchema = "JSON Schema Compilation" validationFailed = "Failed validation" diff --git a/dsc/src/main.rs b/dsc/src/main.rs index 81b73962..9c25f5da 100644 --- a/dsc/src/main.rs +++ b/dsc/src/main.rs @@ -137,7 +137,7 @@ fn check_debug() { } } -// Check if the dsc binary parent process is WinStore.App or Exploerer.exe +// Check if the dsc binary parent process is WinStore.App or Explorer.exe #[cfg(windows)] fn check_store() { use std::io::Read; diff --git a/dsc/tests/dsc_resource_test.tests.ps1 b/dsc/tests/dsc_resource_test.tests.ps1 index 44971e4b..813c4746 100644 --- a/dsc/tests/dsc_resource_test.tests.ps1 +++ b/dsc/tests/dsc_resource_test.tests.ps1 @@ -3,13 +3,20 @@ Describe 'Invoke a resource test directly' { It 'test can be called on a resource' { - $os = if ($IsWindows) { + $os = if ($IsWindows) + { 'Windows' - } elseif ($IsLinux) { + } + elseif ($IsLinux) + { 'Linux' - } elseif ($IsMacOS) { + } + elseif ($IsMacOS) + { 'macOS' - } else { + } + else + { 'Unknown' } @@ -21,7 +28,7 @@ Describe 'Invoke a resource test directly' { $out.inDesiredState | Should -Be $true } - It 'test returns proper error code if no input is provded' { + It 'test returns proper error code if no input is provided' { $out = dsc resource test -r Microsoft/OSInfo 2>&1 $LASTEXITCODE | Should -Be 1 $out | Should -BeLike '*ERROR*' diff --git a/dsc/tests/dsc_variables.tests.ps1 b/dsc/tests/dsc_variables.tests.ps1 index 95d3d348..5b29eaad 100644 --- a/dsc/tests/dsc_variables.tests.ps1 +++ b/dsc/tests/dsc_variables.tests.ps1 @@ -1,16 +1,16 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -Describe 'Configruation variables tests' { - It 'Variables example config works' { - $configFile = "$PSSCriptRoot/../examples/variables.dsc.yaml" - $out = dsc config get -f $configFile | ConvertFrom-Json - $LASTEXITCODE | Should -Be 0 - $out.results[0].result.actualState.output | Should -BeExactly 'myOutput is: Hello world!, myObject is: baz' - } +Describe 'Configuration variables tests' { + It 'Variables example config works' { + $configFile = "$PSScriptRoot/../examples/variables.dsc.yaml" + $out = dsc config get -f $configFile | ConvertFrom-Json + $LASTEXITCODE | Should -Be 0 + $out.results[0].result.actualState.output | Should -BeExactly 'myOutput is: Hello world!, myObject is: baz' + } - It 'Duplicated variable takes last value' { - $configYaml = @' + It 'Duplicated variable takes last value' { + $configYaml = @' $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json variables: myVariable: foo @@ -21,14 +21,14 @@ resources: properties: output: "[variables('myVariable')]" '@ - $out = dsc config get -i $configYaml | ConvertFrom-Json - Write-Verbose -Verbose $out - $LASTEXITCODE | Should -Be 0 - $out.results[0].result.actualState.output | Should -Be 'bar' - } + $out = dsc config get -i $configYaml | ConvertFrom-Json + Write-Verbose -Verbose $out + $LASTEXITCODE | Should -Be 0 + $out.results[0].result.actualState.output | Should -Be 'bar' + } - It 'Missing variable returns error' { - $configYaml = @' + It 'Missing variable returns error' { + $configYaml = @' $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json variables: hello: world @@ -38,9 +38,9 @@ resources: properties: output: "[variables('myVariable')]" '@ - $out = dsc config get -i $configYaml 2>&1 | Out-String - Write-Verbose -Verbose $out - $LASTEXITCODE | Should -Be 2 - $out | Should -BeLike "*Variable 'myVariable' does not exist or has not been initialized yet*" - } + $out = dsc config get -i $configYaml 2>&1 | Out-String + Write-Verbose -Verbose $out + $LASTEXITCODE | Should -Be 2 + $out | Should -BeLike "*Variable 'myVariable' does not exist or has not been initialized yet*" + } } diff --git a/dsc_lib/src/dscresources/dscresource.rs b/dsc_lib/src/dscresources/dscresource.rs index 868a9098..ab673522 100644 --- a/dsc_lib/src/dscresources/dscresource.rs +++ b/dsc_lib/src/dscresources/dscresource.rs @@ -46,7 +46,7 @@ pub struct DscResource { #[derive(Clone, Debug, PartialEq, Deserialize, Serialize, JsonSchema)] pub enum Capability { - /// The resource supports retriving configuration. + /// The resource supports retrieving configuration. Get, /// The resource supports applying configuration. Set, diff --git a/registry/src/main.rs b/registry/src/main.rs index 7b078d79..d76663a1 100644 --- a/registry/src/main.rs +++ b/registry/src/main.rs @@ -135,7 +135,7 @@ pub fn enable_tracing() { let subscriber = tracing_subscriber::Registry::default().with(fmt).with(filter); if tracing::subscriber::set_global_default(subscriber).is_err() { - eprintln!("Unable to set global default tracing subscriber. Tracing is diabled."); + eprintln!("Unable to set global default tracing subscriber. Tracing is disabled."); } } diff --git a/runcommandonset/locales/en-us.toml b/runcommandonset/locales/en-us.toml index 5c043751..c9b08fdd 100644 --- a/runcommandonset/locales/en-us.toml +++ b/runcommandonset/locales/en-us.toml @@ -19,4 +19,4 @@ failedReadStderr = "Failed to read stderr for" failedReadStdout = "Failed to read stdout for" failedWait = "Failed to wait for" invalidInput = "Input is not valid" -unableToTrace = "Unable to set global default tracing subscriber. Tracing is diabled." +unableToTrace = "Unable to set global default tracing subscriber. Tracing is disabled." From 106c208b5d467c2f3ccb22e94b289be308390e43 Mon Sep 17 00:00:00 2001 From: Gijs Reijn Date: Fri, 7 Feb 2025 06:27:33 +0100 Subject: [PATCH 3/5] Resolve remarks --- dsc/tests/dsc_resource_test.tests.ps1 | 17 +++------- dsc/tests/dsc_variables.tests.ps1 | 48 +++++++++++++-------------- 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/dsc/tests/dsc_resource_test.tests.ps1 b/dsc/tests/dsc_resource_test.tests.ps1 index 813c4746..ad898e54 100644 --- a/dsc/tests/dsc_resource_test.tests.ps1 +++ b/dsc/tests/dsc_resource_test.tests.ps1 @@ -3,20 +3,13 @@ Describe 'Invoke a resource test directly' { It 'test can be called on a resource' { - $os = if ($IsWindows) - { + $os = if ($IsWindows) { 'Windows' - } - elseif ($IsLinux) - { + } elseif ($IsLinux) { 'Linux' - } - elseif ($IsMacOS) - { + } elseif ($IsMacOS) { 'macOS' - } - else - { + } else { 'Unknown' } @@ -33,4 +26,4 @@ Describe 'Invoke a resource test directly' { $LASTEXITCODE | Should -Be 1 $out | Should -BeLike '*ERROR*' } -} +} \ No newline at end of file diff --git a/dsc/tests/dsc_variables.tests.ps1 b/dsc/tests/dsc_variables.tests.ps1 index 5b29eaad..46187831 100644 --- a/dsc/tests/dsc_variables.tests.ps1 +++ b/dsc/tests/dsc_variables.tests.ps1 @@ -3,44 +3,44 @@ Describe 'Configuration variables tests' { It 'Variables example config works' { - $configFile = "$PSScriptRoot/../examples/variables.dsc.yaml" - $out = dsc config get -f $configFile | ConvertFrom-Json - $LASTEXITCODE | Should -Be 0 - $out.results[0].result.actualState.output | Should -BeExactly 'myOutput is: Hello world!, myObject is: baz' + $configFile = "$PSScriptRoot/../examples/variables.dsc.yaml" + $out = dsc config get -f $configFile | ConvertFrom-Json + $LASTEXITCODE | Should -Be 0 + $out.results[0].result.actualState.output | Should -BeExactly 'myOutput is: Hello world!, myObject is: baz' } It 'Duplicated variable takes last value' { - $configYaml = @' + $configYaml = @' $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json variables: - myVariable: foo - myVariable: bar +myVariable: foo +myVariable: bar resources: - name: test - type: Microsoft.DSC.Debug/Echo - properties: - output: "[variables('myVariable')]" +type: Microsoft.DSC.Debug/Echo +properties: + output: "[variables('myVariable')]" '@ - $out = dsc config get -i $configYaml | ConvertFrom-Json - Write-Verbose -Verbose $out - $LASTEXITCODE | Should -Be 0 - $out.results[0].result.actualState.output | Should -Be 'bar' + $out = dsc config get -i $configYaml | ConvertFrom-Json + Write-Verbose -Verbose $out + $LASTEXITCODE | Should -Be 0 + $out.results[0].result.actualState.output | Should -Be 'bar' } It 'Missing variable returns error' { - $configYaml = @' + $configYaml = @' $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json variables: - hello: world +hello: world resources: - name: test - type: Microsoft.DSC.Debug/Echo - properties: - output: "[variables('myVariable')]" +type: Microsoft.DSC.Debug/Echo +properties: + output: "[variables('myVariable')]" '@ - $out = dsc config get -i $configYaml 2>&1 | Out-String - Write-Verbose -Verbose $out - $LASTEXITCODE | Should -Be 2 - $out | Should -BeLike "*Variable 'myVariable' does not exist or has not been initialized yet*" + $out = dsc config get -i $configYaml 2>&1 | Out-String + Write-Verbose -Verbose $out + $LASTEXITCODE | Should -Be 2 + $out | Should -BeLike "*Variable 'myVariable' does not exist or has not been initialized yet*" } -} +} \ No newline at end of file From 597fe6fcb9c0b7913a6a9c9a04ed0adbbc086cbd Mon Sep 17 00:00:00 2001 From: "G.Reijn" Date: Sat, 8 Feb 2025 05:38:48 +0100 Subject: [PATCH 4/5] Fix up formatting --- dsc/tests/dsc_variables.tests.ps1 | 50 +++++++++++++++---------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/dsc/tests/dsc_variables.tests.ps1 b/dsc/tests/dsc_variables.tests.ps1 index 46187831..6d28325e 100644 --- a/dsc/tests/dsc_variables.tests.ps1 +++ b/dsc/tests/dsc_variables.tests.ps1 @@ -1,46 +1,46 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -Describe 'Configuration variables tests' { +Describe 'Configruation variables tests' { It 'Variables example config works' { - $configFile = "$PSScriptRoot/../examples/variables.dsc.yaml" - $out = dsc config get -f $configFile | ConvertFrom-Json - $LASTEXITCODE | Should -Be 0 - $out.results[0].result.actualState.output | Should -BeExactly 'myOutput is: Hello world!, myObject is: baz' + $configFile = "$PSSCriptRoot/../examples/variables.dsc.yaml" + $out = dsc config get -f $configFile | ConvertFrom-Json + $LASTEXITCODE | Should -Be 0 + $out.results[0].result.actualState.output | Should -BeExactly 'myOutput is: Hello world!, myObject is: baz' } It 'Duplicated variable takes last value' { - $configYaml = @' + $configYaml = @' $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json variables: -myVariable: foo -myVariable: bar + myVariable: foo + myVariable: bar resources: - name: test -type: Microsoft.DSC.Debug/Echo -properties: - output: "[variables('myVariable')]" + type: Microsoft.DSC.Debug/Echo + properties: + output: "[variables('myVariable')]" '@ - $out = dsc config get -i $configYaml | ConvertFrom-Json - Write-Verbose -Verbose $out - $LASTEXITCODE | Should -Be 0 - $out.results[0].result.actualState.output | Should -Be 'bar' + $out = dsc config get -i $configYaml | ConvertFrom-Json + Write-Verbose -Verbose $out + $LASTEXITCODE | Should -Be 0 + $out.results[0].result.actualState.output | Should -Be 'bar' } It 'Missing variable returns error' { - $configYaml = @' + $configYaml = @' $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json variables: -hello: world + hello: world resources: - name: test -type: Microsoft.DSC.Debug/Echo -properties: - output: "[variables('myVariable')]" + type: Microsoft.DSC.Debug/Echo + properties: + output: "[variables('myVariable')]" '@ - $out = dsc config get -i $configYaml 2>&1 | Out-String - Write-Verbose -Verbose $out - $LASTEXITCODE | Should -Be 2 - $out | Should -BeLike "*Variable 'myVariable' does not exist or has not been initialized yet*" + $out = dsc config get -i $configYaml 2>&1 | Out-String + Write-Verbose -Verbose $out + $LASTEXITCODE | Should -Be 2 + $out | Should -BeLike "*Variable 'myVariable' does not exist or has not been initialized yet*" } -} \ No newline at end of file +} From 6ee57fbdbbf755398f3c59b2e0183fccb6fbb96b Mon Sep 17 00:00:00 2001 From: "G.Reijn" Date: Sat, 8 Feb 2025 06:16:25 +0100 Subject: [PATCH 5/5] Replace value in subCommand --- dsc/src/subcommand.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dsc/src/subcommand.rs b/dsc/src/subcommand.rs index 321cb795..17763864 100644 --- a/dsc/src/subcommand.rs +++ b/dsc/src/subcommand.rs @@ -329,7 +329,7 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option, mounte } }, Err(err) => { - error!("{}: {err}", t!("subcommand.invalidParamters")); + error!("{}: {err}", t!("subcommand.invalidParameters")); exit(EXIT_INVALID_INPUT); } }