From 956b8a00931ae7b7fe33f04d13592c9872267dcc Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Mon, 20 Jul 2020 07:48:50 +0000 Subject: [PATCH] Add Pester tests for Windows Features (#1225) * Add Windows Features Pester tests * Move win feature tests to separate file * Remove validation script for disc space * Remove Windows updates test --- images/win/Windows2016-Azure.json | 6 --- images/win/Windows2019-Azure.json | 12 ------ .../Installers/Install-ContainersFeature.ps1 | 2 + .../scripts/Installers/Validate-DiskSpace.ps1 | 14 ------- .../win/scripts/Installers/Validate-WSL.ps1 | 14 ------- .../scripts/Tests/WindowsFeatures.Tests.ps1 | 41 +++++++++++++++++++ 6 files changed, 43 insertions(+), 46 deletions(-) delete mode 100644 images/win/scripts/Installers/Validate-DiskSpace.ps1 delete mode 100644 images/win/scripts/Installers/Validate-WSL.ps1 create mode 100644 images/win/scripts/Tests/WindowsFeatures.Tests.ps1 diff --git a/images/win/Windows2016-Azure.json b/images/win/Windows2016-Azure.json index e5c56c9dc..26b6e9c74 100644 --- a/images/win/Windows2016-Azure.json +++ b/images/win/Windows2016-Azure.json @@ -792,12 +792,6 @@ "{{ template_dir }}/scripts/Installers/Validate-VSWhere.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Validate-DiskSpace.ps1" - ] - }, { "type": "powershell", "scripts":[ diff --git a/images/win/Windows2019-Azure.json b/images/win/Windows2019-Azure.json index 4ba806872..a345f29a6 100644 --- a/images/win/Windows2019-Azure.json +++ b/images/win/Windows2019-Azure.json @@ -256,12 +256,6 @@ "{{ template_dir }}/scripts/Installers/Validate-Wix.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Validate-WSL.ps1" - ] - }, { "type": "powershell", "scripts":[ @@ -797,12 +791,6 @@ "{{ template_dir }}/scripts/Installers/Validate-AliyunCli.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Validate-DiskSpace.ps1" - ] - }, { "type": "powershell", "scripts":[ diff --git a/images/win/scripts/Installers/Install-ContainersFeature.ps1 b/images/win/scripts/Installers/Install-ContainersFeature.ps1 index a0513f5e2..2fc9d8f2d 100644 --- a/images/win/scripts/Installers/Install-ContainersFeature.ps1 +++ b/images/win/scripts/Installers/Install-ContainersFeature.ps1 @@ -15,3 +15,5 @@ if ($cpu.VirtualizationFirmwareEnabled -and $cpu.SecondLevelAddressTranslationEx } else { Write-Host "Skipping installation of Hyper-V feature" } + +Invoke-PesterTests -TestFile "WindowsFeatures" -TestName "ContainersFeature" \ No newline at end of file diff --git a/images/win/scripts/Installers/Validate-DiskSpace.ps1 b/images/win/scripts/Installers/Validate-DiskSpace.ps1 deleted file mode 100644 index d5b4f9966..000000000 --- a/images/win/scripts/Installers/Validate-DiskSpace.ps1 +++ /dev/null @@ -1,14 +0,0 @@ -################################################################################ -## File: Validate-DiskSpace.ps1 -## Desc: Validate free disk space -################################################################################ - -$availableSpaceMB = [math]::Round((Get-PSDrive -Name C).Free / 1MB) -$minimumFreeSpaceMB = 15 * 1024 - -Write-Host "Available disk space: $availableSpaceMB MB" -if ($availableSpaceMB -le $minimumFreeSpaceMB) -{ - Write-Host "Not enough disk space on the image (minimum available space: $minimumFreeSpaceMB MB)" - exit 1 -} diff --git a/images/win/scripts/Installers/Validate-WSL.ps1 b/images/win/scripts/Installers/Validate-WSL.ps1 deleted file mode 100644 index 83da69339..000000000 --- a/images/win/scripts/Installers/Validate-WSL.ps1 +++ /dev/null @@ -1,14 +0,0 @@ -################################################################################ -## File: Validate-WSL.ps1 -## Desc: Validate WSL CLI existst -################################################################################ - -if (Get-Command -Name 'wsl') -{ - Write-Host 'wsl is on path' -} -else -{ - Write-Host 'wsl not on path' - exit 1 -} diff --git a/images/win/scripts/Tests/WindowsFeatures.Tests.ps1 b/images/win/scripts/Tests/WindowsFeatures.Tests.ps1 new file mode 100644 index 000000000..7e5ec0a1e --- /dev/null +++ b/images/win/scripts/Tests/WindowsFeatures.Tests.ps1 @@ -0,0 +1,41 @@ +Describe "WindowsFeatures" { + + $testCases = @( + @{ FeatureName = "NET-Framework-Features" } + @{ FeatureName = "NET-Framework-45-Features" } + @{ FeatureName = "FS-iSCSITarget-Server" } + ) + + if (Test-isWin16) { + $testCases += @{ FeatureName = "BITS" } + $testCases += @{ FeatureName = "DSC-Service" } + } + if (Test-isWin19) { + $testCases += @{ FeatureName = "Microsoft-Windows-Subsystem-Linux" } + } + + It "Windows Feature is installed" -TestCases $testCases { + (Get-WindowsFeature -Name $FeatureName).InstallState | Should -Be "Installed" + } + + if (Test-isWin19) { + it "Check WSL is on path" { + (Get-Command -Name 'wsl') | Should -BeTrue + } + } +} + +Describe "ContainersFeature" { + It "Windows containers feature is installed" { + (Get-WindowsFeature -Name "Containers").InstallState | Should -Be "Installed" + } +} + +Describe "DiskSpace" { + it "The image has enough disk space"{ + $availableSpaceMB = [math]::Round((Get-PSDrive -Name C).Free / 1MB) + $minimumFreeSpaceMB = 18 * 1024 + + $availableSpaceMB | Should -BeGreaterThan $minimumFreeSpaceMB + } +} \ No newline at end of file