|
| 1 | +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" |
| 2 | +Import-Module $modPath -Force -Verbose |
| 3 | + |
1 | 4 | Describe "DSC resource tests" -tags 'CI' { |
2 | 5 | BeforeAll { |
3 | 6 | $DSC_ROOT = $env:DSC_ROOT |
@@ -132,3 +135,105 @@ Describe 'Repository Resource Tests' -Tags 'CI' { |
132 | 135 | } |
133 | 136 | } |
134 | 137 |
|
| 138 | +Describe "PSResourceList Resource Tests" -Tags 'CI' { |
| 139 | + BeforeAll { |
| 140 | + $DSC_ROOT = $env:DSC_ROOT |
| 141 | + if (-not (Test-Path -Path $DSC_ROOT)) { |
| 142 | + throw "DSC_ROOT environment variable is not set or path does not exist." |
| 143 | + } |
| 144 | + |
| 145 | + $env:PATH += ";$DSC_ROOT" |
| 146 | + |
| 147 | + # Ensure DSC v3 is available |
| 148 | + if (-not (Get-Command -name dsc -CommandType Application -ErrorAction SilentlyContinue)) { |
| 149 | + throw "DSC v3 is not installed" |
| 150 | + } |
| 151 | + |
| 152 | + $dscExe = Get-Command -name dsc -CommandType Application | Select-Object -First 1 |
| 153 | + |
| 154 | + $localRepo = "psgettestlocal" |
| 155 | + $testModuleName = "test_local_mod" |
| 156 | + $testModuleName2 = "test_local_mod2" |
| 157 | + $testModuleName3 = "Test_Local_Mod3" |
| 158 | + Get-NewPSResourceRepositoryFile |
| 159 | + Register-LocalRepos |
| 160 | + |
| 161 | + $localRepoUriAddress = Join-Path -Path $TestDrive -ChildPath "testdir" |
| 162 | + |
| 163 | + New-TestModule -moduleName $testModuleName -repoName $localRepo -packageVersion "1.0.0" -prereleaseLabel "" -tags @() |
| 164 | + New-TestModule -moduleName $testModuleName -repoName $localRepo -packageVersion "5.0.0" -prereleaseLabel "" -tags @() |
| 165 | + New-TestModule -moduleName $testModuleName2 -repoName $localRepo -packageVersion "5.0.0" -prereleaseLabel "" -tags @() |
| 166 | + New-TestModule -moduleName $testModuleName3 -repoName $localRepo -packageVersion "1.0.0" -prereleaseLabel "" -tags @() |
| 167 | + } |
| 168 | + AfterAll { |
| 169 | + # Clean up the test repository |
| 170 | + Get-RevertPSResourceRepositoryFile |
| 171 | + } |
| 172 | + |
| 173 | + It 'Can get a PSResourceList resource instance' { |
| 174 | + $psResourceListParams = @{ |
| 175 | + repositoryName = $localRepo |
| 176 | + resources = @() |
| 177 | + } |
| 178 | + |
| 179 | + $resourceInput = $psResourceListParams | ConvertTo-Json -Depth 5 |
| 180 | + |
| 181 | + $getResult = & $dscExe resource get --resource Microsoft.PowerShell.PSResourceGet/PSResourceList --input $resourceInput -o json | ConvertFrom-Json |
| 182 | + |
| 183 | + $getResult.actualState.repositoryName | Should -BeExactly $localRepo |
| 184 | + $getResult.actualState.resources.Count | Should -Be 0 |
| 185 | + } |
| 186 | + |
| 187 | + It 'Can get a PSResourceList resource instance with resources' { |
| 188 | + $psResourceListParams = @{ |
| 189 | + repositoryName = $localRepo |
| 190 | + resources = @( |
| 191 | + @{ |
| 192 | + name = $testModuleName |
| 193 | + version = '1.0.0' |
| 194 | + }, |
| 195 | + @{ |
| 196 | + name = $testModuleName2 |
| 197 | + version = '5.0.0' |
| 198 | + } |
| 199 | + ) |
| 200 | + } |
| 201 | + |
| 202 | + $resourceInput = $psResourceListParams | ConvertTo-Json -Depth 5 |
| 203 | + $getResult = & $dscExe resource get --resource Microsoft.PowerShell.PSResourceGet/PSResourceList --input $resourceInput -o json | ConvertFrom-Json |
| 204 | + $getResult.actualState.repositoryName | Should -BeExactly $localRepo |
| 205 | + $getResult.actualState.resources.Count | Should -Be 2 |
| 206 | + $getResult.actualState.resources[0].name | Should -BeExactly $testModuleName |
| 207 | + $getResult.actualState.resources[0]._exist | Should -BeFalse |
| 208 | + $getResult.actualState.resources[1].name | Should -BeExactly $testModuleName2 |
| 209 | + $getResult.actualState.resources[1]._exist | Should -BeFalse |
| 210 | + } |
| 211 | + |
| 212 | + It 'Can set a PSResourceList resource instance with resources' { |
| 213 | + $psResourceListParams = @{ |
| 214 | + repositoryName = $localRepo |
| 215 | + resources = @( |
| 216 | + @{ |
| 217 | + name = $testModuleName |
| 218 | + version = '1.0.0' |
| 219 | + }, |
| 220 | + @{ |
| 221 | + name = $testModuleName2 |
| 222 | + version = '5.0.0' |
| 223 | + } |
| 224 | + ) |
| 225 | + } |
| 226 | + |
| 227 | + $resourceInput = $psResourceListParams | ConvertTo-Json -Depth 5 |
| 228 | + $getResult = & $dscExe resource set --resource Microsoft.PowerShell.PSResourceGet/PSResourceList --input $resourceInput -o json | ConvertFrom-Json |
| 229 | + $getResult.actualState.repositoryName | Should -BeExactly $localRepo |
| 230 | + $getResult.actualState.resources.Count | Should -Be 2 |
| 231 | + $getResult.actualState.resources[0].name | Should -BeExactly $testModuleName |
| 232 | + $getResult.actualState.resources[0].version | Should -BeExactly '5.0.0' |
| 233 | + $getResult.actualState.resources[1].name | Should -BeExactly $testModuleName2 |
| 234 | + $getResult.actualState.resources[1].version | Should -BeExactly '1.0.0' |
| 235 | + } |
| 236 | + |
| 237 | + |
| 238 | +} |
| 239 | + |
0 commit comments