diff --git a/.MetaTestOptIn.json b/.MetaTestOptIn.json index 053c1a2..3074e38 100644 --- a/.MetaTestOptIn.json +++ b/.MetaTestOptIn.json @@ -1,4 +1,6 @@ [ - "Common Tests - Validate Markdown Files", - "Common Tests - Validate Example Files" + "Common Tests - Validate Markdown Files", + "Common Tests - Validate Example Files", + "Common Tests - Validate Module Files", + "Common Tests - Validate Script Files" ] diff --git a/.gitignore b/.gitignore index f9f0b1b..4262dae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ DSCResource.Tests +DSCResource.Tests/* .vs +/DSCResource.Tests +/DSCResource.Tests diff --git a/DSCResource.Tests b/DSCResource.Tests deleted file mode 160000 index 104da5c..0000000 --- a/DSCResource.Tests +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 104da5c476906230ccdfbd2375ac01151211efdf diff --git a/DSCResources/MSFT_Language/MSFT_Language.psm1 b/DSCResources/MSFT_Language/MSFT_Language.psm1 index 09bfe54..8ee9f7e 100644 --- a/DSCResources/MSFT_Language/MSFT_Language.psm1 +++ b/DSCResources/MSFT_Language/MSFT_Language.psm1 @@ -133,39 +133,39 @@ Function Set-TargetResource [System.String] $IsSingleInstance, - [Parameter(Mandatory = $false)] + [Parameter()] [System.Int32] $LocationID, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $MUILanguage, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $MUIFallbackLanguage, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $SystemLocale, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String[]] $AddInputLanguages, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String[]] $RemoveInputLanguages, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $UserLocale, - [Parameter(Mandatory = $false)] + [Parameter()] [System.Boolean] $CopySystem =$true, - [Parameter(Mandatory = $false)] + [Parameter()] [System.Boolean] $CopyNewUser=$true ) @@ -345,41 +345,41 @@ Function Test-TargetResource [System.String] $IsSingleInstance, - [Parameter(Mandatory = $false)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.Int32] $LocationID, - [Parameter(Mandatory = $false)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] $MUILanguage, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $MUIFallbackLanguage, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $SystemLocale, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String[]] $AddInputLanguages, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String[]] $RemoveInputLanguages, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $UserLocale, - [Parameter(Mandatory = $false)] + [Parameter()] [System.Boolean] $CopySystem, - [Parameter(Mandatory = $false)] + [Parameter()] [System.Boolean] $CopyNewUser ) diff --git a/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 b/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 index 9c7e026..6f8dfe5 100644 --- a/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 +++ b/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 @@ -9,6 +9,9 @@ .PARAMETER LanguagePackLocation Not used in Get-TargetResource. + .PARAMETER SuppressReboot + Not used in Get-TargetResource. + .PARAMETER Ensure Not used in Get-TargetResource. #> @@ -39,6 +42,7 @@ Function Get-TargetResource $returnValue = @{ LanguagePackName = [System.String]$LanguagePackName + SuppressReboot = [Boolean]$false Ensure = [System.String]$ensure } @@ -56,6 +60,10 @@ Function Get-TargetResource Either Local or Remote path to the language pack cab file. This is only used when installing a language pack + .PARAMETER SuppressReboot + If set to true the reboot required flag isn't set after successful installation of a + language pack, this can be useful to save time when installing multiple language packs. + .PARAMETER Ensure Indicates whether the given language pack should be installed or uninstalled. Set this property to Present to install the Language Pack, and Absent to uninstall @@ -71,42 +79,69 @@ Function Set-TargetResource [System.String] $LanguagePackName, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $LanguagePackLocation, - [Parameter(Mandatory = $false)] + [Parameter()] + [Boolean] + $SuppressReboot=$false, + + [Parameter()] [ValidateSet("Present","Absent")] [System.String] $Ensure="Present" ) + $timeout = 7200 - switch ($Ensure) { + switch ($Ensure) + { 'Present' { - if ($PSBoundParameters.ContainsKey('LanguagePackLocation')) + if ($PSBoundParameters.ContainsKey('LanguagePackLocation')) + { + Write-Verbose "Installing Language Pack" + if (Test-Path -Path $LanguagePackLocation) { - Write-Verbose "Installing Language Pack" - if (Test-Path -Path $LanguagePackLocation) - { - lpksetup.exe /i $LanguagePackName /p $LanguagePackLocation /r /a /s - } - else - { - Throw "Invalid source Location" - } + lpksetup.exe /i $LanguagePackName /p $LanguagePackLocation /r /a /s + $startTime = Get-Date } else { - Throw "Language Pack location must be specified when adding a new Language Pack" + Throw "Invalid source Location" } } - 'Absent' { - Write-Verbose "Removing Language Pack" - lpksetup.exe /u $LanguagePackName /r /a /s + else + { + Throw "Language Pack location must be specified when adding a new Language Pack" } + } + 'Absent' { + Write-Verbose "Removing Language Pack" + lpksetup.exe /u $LanguagePackName /r /a /s + $startTime = Get-Date + } + default { + Throw "invalid operation" + } + } + do + { + $Process = Get-Process -Name "lpksetup" -ErrorAction SilentlyContinue + $currentTime = (Get-Date) - $startTime + if ($currentTime.TotalSeconds -gt $timeout) + { + throw "Process did not complete in under $timeout seconds" + } + Write-Verbose "Waiting for Process to finish. Time Taken: $($currentTime)" + Start-Sleep -Seconds 10 + } while ($null -ne $Process) + + #allow for suppression to install multiple language packs at the same time to save time + if ($SuppressReboot -ne $true) + { + #Force a reboot after installing or removing a language pack + $global:DSCMachineStatus = 1 } - #Force a reboot after installing or removing a language pack - $global:DSCMachineStatus = 1 } <# @@ -119,6 +154,10 @@ Function Set-TargetResource .PARAMETER LanguagePackLocation Not used in Test-TargetResource. + .PARAMETER SuppressReboot + If set to true the reboot required flag isn't set after successful installation of a + language pack, this can be useful to save time when installing multiple language packs. + .PARAMETER Ensure Indicates whether the given language pack should be present or absent. Set this property to Present to install the Language Pack, and Absent to uninstall @@ -134,11 +173,15 @@ Function Test-TargetResource [System.String] $LanguagePackName, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $LanguagePackLocation, + + [Parameter()] + [Boolean] + $SuppressReboot=$false, - [Parameter(Mandatory = $false)] + [Parameter()] [ValidateSet("Present","Absent")] [System.String] $Ensure="Present" @@ -152,7 +195,8 @@ Function Test-TargetResource Write-Verbose "Language Pack Found: $Found" - switch ($Ensure) { + switch ($Ensure) + { 'Present' { $result = $Found } diff --git a/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.schema.mof b/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.schema.mof index 748bf85..17ad9da 100644 --- a/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.schema.mof +++ b/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.schema.mof @@ -4,6 +4,7 @@ class MSFT_LanguagePack : OMI_BaseResource { [Key] String LanguagePackName; [Write] String LanguagePackLocation; + [Write] Boolean SuppressReboot; [Write, ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; }; diff --git a/Examples/Sample_CombinedResourceUse.ps1 b/Examples/Sample_CombinedResourceUse.ps1 new file mode 100644 index 0000000..a00bec0 --- /dev/null +++ b/Examples/Sample_CombinedResourceUse.ps1 @@ -0,0 +1,32 @@ +Configuration Example +{ + + Import-DscResource -Module LanguageDsc + + LanguagePack InstallLanguagePack + { + LanguagePackName = "en-GB" + LanguagePackLocation = "\\fileserver1\LanguagePacks\" + } + + Language ConfigureLanguage { + IsSingleInstance = "Yes" + LocationID = 242 + MUILanguage = "en-GB" + MUIFallbackLanguage = "en-US" + SystemLocale = "en-GB" + AddInputLanguages = @("0809:00000809") + RemoveInputLanguages = @("0409:00000409") + UserLocale = "en-GB" + CopySystem = $true + CopyNewUser = $true + Dependson = "[LanguagePack]InstallLanguagePack" + } + + LocalConfigurationManager + { + RebootNodeIfNeeded = $true + ActionAfterReboot = 'ContinueConfiguration' + ConfigurationMode = 'ApplyAndAutoCorrect' + } +} diff --git a/Examples/Sample_ConfigureLanguage.ps1 b/Examples/Sample_ConfigureLanguage.ps1 index 637cd1a..f0df42f 100644 --- a/Examples/Sample_ConfigureLanguage.ps1 +++ b/Examples/Sample_ConfigureLanguage.ps1 @@ -2,19 +2,19 @@ Configuration Example { - Import-DscResource -Module LanguageDsc - Language ConfigureLanguage { - IsSingleInstance = "Yes" - LocationID = 242 - MUILanguage = "en-GB" + Language ConfigureLanguage + { + IsSingleInstance = "Yes" + LocationID = 242 + MUILanguage = "en-GB" MUIFallbackLanguage = "en-US" - SystemLocale = "en-GB" - AddInputLanguages = @("0809:00000809") + SystemLocale = "en-GB" + AddInputLanguages = @("0809:00000809") RemoveInputLanguages = @("0409:00000409") UserLocale = "en-GB" - CopySystem = $true + CopySystem = $true CopyNewUser = $true } } diff --git a/LanguageDsc.psd1 b/LanguageDsc.psd1 index 0e675ab..76da642 100644 --- a/LanguageDsc.psd1 +++ b/LanguageDsc.psd1 @@ -12,7 +12,7 @@ # RootModule = '' # Version number of this module. -ModuleVersion = '1.0' +ModuleVersion = '1.0.0.0' # Supported PSEditions # CompatiblePSEditions = @() @@ -30,7 +30,7 @@ CompanyName = "Leo D'Arcy" Copyright = "(c) 2017 Leo D'Arcy. All rights reserved." # Description of the functionality provided by this module -# Description = '' + Description = 'DSC Module for managing the installation and removal of language packs and setting language settings on Windows operating systems' # Minimum version of the Windows PowerShell engine required by this module PowerShellVersion = '4.0' @@ -75,13 +75,13 @@ FunctionsToExport = @() CmdletsToExport = @() # Variables to export from this module -VariablesToExport = '*' +VariablesToExport = @() # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. AliasesToExport = @() # DSC resources to export from this module -# DscResourcesToExport = @() +DscResourcesToExport = @('Language', 'LanguagePack') # List of all modules packaged with this module # ModuleList = @() @@ -95,19 +95,19 @@ PrivateData = @{ PSData = @{ # Tags applied to this module. These help with module discovery in online galleries. - # Tags = @() + Tags = @("Language", "LanguageDSC", "LanguagePack", "DSC", "DesiredStateConfiguration", "DSCResource") # A URL to the license for this module. - # LicenseUri = '' + LicenseUri = 'https://github.com/ld0614/LanguageDsc/blob/master/LICENSE' # A URL to the main website for this project. - # ProjectUri = '' + ProjectUri = 'https://github.com/ld0614/LanguageDsc' # A URL to an icon representing this module. # IconUri = '' # ReleaseNotes of this module - # ReleaseNotes = '' + ReleaseNotes = 'Initial Release of LanguageDSC Module containing Language and LanguagePack resources' } # End of PSData hashtable diff --git a/ModuleCreation.ps1 b/ModuleCreation.ps1 index 36cb202..f5a99bd 100644 --- a/ModuleCreation.ps1 +++ b/ModuleCreation.ps1 @@ -1,5 +1,6 @@ $LanguagePackName = New-xDscResourceProperty -Name "LanguagePackName" -Type String -Attribute Key $LanguagePackLocation = New-xDscResourceProperty -Name "LanguagePackLocation" -Type String -Attribute Write +$SuppressReboot = New-xDscResourceProperty -Name "SuppressReboot" -Type Boolean -Attribute Write $Ensure = New-xDscResourceProperty –Name Ensure -Type String -Attribute Write –ValidateSet “Present”, “Absent” $IsSingleInstance = New-xDscResourceProperty -Name "IsSingleInstance" -Type String -Attribute Key -ValidateSet “Yes” @@ -14,6 +15,6 @@ $CopySystem = New-xDscResourceProperty -Name "CopySystem" -Type Boolean -Attribu $CopyNewUser = New-xDscResourceProperty -Name "CopyNewUser" -Type Boolean -Attribute Write $CurrentInstalledLanguages = New-xDscResourceProperty -Name CurrentInstalledLanguages -Type Hashtable -Attribute Read -New-xDscResource -Name "MSFT_LanguagePack" -FriendlyName "LanguagePack" -Property $LanguagePackName, $LanguagePackLocation, $Ensure -Path "C:\Temp\DSCResources" -ModuleName "LanguageDsc" +New-xDscResource -Name "MSFT_LanguagePack" -FriendlyName "LanguagePack" -Property $LanguagePackName, $LanguagePackLocation, $SuppressReboot, $Ensure -Path "C:\Temp\DSCResources" -ModuleName "LanguageDsc" New-xDscResource -Name "MSFT_Language" -FriendlyName "Language" -Property $IsSingleInstance, $LocationID, $MUILanguage, $MUIFallbackLanguage, $SystemLocale, $AddInputLanguages, $RemoveInputLanguages, $UserLocale, $CopySystem, $CopyNewUser, $CurrentInstalledLanguages -Path "C:\Temp\DSCResources" -ModuleName "LanguageDsc" diff --git a/README.md b/README.md index 151669b..7b09839 100644 --- a/README.md +++ b/README.md @@ -48,3 +48,15 @@ This resource will install or remove a single language pack from the target syst * Initial release with the following resources: * Language * LanguagePack + +## How to Test + +This resource is configured to exclude integration tests from its automated testing utilizing appveyor. This is due to the external dependencies required for the langagePack Resource. To configure a valid testing environment the following prerequisites are required: + +* Windows Server Operating System with en-US language installed +* Git for Windows +* C:\LanguagePacks must exist +* en-GB (English-UK) Language Pack must be in C:\LanguagePacks +* de-DE (German) Language Pack must be in C:\LanguagePacks + +These specifics can be controlled by modifying the MSFT_LanguagePack.Integration.Tests.ps1 file diff --git a/Tests/Integration/MSFT_Language.Integration.Tests.ps1 b/Tests/Integration/MSFT_Language.Integration.Tests.ps1 index a4a5c95..de2d74e 100644 --- a/Tests/Integration/MSFT_Language.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_Language.Integration.Tests.ps1 @@ -18,20 +18,74 @@ $TestEnvironment = Initialize-TestEnvironment ` #endregion -# TODO: Other Init Code Goes Here... +Import-Module "$script:moduleRoot\DSCResources\$script:DSCResourceName\$script:DSCResourceName.psm1" # Using try/finally to always cleanup. try { + $LocationID = 242 + $MUILanguage = "en-GB" + $MUIFallbackLanguage = 'en-US' + $SystemLocale = 'en-GB' + $AddInputLanguages = "0809:00000809" + $RemoveInputLanguages = "0409:00000409" + $UserLocale = "en-GB" + + Describe "Pre-flight Checks" -Tag "Integration" { + Context "Ensure System requires modification" { + $CurrentState = Get-TargetResource -IsSingleInstance "Yes" + It "LocationID requires modification" { + $CurrentState.LocationID | Should Not Be $LocationID + } + + It "MUILanguage requires modification" { + #$CurrentState = Get-TargetResource -IsSingleInstance "Yes" + $CurrentState.MUILanguage | Should Not Be $MUILanguage + } + + It "MUI Fallback Language requires modification" { + #$CurrentState = Get-TargetResource -IsSingleInstance "Yes" + $CurrentState.MUIFallbackLanguage | Should Not Be $MUIFallbackLanguage + } + + It "System Locale requires modification" { + #$CurrentState = Get-TargetResource -IsSingleInstance "Yes" + $CurrentState.SystemLocale | Should Not Be $SystemLocale + } + + It "$AddInputLanguages keyboard is not already installed" { + #$CurrentState = Get-TargetResource -IsSingleInstance "Yes" + $CurrentState.CurrentInstalledLanguages.Values | Should Not Match $AddInputLanguages + } + + It "$RemoveInputLanguages keyboard should be installed" { + #$CurrentState = Get-TargetResource -IsSingleInstance "Yes" + $CurrentState.CurrentInstalledLanguages.Values | Should Match $RemoveInputLanguages + } + + It "User Locale requires modification" { + #$CurrentState = Get-TargetResource -IsSingleInstance "Yes" + $CurrentState.UserLocale | Should Not Be $UserLocale + } + } + } + #region Integration Tests $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1" . $configFile - Describe "$($script:DSCResourceName)_Integration" -Tag "Integration" { + Describe "$($script:DSCResourceName)_Integration" -Tag "Integration","RebootRequired" { #region DEFAULT TESTS It 'Should compile and apply the MOF without throwing' { { - & "$($script:DSCResourceName)_Config" -OutputPath $TestDrive + & "$($script:DSCResourceName)_Config" -OutputPath $TestDrive ` + -LocationID $LocationID ` + -MUILanguage $MUILanguage ` + -MUIFallbackLanguage $MUIFallbackLanguage ` + -SystemLocale $SystemLocale ` + -AddInputLanguages $AddInputLanguages ` + -RemoveInputLanguages $RemoveInputLanguages ` + -UserLocale $UserLocale Start-DscConfiguration -Path $TestDrive ` -ComputerName localhost -Wait -Verbose -Force } | Should not throw @@ -42,8 +96,17 @@ try } #endregion - It 'Should have set the resource and all the parameters should match' { - # TODO: Validate the Config was Set Correctly Here... + It 'Resource Test should return true' { + Test-TargetResource -IsSingleInstance "Yes" ` + -LocationID $LocationID ` + -MUILanguage $MUILanguage ` + -MUIFallbackLanguage $MUIFallbackLanguage ` + -SystemLocale $SystemLocale ` + -AddInputLanguages $AddInputLanguages ` + -RemoveInputLanguages $RemoveInputLanguages ` + -UserLocale $UserLocale ` + -CopySystem $true ` + -CopyNewUser $true | Should Be $true } } #endregion diff --git a/Tests/Integration/MSFT_Language.config.ps1 b/Tests/Integration/MSFT_Language.config.ps1 index 35001e0..96d65bc 100644 --- a/Tests/Integration/MSFT_Language.config.ps1 +++ b/Tests/Integration/MSFT_Language.config.ps1 @@ -1,19 +1,42 @@ # Integration Test Config Template Version: 1.0.0 configuration MSFT_Language_Config { - + Param + ( + [Parameter(Mandatory=$true)] + [Int] + $LocationID, + [Parameter(Mandatory=$true)] + [String] + $MUILanguage, + [Parameter(Mandatory=$true)] + [String] + $MUIFallbackLanguage, + [Parameter(Mandatory=$true)] + [String] + $SystemLocale, + [Parameter(Mandatory=$true)] + [String] + $AddInputLanguages, + [Parameter(Mandatory=$true)] + [String] + $RemoveInputLanguages, + [Parameter(Mandatory=$true)] + [String] + $UserLocale + ) Import-DscResource -ModuleName LanguageDsc node localhost { Language Integration_Test { IsSingleInstance = "Yes" - LocationID = 242 - MUILanguage = "en-GB" - MUIFallbackLanguage = "en-US" - SystemLocale = "en-GB" - AddInputLanguages = @("0809:00000809") - RemoveInputLanguages = @("0409:00000409") - UserLocale = "en-GB" + LocationID = $LocationID + MUILanguage = $MUILanguage + MUIFallbackLanguage = $MUIFallbackLanguage + SystemLocale = $SystemLocale + AddInputLanguages = $AddInputLanguages + RemoveInputLanguages = $RemoveInputLanguages + UserLocale = $UserLocale CopySystem = $true CopyNewUser = $true } diff --git a/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 b/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 index a6b308c..0471507 100644 --- a/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 @@ -17,21 +17,87 @@ $TestEnvironment = Initialize-TestEnvironment ` -TestType Integration #endregion - -# TODO: Other Init Code Goes Here... +Import-Module "$script:moduleRoot\DSCResources\$script:DSCResourceName\$script:DSCResourceName.psm1" # Using try/finally to always cleanup. try { - #region Integration Tests + $LanguagePackFolderLocation = "c:\LanguagePacks\" + $LanguagePackFileLocation = "c:\LanguagePacks\x64fre_Server_de-de_lp.cab" + $NewLanguagePackFromFolder = 'en-GB' + $NewLanguagePackFromFile = 'de-DE' + $RemoveLanguagePack = 'en-US' + + Describe "Pre-flight Checks" -Tag "Integration" { + + Context "Ensure Language Binaries are available" { + It "Language Pack Folder $LanguagePackFolderLocation Exists" { + Test-Path -Path $LanguagePackFolderLocation -PathType Container | Should Be $true + } + + It "Language Pack Folder must include at least 1 cab file" { + (Get-ChildItem -Path $LanguagePackFolderLocation -Filter "*.cab").count | Should BeGreaterThan 0 + } + + It "Language Pack File Location must be a cab file" { + $LanguagePackFileLocation.EndsWith(".cab") | Should Be $true + } + + It "Language Pack File Location must exist" { + Test-Path -Path $LanguagePackFileLocation -PathType Leaf | Should Be $true + } + } + + + Context "Ensure System requires modification" { + It "New Language Pack $NewLanguagePackFromFolder mustn't be installed" { + $CurrentState = Get-TargetResource -LanguagePackName $NewLanguagePackFromFolder + $CurrentState.ensure | Should Be "Absent" + } + + It "New Language Pack $NewLanguagePackFromFile mustn't be installed" { + $CurrentState = Get-TargetResource -LanguagePackName $NewLanguagePackFromFile + $CurrentState.ensure | Should Be "Absent" + } + + It "Language Pack to be removed $RemoveLanguagePack must be installed" { + $CurrentState = Get-TargetResource -LanguagePackName $RemoveLanguagePack + $CurrentState.ensure | Should Be "Present" + } + } + } + $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1" - . $configFile + . $configFile + + #region Integration Tests + Describe "$($script:DSCResourceName) Folder Install Integration" -Tag "Integration" { + #region DEFAULT TESTS + It "Should compile and apply the MOF without throwing" { + { + Write-Verbose "Run Config" -Verbose:$true + & "$($script:DSCResourceName)_Config" -OutputPath $TestDrive -LangaugePackName $NewLanguagePackFromFolder -LangaugePackLocation $LanguagePackFolderLocation -Ensure "Present" + Start-DscConfiguration -Path $TestDrive ` + -ComputerName localhost -Wait -Verbose -Force + } | Should not throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw + } + #endregion + + It 'Should have installed the language Pack' { + $currentConfig = Get-TargetResource -LanguagePackName $NewLanguagePackFromFolder -Verbose + $currentConfig.Ensure | Should Be "Present" + } + } - Describe "$($script:DSCResourceName)_Integration" -Tag "Integration" { + Describe "$($script:DSCResourceName) File Install Integration" -Tag "Integration" { #region DEFAULT TESTS It 'Should compile and apply the MOF without throwing' { { - & "$($script:DSCResourceName)_Config" -OutputPath $TestDrive + & "$($script:DSCResourceName)_Config" -OutputPath $TestDrive -LangaugePackName $NewLanguagePackFromFile -LangaugePackLocation $LanguagePackFileLocation -Ensure "Present" Start-DscConfiguration -Path $TestDrive ` -ComputerName localhost -Wait -Verbose -Force } | Should not throw @@ -41,15 +107,34 @@ try { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw } #endregion - InModuleScope 'MSFT_Language' { - It 'Should have set the resource and all the parameters should match' { - $currentConfig = Get-TargetResource -LanguagePackName "en-GB" -Verbose - $currentConfig.Ensure | Should Be $true - } + + It 'Should have installed the language Pack' { + $currentConfig = Get-TargetResource -LanguagePackName $NewLanguagePackFromFile -Verbose + $currentConfig.Ensure | Should Be "Present" } } - #endregion + Describe "$($script:DSCResourceName) Language Pack Uninstall Integration" -Tag "Integration","RebootRequired" { + #region DEFAULT TESTS + It 'Should compile and apply the MOF without throwing' { + { + & "$($script:DSCResourceName)_Config" -OutputPath $TestDrive -LangaugePackName $RemoveLanguagePack -Ensure "Absent" + Start-DscConfiguration -Path $TestDrive ` + -ComputerName localhost -Wait -Verbose -Force + } | Should not throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw + } + #endregion + + It 'Should have removed the language Pack' { + $currentConfig = Get-TargetResource -LanguagePackName $RemoveLanguagePack -Verbose + $currentConfig.Ensure | Should Be "Absent" + } + } + #endregion } finally { diff --git a/Tests/Integration/MSFT_LanguagePack.config.ps1 b/Tests/Integration/MSFT_LanguagePack.config.ps1 index 2829291..047e133 100644 --- a/Tests/Integration/MSFT_LanguagePack.config.ps1 +++ b/Tests/Integration/MSFT_LanguagePack.config.ps1 @@ -1,14 +1,27 @@ # Integration Test Config Template Version: 1.0.0 configuration MSFT_LanguagePack_Config { + Param + ( + [Parameter(Mandatory=$true)] + [String] + $LangaugePackName, + [Parameter(Mandatory=$false)] + [String] + $LangaugePackLocation, + [Parameter(Mandatory=$true)] + [ValidateSet("Present","Absent")] + [String] + $Ensure + ) Import-DscResource -ModuleName LanguageDsc node localhost { LanguagePack Integration_Test { - LanguagePackName = "De-DE" - LanguagePackLocation = "C:\Temp\x64fre_Server_de-de_lp.cab" - Ensure = "Present" + LanguagePackName = $LangaugePackName + LanguagePackLocation = $LangaugePackLocation + Ensure = $Ensure } } } diff --git a/appveyor.yml b/appveyor.yml index 2f488bf..bc38f09 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,6 +7,39 @@ # environment configuration # #---------------------------------# version: 1.0.{build}.0 # TODO Modify version + +image: Visual Studio 2017 +init: +#init script to download binaries required for integration testing +- ps: >- + $LanguagePackFolderLocation = "c:\LanguagePacks\" + + $LanguagePackFileLocation = "c:\LanguagePacks\x64fre_Server_de-de_lp.cab" + + $StorageAccountName = "languageddsctesting" + + $ContainerName = "intergrationtesting" + + + New-Item -Path $LanguagePackFolderLocation -ItemType Directory + + $RESTResult = Invoke-RestMethod "https://$StorageAccountName.blob.core.windows.net/$($ContainerName)?restype=container&comp=list" -Method Get + + [XML]$RESTResult = $RESTResult.Substring(3) #trim random chars off front + + [XML]$XMLResult = $RESTResult + + $reader=(New-Object System.Xml.XmlNodeReader $RESTResult) + + + foreach ($Blob in $XMLResult.EnumerationResults.Blobs.GetEnumerator()) + + { + $OutputFile = Join-Path -Path $LanguagePackFolderLocation -ChildPath $Blob.Name + (New-Object System.Net.WebClient).DownloadFile($Blob.Url, $OutputFile) + } + + install: - git clone https://github.com/PowerShell/DscResource.Tests - ps: Import-Module "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" @@ -24,7 +57,18 @@ build: false test_script: - ps: | - Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -ExcludeTag "Integration" -Verbose + Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -ExcludeTag "RebootRequired" -Verbose + #Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -ExcludeTag "Integration" -Verbose + - cmd: >- + 7z a LanguageDsc.zip DSCResources\* -r + - cmd: >- + 7z a LanguageDsc.zip Examples\* -r + - cmd: >- + 7z a LanguageDsc.zip LanguageDsc.psd1 + - cmd: >- + 7z a LanguageDsc.zip LICENSE + - cmd: >- + 7z a LanguageDsc.zip README.md #---------------------------------# # deployment configuration # @@ -34,3 +78,12 @@ test_script: deploy_script: - ps: | Invoke-AppveyorAfterTestTask + + +#---------------------------------# +# artifact configuration # +#---------------------------------# + +artifacts: +- path: LanguageDsc.zip + name: LanguageDsc