Skip to content

Commit 771e649

Browse files
authored
Update tests for PowerShell 7-Preview.3 release (#27)
1 parent eb782de commit 771e649

File tree

2 files changed

+142
-33
lines changed

2 files changed

+142
-33
lines changed

src/.ci/test.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ jobs:
1313
- ${{ parameters.powershellExecutable }}: |
1414
if($IsMacOs)
1515
{
16+
brew update
1617
brew cask install powershell-preview
1718
sudo ln -s -f /usr/local/microsoft/powershell/7-preview/pwsh /usr/local/bin/pwsh
1819
}
1920
elseif($IsLinux)
2021
{
22+
sudo apt-get update
2123
sudo apt-get install powershell-preview
2224
sudo ln -s /opt/microsoft/powershell/7-preview/pwsh /usr/local/bin/pwsh
2325
}
@@ -42,16 +44,6 @@ jobs:
4244
dir env:PATH
4345
displayName: Capture Path
4446
45-
- bash: |
46-
# Patching to fix MMI issue until PowerShell 7 Preview 3 can be released with the fix
47-
curl --output ./Microsoft.Management.Infrastructure.dll https://pscoretestdata.blob.core.windows.net/psdesiredstateconfiguration/Microsoft.Management.Infrastructure.dll
48-
echo "copying to $PSHOME/Microsoft.Management.Infrastructure.dll"
49-
ls -l "$PSHOME/Microsoft.Management.Infrastructure.dll"
50-
sudo cp ./Microsoft.Management.Infrastructure.dll "$PSHOME/Microsoft.Management.Infrastructure.dll"
51-
ls -l "$PSHOME/Microsoft.Management.Infrastructure.dll"
52-
displayName: Patch macOS
53-
condition: and( eq('${{ parameters.imageName }}', 'macOS-10.14'), succeeded())
54-
5547
- ${{ parameters.powershellExecutable }}: |
5648
Get-PSRepository
5749
displayName: Capture PSRepository
@@ -65,7 +57,7 @@ jobs:
6557
Install-Module -Name "PSScriptAnalyzer" -RequiredVersion 1.18.0 -Force
6658
displayName: Install dependencies
6759
timeoutInMinutes: 10
68-
60+
6961
- ${{ parameters.powershellExecutable }}: |
7062
Install-Module -Name PSPackageProject -Force
7163
displayName: Install PSPackageProject module

test/PSDesiredStateConfiguration.Tests.ps1

Lines changed: 139 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
Function Install-ModuleIfMissing
2+
{
3+
param(
4+
[parameter(Mandatory)]
5+
[String]
6+
$Name,
7+
[version]
8+
$MinimumVersion,
9+
[switch]
10+
$SkipPublisherCheck,
11+
[switch]
12+
$Force
13+
)
14+
15+
$module = Get-Module -Name $Name -ListAvailable -ErrorAction Ignore | Sort-Object -Property Version -Descending | Select-Object -First 1
16+
17+
if(!$module -or $module.Version -lt $MinimumVersion)
18+
{
19+
Write-Verbose "Installing module '$Name' ..." -Verbose
20+
Install-Module -Name $Name -Force -SkipPublisherCheck:$SkipPublisherCheck.IsPresent
21+
}
22+
}
23+
124
Describe "Test PSDesiredStateConfiguration" -tags CI {
225
Context "Module loading" {
326
BeforeAll {
@@ -27,11 +50,99 @@ Describe "Test PSDesiredStateConfiguration" -tags CI {
2750
$commands | Where-Object {$_.Name -eq 'Get-DscResource'} | Should -Not -BeNullOrEmpty
2851
}
2952
}
53+
Context "Get-DscResource - Composite Resources" {
54+
BeforeAll {
55+
$origProgress = $global:ProgressPreference
56+
$global:ProgressPreference = 'SilentlyContinue'
57+
Install-ModuleIfMissing -Name PSDscResources
58+
$testCases = @(
59+
@{
60+
TestCaseName = 'case mismatch in resource name'
61+
Name = 'groupset'
62+
ModuleName = 'PSDscResources'
63+
}
64+
@{
65+
TestCaseName = 'Both names have matching case'
66+
Name = 'GroupSet'
67+
ModuleName = 'PSDscResources'
68+
}
69+
@{
70+
TestCaseName = 'case mismatch in module name'
71+
Name = 'GroupSet'
72+
ModuleName = 'psdscResources'
73+
}
74+
)
75+
}
76+
AfterAll {
77+
$Global:ProgressPreference = $origProgress
78+
}
79+
it "should be able to get <Name> - <TestCaseName>" -TestCases $testCases {
80+
param($Name)
81+
82+
if($IsWindows)
83+
{
84+
Set-ItResult -Pending -Because "Will only find script from PSDesiredStateConfiguration without modulename"
85+
}
86+
87+
if($IsLinux)
88+
{
89+
Set-ItResult -Pending -Because "https://github.com/PowerShell/PSDesiredStateConfiguration/issues/26"
90+
}
91+
92+
$resource = Get-DscResource -Name $name
93+
$resource | Should -Not -BeNullOrEmpty
94+
$resource.Name | Should -Be $Name
95+
$resource.ImplementationDetail | Should -BeNullOrEmpty
96+
}
97+
98+
it "should be able to get <Name> from <ModuleName> - <TestCaseName>" -TestCases $testCases {
99+
param($Name,$ModuleName, $PendingBecause)
100+
101+
if($IsLinux)
102+
{
103+
Set-ItResult -Pending -Because "https://github.com/PowerShell/PSDesiredStateConfiguration/issues/26"
104+
}
105+
106+
if($PendingBecause)
107+
{
108+
Set-ItResult -Pending -Because $PendingBecause
109+
}
110+
$resource = Get-DscResource -Name $Name -Module $ModuleName
111+
$resource | Should -Not -BeNullOrEmpty
112+
$resource.Name | Should -Be $Name
113+
$resource.ImplementationDetail | Should -BeNullOrEmpty
114+
}
115+
}
30116
Context "Get-DscResource - ScriptResources" {
31117
BeforeAll {
32118
$origProgress = $global:ProgressPreference
33119
$global:ProgressPreference = 'SilentlyContinue'
120+
121+
Install-ModuleIfMissing -Name PSDscResources -Force
122+
123+
Install-ModuleIfMissing -Name PowerShellGet -MinimumVersion '2.2.1'
124+
$module = Get-Module PowerShellGet -ListAvailable | Sort-Object -Property Version -Descending | Select-Object -First 1
125+
126+
$psGetModuleSpecification = @{ModuleName=$module.Name;ModuleVersion=$module.Version.ToString()}
127+
$psGetModuleCount = @(Get-Module PowerShellGet -ListAvailable).Count
34128
$testCases = @(
129+
@{
130+
TestCaseName = 'case mismatch in resource name'
131+
Name = 'script'
132+
ModuleName = 'PSDscResources'
133+
}
134+
@{
135+
TestCaseName = 'Both names have matching case'
136+
Name = 'Script'
137+
ModuleName = 'PSDscResources'
138+
}
139+
@{
140+
TestCaseName = 'case mismatch in module name'
141+
Name = 'Script'
142+
ModuleName = 'psdscResources'
143+
}
144+
<#
145+
Add these back when PowerShellGet is fixed https://github.com/PowerShell/PowerShellGet/pull/529
35146
@{
36147
TestCaseName = 'case mismatch in resource name'
37148
Name = 'PsModule'
@@ -46,9 +157,8 @@ Describe "Test PSDesiredStateConfiguration" -tags CI {
46157
TestCaseName = 'case mismatch in module name'
47158
Name = 'PSModule'
48159
ModuleName = 'powershellget'
49-
# Linux issue: https://github.com/PowerShell/PSDesiredStateConfiguration/issues/12
50-
PendingBecause = 'https://github.com/PowerShell/PSDesiredStateConfiguration/issues/12'
51160
}
161+
#>
52162
)
53163
}
54164
AfterAll {
@@ -58,34 +168,45 @@ Describe "Test PSDesiredStateConfiguration" -tags CI {
58168
it "should be able to get <Name> - <TestCaseName>" -TestCases $testCases {
59169
param($Name)
60170

61-
if($IsLinux -or $IsWindows)
171+
if($IsWindows)
62172
{
63-
Set-ItResult -Pending -Because "https://github.com/PowerShell/PSDesiredStateConfiguration/issues/15"
173+
Set-ItResult -Pending -Because "Will only find script from PSDesiredStateConfiguration without modulename"
64174
}
65175

66-
$resource = Get-DscResource -Name $name
67-
$resource | Should -Not -BeNullOrEmpty
68-
$resource.Name | Should -Be $Name
176+
if($PendingBecause)
177+
{
178+
Set-ItResult -Pending -Because $PendingBecause
179+
}
180+
181+
$resources = @(Get-DscResource -Name $name)
182+
$resources | Should -Not -BeNullOrEmpty
183+
foreach($resource in $resource)
184+
{
185+
$resource.Name | Should -Be $Name
186+
}
69187
}
70188

71189
it "should be able to get <Name> from <ModuleName> - <TestCaseName>" -TestCases $testCases {
72190
param($Name,$ModuleName, $PendingBecause)
73191

74192
if($IsLinux)
75193
{
76-
Set-ItResult -Pending -Because "https://github.com/PowerShell/PSDesiredStateConfiguration/issues/12"
194+
Set-ItResult -Pending -Because "https://github.com/PowerShell/PSDesiredStateConfiguration/issues/12 and https://github.com/PowerShell/PowerShellGet/pull/529"
77195
}
78196

79197
if($PendingBecause)
80198
{
81199
Set-ItResult -Pending -Because $PendingBecause
82200
}
83-
$resource = Get-DscResource -Name $Name -Module $ModuleName
84-
$resource | Should -Not -BeNullOrEmpty
85-
$resource.Name | Should -Be $Name
201+
202+
$resources = @(Get-DscResource -Name $name -Module $ModuleName)
203+
$resources | Should -Not -BeNullOrEmpty
204+
foreach($resource in $resource)
205+
{
206+
$resource.Name | Should -Be $Name
207+
}
86208
}
87209

88-
# Fails on all platforms
89210
it "should throw when resource is not found" {
90211
Set-ItResult -Pending -Because "https://github.com/PowerShell/PSDesiredStateConfiguration/issues/17"
91212
{
@@ -99,19 +220,17 @@ Describe "Test PSDesiredStateConfiguration" -tags CI {
99220
BeforeAll {
100221
$origProgress = $global:ProgressPreference
101222
$global:ProgressPreference = 'SilentlyContinue'
102-
Install-Module -Name XmlContentDsc -Force
223+
Install-ModuleIfMissing -Name XmlContentDsc -Force
103224
$classTestCases = @(
104225
@{
105226
TestCaseName = 'Good case'
106227
Name = 'XmlFileContentResource'
107228
ModuleName = 'XmlContentDsc'
108-
PendingBecause = "https://github.com/PowerShell/PSDesiredStateConfiguration/issues/19"
109229
}
110230
@{
111231
TestCaseName = 'Module Name case mismatch'
112232
Name = 'XmlFileContentResource'
113233
ModuleName = 'xmlcontentdsc'
114-
PendingBecause = 'https://github.com/PowerShell/PSDesiredStateConfiguration/issues/12'
115234
}
116235
@{
117236
TestCaseName = 'Resource name case mismatch'
@@ -122,29 +241,27 @@ Describe "Test PSDesiredStateConfiguration" -tags CI {
122241
}
123242
AfterAll {
124243
$Global:ProgressPreference = $origProgress
125-
Uninstall-Module -name XmlContentDsc -AllVersions
126244
}
127245

128-
# Fix for most of thse are in https://github.com/PowerShell/PowerShell/pull/10350
129246
it "should be able to get class resource - <Name> from <ModuleName> - <TestCaseName>" -TestCases $classTestCases {
130247
param($Name,$ModuleName, $PendingBecause)
131-
if($IsLinux -or $IsMacOs)
132-
{
133-
Set-ItResult -Pending -Because "Fix for most of these are in https://github.com/PowerShell/PowerShell/pull/10350"
134-
}
135248

136249
if($PendingBecause)
137250
{
138251
Set-ItResult -Pending -Because $PendingBecause
139252
}
253+
140254
$resource = Get-DscResource -Name $Name -Module $ModuleName
141255
$resource | Should -Not -BeNullOrEmpty
142256
$resource.Name | Should -Be $Name
143257
}
144258

145259
it "should be able to get class resource - <Name> - <TestCaseName>" -TestCases $classTestCases {
146260
param($Name,$ModuleName, $PendingBecause)
147-
Set-ItResult -Pending -Because "https://github.com/PowerShell/PSDesiredStateConfiguration/issues/19"
261+
if($IsWindows)
262+
{
263+
Set-ItResult -Pending -Because "https://github.com/PowerShell/PSDesiredStateConfiguration/issues/19"
264+
}
148265
if($PendingBecause)
149266
{
150267
Set-ItResult -Pending -Because $PendingBecause

0 commit comments

Comments
 (0)