Skip to content

Commit a0a4fba

Browse files
committed
logging
1 parent 03ac34c commit a0a4fba

File tree

2 files changed

+43
-71
lines changed

2 files changed

+43
-71
lines changed
Lines changed: 40 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,44 @@
1-
# # Copyright (c) Microsoft Corporation.
2-
# # Licensed under the MIT License.
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
33

4-
# BeforeDiscovery {
5-
# if ($IsWindows) {
6-
# $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
7-
# $principal = [System.Security.Principal.WindowsPrincipal]::new($identity)
8-
# $isElevated = $principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
4+
BeforeDiscovery {
5+
if ($IsWindows) {
6+
$identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
7+
$principal = [System.Security.Principal.WindowsPrincipal]::new($identity)
8+
$isElevated = $principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
99

10-
# if ($env:GITHUB_ACTION) {
11-
# $script:currentModulePaths = $env:PSModulePath
12-
# Write-Verbose -Message "Running in GitHub Actions" -Verbose
13-
# # Uninstall the PSDesiredStateConfiguration module as this requires v1.1 and the build script installs it
14-
# Uninstall-PSResource -Name 'PSDesiredStateConfiguration' -Version 2.0.7 -ErrorAction Stop
15-
# # Get current PSModulePath and exclude PowerShell 7 paths
16-
# $currentPaths = $env:PSModulePath -split ';' | Where-Object {
17-
# $_ -notmatch 'PowerShell[\\/]7' -and
18-
# $_ -notmatch 'Program Files[\\/]PowerShell[\\/]' -and
19-
# $_ -notmatch 'Documents[\\/]PowerShell[\\/]'
20-
# }
21-
22-
# # Check if Windows PowerShell modules path exists
23-
# $windowsPSPath = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\Modules"
24-
# if ($windowsPSPath -notin $currentPaths) {
25-
# $currentPaths += $windowsPSPath
26-
# }
27-
28-
# # Update PSModulePath
29-
# $env:PSModulePath = $currentPaths -join ';'
30-
# }
31-
# }
32-
# }
10+
Write-Verbose -Message $env:Path -Verbose
11+
Write-Verbose -Message $env:Path -Verbose
12+
}
13+
}
3314

34-
# Describe 'PowerShell extension tests' {
35-
# It 'Example PowerShell file should work' -Skip:(!$IsWindows -or !$isElevated) {
36-
# $psFile = Resolve-Path -Path "$PSScriptRoot\..\..\dsc\examples\variable.dsc.ps1"
37-
# $out = dsc -l trace config get -f $psFile 2>$TestDrive/error.log | ConvertFrom-Json
38-
# $LASTEXITCODE | Should -Be 0 -Because (Get-Content -Path $TestDrive/error.log -Raw | Out-String)
39-
# $out.results[0].result.actualState.Ensure | Should -Be 'Absent'
40-
# (Get-Content -Path $TestDrive/error.log -Raw) | Should -Match "Importing file '$psFile' with extension 'Microsoft.DSC.Extension/PowerShell'"
41-
# }
15+
Describe 'PowerShell extension tests' {
16+
It 'Example PowerShell file should work' -Skip:(!$IsWindows -or !$isElevated) {
17+
$psFile = Resolve-Path -Path "$PSScriptRoot\..\..\dsc\examples\variable.dsc.ps1"
18+
$out = dsc -l trace config get -f $psFile 2>$TestDrive/error.log | ConvertFrom-Json
19+
$LASTEXITCODE | Should -Be 0 -Because (Get-Content -Path $TestDrive/error.log -Raw | Out-String)
20+
$out.results[0].result.actualState.Ensure | Should -Be 'Absent'
21+
(Get-Content -Path $TestDrive/error.log -Raw) | Should -Match "Importing file '$psFile' with extension 'Microsoft.DSC.Extension/PowerShell'"
22+
}
4223

43-
# It 'Invalid PowerShell configuration document file returns error' -Skip:(!$IsWindows) {
44-
# $psFile = "$TestDrive/invalid.ps1"
45-
# Set-Content -Path $psFile -Value @"
46-
# configuration InvalidConfiguration {
47-
# Import-DscResource -ModuleName InvalidModule
48-
# Node localhost
49-
# {
50-
# Test Invalid {
51-
# Name = 'InvalidTest'
52-
# Ensure = 'Present'
53-
# }
54-
# }
55-
# }
56-
# "@
57-
# dsc -l trace config get -f $psFile 2>$TestDrive/error.log
58-
# $LASTEXITCODE | Should -Be 2 -Because (Get-Content -Path $TestDrive/error.log -Raw | Out-String)
59-
# $content = (Get-Content -Path $TestDrive/error.log -Raw)
60-
# $content | Should -BeLike "*Importing file '$psFile' with extension 'Microsoft.DSC.Extension/WindowsPowerShell'*"
61-
# $content | Should -Match "No DSC resources found in the imported modules."
62-
# }
63-
# }
64-
65-
# AfterAll {
66-
# if ($IsWindows -and $env:GITHUB_ACTION) {
67-
# Install-PSResource -Name 'PSDesiredStateConfiguration' -Version 2.0.7 -ErrorAction Stop -TrustRepository -Reinstall
68-
# }
69-
70-
# Write-Verbose -Message "Restoring original PSModulePath" -Verbose
71-
# Write-Verbose -Message ($script:currentModulePaths) -Verbose
72-
# $env:PSModulePath = $script:currentModulePaths
73-
# }
24+
It 'Invalid PowerShell configuration document file returns error' -Skip:(!$IsWindows) {
25+
$psFile = "$TestDrive/invalid.ps1"
26+
Set-Content -Path $psFile -Value @"
27+
configuration InvalidConfiguration {
28+
Import-DscResource -ModuleName InvalidModule
29+
Node localhost
30+
{
31+
Test Invalid {
32+
Name = 'InvalidTest'
33+
Ensure = 'Present'
34+
}
35+
}
36+
}
37+
"@
38+
dsc -l trace config get -f $psFile 2>$TestDrive/error.log
39+
$LASTEXITCODE | Should -Be 2 -Because (Get-Content -Path $TestDrive/error.log -Raw | Out-String)
40+
$content = (Get-Content -Path $TestDrive/error.log -Raw)
41+
$content | Should -BeLike "*Importing file '$psFile' with extension 'Microsoft.DSC.Extension/WindowsPowerShell'*"
42+
$content | Should -Match "No DSC resources found in the imported modules."
43+
}
44+
}

powershell-adapter/Tests/win_powershell_cache.tests.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ Describe 'WindowsPowerShell adapter resource tests - requires elevated permissio
4848
}
4949

5050
It 'Get works on Binary "File" resource' {
51-
51+
Write-Verbose -Message $env:Path -Verbose
52+
Write-Verbose -Message $env:PSModulePath -Verbose
5253
$testFile = "$testdrive\test.txt"
5354
'test' | Set-Content -Path $testFile -Force
54-
$r = '{"DestinationPath":"' + $testFile.replace('\', '\\') + '"}' | dsc resource get -r 'PSDesiredStateConfiguration/File' -f -
55+
$r = '{"DestinationPath":"' + $testFile.replace('\', '\\') + '"}' | dsc -l trace resource get -r 'PSDesiredStateConfiguration/File' -f -
5556
$LASTEXITCODE | Should -Be 0
5657
$res = $r | ConvertFrom-Json
5758
$res.actualState.DestinationPath | Should -Be "$testFile"

0 commit comments

Comments
 (0)