|
| 1 | +# Copyright (c) Microsoft Corporation. |
| 2 | +# Licensed under the MIT License. |
| 3 | + |
| 4 | +Describe 'Apt resource tests' { |
| 5 | + BeforeAll { |
| 6 | + $aptExists = ($null -ne (Get-Command apt -CommandType Application -ErrorAction Ignore)) |
| 7 | + } |
| 8 | + |
| 9 | + Context "export" { |
| 10 | + It "should have more than 20 resources" -Skip:$(! $IsLinux) { |
| 11 | + if (-not $aptExists) { |
| 12 | + Set-ItResult -Skip -Because "Apt not found" |
| 13 | + } |
| 14 | + |
| 15 | + $result = dsc resource export --resource DSC.PackageManagement/Apt | ConvertFrom-Json |
| 16 | + $result.resources.Count | Should -BeGreaterThan 20 |
| 17 | + } |
| 18 | + } |
| 19 | + |
| 20 | + Context "wget tests" { |
| 21 | + BeforeAll { |
| 22 | + $pkgName = "wget" |
| 23 | + $yamlPath = "$PSScriptRoot/assets/apt_${pkgName}.dsc.yaml" |
| 24 | + } |
| 25 | + |
| 26 | + It 'Config get works' -Skip:$(! $IsLinux) { |
| 27 | + if (-not $aptExists) { |
| 28 | + Set-ItResult -Skip -Because "Apt not found" |
| 29 | + } |
| 30 | + $out = dsc config get -p $yamlPath | ConvertFrom-Json -Depth 10 |
| 31 | + $LASTEXITCODE | Should -Be 0 |
| 32 | + $exists = $null -ne (Get-Command $pkgName -CommandType Application -ErrorAction Ignore) |
| 33 | + $observed = $out.results[1].result.actualState._exist |
| 34 | + $observed | Should -Be $exists |
| 35 | + } |
| 36 | + |
| 37 | + It 'Config test works' -Skip:$(! $IsLinux) { |
| 38 | + if (-not $aptExists) { |
| 39 | + Set-ItResult -Skip -Because "Apt not found" |
| 40 | + } |
| 41 | + |
| 42 | + $out = dsc config test -p $yamlPath| ConvertFrom-Json -Depth 10 |
| 43 | + $LASTEXITCODE | Should -Be 0 |
| 44 | + $exists = $null -ne (Get-Command pkgName -CommandType Application -ErrorAction Ignore) |
| 45 | + $out.results[1].result.inDesiredState | Should -Be $exists |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + Context "install/uninstall rolldice tests" { |
| 50 | + BeforeAll { |
| 51 | + $pkgName = "rolldice" |
| 52 | + $yamlInstallPath = "$PSScriptRoot/assets/apt_install_${pkgName}.dsc.yaml" |
| 53 | + $yamlUnInstallPath = "$PSScriptRoot/assets/apt_uninstall_${pkgName}.dsc.yaml" |
| 54 | + } |
| 55 | + |
| 56 | + It 'Can install a package' -Skip:$(! $IsLinux) { |
| 57 | + Set-ItResult -Skip -Because "Apt requires sudo" |
| 58 | + |
| 59 | + if (apt list $pkgname 2>&1 | Select-String installed ) { |
| 60 | + apt remove -y $pkgname |
| 61 | + } |
| 62 | + |
| 63 | + $result = dsc config set -p $yamlInstallPath | ConvertFrom-Json |
| 64 | + $result.results[1].result.beforestate._exist | Should -Be false |
| 65 | + $result.results[1].result.afterstate._exist | Should -Be true |
| 66 | + } |
| 67 | + |
| 68 | + It 'Can uninstall a package' -Skip:$(! $IsLinux) { |
| 69 | + Set-ItResult -Skip -Because "Apt requires sudo" |
| 70 | + |
| 71 | + if ($null -eq (apt list $pkgName 2>&1 | Select-String installed)) { |
| 72 | + apt install -y $pkgname |
| 73 | + } |
| 74 | + |
| 75 | + $result = dsc config set -p $yamlUnInstallPath | ConvertFrom-Json |
| 76 | + $result.results[1].result.beforestate._exist | Should -Be true |
| 77 | + $result.results[1].result.afterstate._exist | Should -Be false |
| 78 | + } |
| 79 | + } |
| 80 | +} |
0 commit comments