From 1a488e32e34cecdf70bcbe3bb91cf7e145eac77a Mon Sep 17 00:00:00 2001 From: "G.Reijn" Date: Mon, 9 Dec 2024 19:11:51 +0100 Subject: [PATCH] Resolve remarks --- .vscode/settings.json | 1 + .../TestClassNoVersion.psd1 | 6 +- .../Tests/powershellgroup.resource.tests.ps1 | 77 ++++++------------- 3 files changed, 26 insertions(+), 58 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 24bf5814..93224251 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,6 +12,7 @@ "./y2j/Cargo.toml" ], "rust-analyzer.showUnlinkedFileNotification": true, + "powershell.codeFormatting.preset": "OTBS", "json.schemas": [ { "fileMatch": ["**/*.dsc.resource.json"], diff --git a/powershell-adapter/Tests/TestClassNoVersion/TestClassNoVersion.psd1 b/powershell-adapter/Tests/TestClassNoVersion/TestClassNoVersion.psd1 index 7defc6db..659605dd 100644 --- a/powershell-adapter/Tests/TestClassNoVersion/TestClassNoVersion.psd1 +++ b/powershell-adapter/Tests/TestClassNoVersion/TestClassNoVersion.psd1 @@ -25,16 +25,16 @@ Copyright = '(c) Microsoft. All rights reserved.' # 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 = '*' + FunctionsToExport = @() # 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 = '*' + 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 = '*' + AliasesToExport = @() # DSC resources to export from this module DscResourcesToExport = 'TestClassNoVersion' diff --git a/powershell-adapter/Tests/powershellgroup.resource.tests.ps1 b/powershell-adapter/Tests/powershellgroup.resource.tests.ps1 index 21eeec90..75f01969 100644 --- a/powershell-adapter/Tests/powershellgroup.resource.tests.ps1 +++ b/powershell-adapter/Tests/powershellgroup.resource.tests.ps1 @@ -7,12 +7,9 @@ Describe 'PowerShell adapter resource tests' { $OldPSModulePath = $env:PSModulePath $env:PSModulePath += [System.IO.Path]::PathSeparator + $PSScriptRoot - if ($IsLinux -or $IsMacOS) - { + if ($IsLinux -or $IsMacOS) { $cacheFilePath = Join-Path $env:HOME ".dsc" "PSAdapterCache.json" - } - else - { + } else { $cacheFilePath = Join-Path $env:LocalAppData "dsc" "PSAdapterCache.json" } } @@ -142,20 +139,14 @@ Describe 'PowerShell adapter resource tests' { # generate the cache $null = dsc resource list '*' -a Microsoft.DSC/PowerShell # update the version in the cache file - $cacheFilePath = if ($IsWindows) - { + $cacheFilePath = if ($IsWindows) { # PS 6+ on Windows Join-Path $env:LocalAppData "dsc\PSAdapterCache.json" - } - else - { + } else { # either WinPS or PS 6+ on Linux/Mac - if ($PSVersionTable.PSVersion.Major -le 5) - { + if ($PSVersionTable.PSVersion.Major -le 5) { Join-Path $env:LocalAppData "dsc\WindowsPSAdapterCache.json" - } - else - { + } else { Join-Path $env:HOME ".dsc" "PSAdapterCache.json" } } @@ -177,8 +168,7 @@ Describe 'PowerShell adapter resource tests' { Remove-Item -Recurse -Force -Path "$PSScriptRoot/TestClassResource" $oldPath = $env:PSModulePath - try - { + try { $env:PSModulePath += [System.IO.Path]::PathSeparator + $TestDrive # generate the cache @@ -191,9 +181,7 @@ Describe 'PowerShell adapter resource tests' { $LASTEXITCODE | Should -Be 0 "$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Detected non-existent cache entry' "$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Constructing Get-DscResource cache' - } - finally - { + } finally { $env:PSModulePath = $oldPath Copy-Item -Recurse -Force -Path "$PSScriptRoot/Backup/TestClassResource" -Destination "$PSScriptRoot" Remove-Item -Recurse -Force -Path "$PSScriptRoot/Backup" @@ -241,8 +229,7 @@ Describe 'PowerShell adapter resource tests' { $oldPath = $env:PSModulePath - try - { + try { $env:PSModulePath += [System.IO.Path]::PathSeparator + $pathRoot1 $env:PSModulePath += [System.IO.Path]::PathSeparator + $pathRoot2 @@ -252,17 +239,14 @@ Describe 'PowerShell adapter resource tests' { $r = @($resources | ? { $_.Type -eq 'TestClassResource/TestClassResource' }) $r.Count | Should -Be 1 $r[0].Version | Should -Be '2.0.1' - } - finally - { + } finally { $env:PSModulePath = $oldPath } } It 'Verify adapted_dsc_type field in Get' { $oldPath = $env:PATH - try - { + try { $adapterPath = Join-Path $PSScriptRoot 'TestAdapter' $env:PATH += [System.IO.Path]::PathSeparator + $adapterPath @@ -270,17 +254,14 @@ Describe 'PowerShell adapter resource tests' { $LASTEXITCODE | Should -Be 0 $resources = $r | ConvertFrom-Json $resources.actualState.result | Should -Be $True - } - finally - { + } finally { $env:PATH = $oldPath } } It 'Verify adapted_dsc_type field in Set' { $oldPath = $env:PATH - try - { + try { $adapterPath = Join-Path $PSScriptRoot 'TestAdapter' $env:PATH += [System.IO.Path]::PathSeparator + $adapterPath @@ -289,17 +270,14 @@ Describe 'PowerShell adapter resource tests' { $resources = $r | ConvertFrom-Json $resources.beforeState.result | Should -Be $True $resources.afterState.result | Should -Be $True - } - finally - { + } finally { $env:PATH = $oldPath } } It 'Verify adapted_dsc_type field in Test' { $oldPath = $env:PATH - try - { + try { $adapterPath = Join-Path $PSScriptRoot 'TestAdapter' $env:PATH += [System.IO.Path]::PathSeparator + $adapterPath @@ -307,17 +285,14 @@ Describe 'PowerShell adapter resource tests' { $LASTEXITCODE | Should -Be 0 $resources = $r | ConvertFrom-Json $resources.actualState.result | Should -Be $True - } - finally - { + } finally { $env:PATH = $oldPath } } It 'Verify adapted_dsc_type field in Export' { $oldPath = $env:PATH - try - { + try { $adapterPath = Join-Path $PSScriptRoot 'TestAdapter' $env:PATH += [System.IO.Path]::PathSeparator + $adapterPath @@ -325,9 +300,7 @@ Describe 'PowerShell adapter resource tests' { $LASTEXITCODE | Should -Be 0 $resources = $r | ConvertFrom-Json $resources.resources[0].properties.result | Should -Be $True - } - finally - { + } finally { $env:PATH = $oldPath } } @@ -347,20 +320,14 @@ Describe 'PowerShell adapter resource tests' { It 'Verify that there are no cache rebuilds for several sequential executions' { # remove cache file - $cacheFilePath = if ($IsWindows) - { + $cacheFilePath = if ($IsWindows) { # PS 6+ on Windows Join-Path $env:LocalAppData "dsc\PSAdapterCache.json" - } - else - { + } else { # either WinPS or PS 6+ on Linux/Mac - if ($PSVersionTable.PSVersion.Major -le 5) - { + if ($PSVersionTable.PSVersion.Major -le 5) { Join-Path $env:LocalAppData "dsc\WindowsPSAdapterCache.json" - } - else - { + } else { Join-Path $env:HOME ".dsc" "PSAdapterCache.json" } }