Skip to content

Commit

Permalink
Resolve remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
G.Reijn authored and G.Reijn committed Dec 9, 2024
1 parent b7e94a8 commit 1a488e3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 58 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"./y2j/Cargo.toml"
],
"rust-analyzer.showUnlinkedFileNotification": true,
"powershell.codeFormatting.preset": "OTBS",
"json.schemas": [
{
"fileMatch": ["**/*.dsc.resource.json"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
77 changes: 22 additions & 55 deletions powershell-adapter/Tests/powershellgroup.resource.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down Expand Up @@ -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"
}
}
Expand All @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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

Expand All @@ -252,35 +239,29 @@ 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

$r = '{TestCaseId: 1}' | dsc resource get -r 'Test/TestCase' -f -
$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

Expand All @@ -289,45 +270,37 @@ 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

$r = '{TestCaseId: 1}' | dsc resource test -r 'Test/TestCase' -f -
$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

$r = dsc resource export -r 'Test/TestCase'
$LASTEXITCODE | Should -Be 0
$resources = $r | ConvertFrom-Json
$resources.resources[0].properties.result | Should -Be $True
}
finally
{
} finally {
$env:PATH = $oldPath
}
}
Expand All @@ -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"
}
}
Expand Down

0 comments on commit 1a488e3

Please sign in to comment.