diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..3f56544 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +* text eol=crlf +*.exe binary diff --git a/.gitignore b/.gitignore index 5f4aabe..b03606a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ DSCResource.Tests -*.vscode diff --git a/.vscode/analyzersettings.psd1 b/.vscode/analyzersettings.psd1 new file mode 100644 index 0000000..be415e4 --- /dev/null +++ b/.vscode/analyzersettings.psd1 @@ -0,0 +1,53 @@ +@{ + <# + For the custom rules to work, the DscResource.Tests repo must be + cloned. It is automatically clone as soon as any unit or + integration tests are run. + #> + CustomRulePath = '.\DSCResource.Tests\DscResource.AnalyzerRules' + + IncludeRules = @( + # DSC Resource Kit style guideline rules. + 'PSAvoidDefaultValueForMandatoryParameter', + 'PSAvoidDefaultValueSwitchParameter', + 'PSAvoidInvokingEmptyMembers', + 'PSAvoidNullOrEmptyHelpMessageAttribute', + 'PSAvoidUsingCmdletAliases', + 'PSAvoidUsingComputerNameHardcoded', + 'PSAvoidUsingDeprecatedManifestFields', + 'PSAvoidUsingEmptyCatchBlock', + 'PSAvoidUsingInvokeExpression', + 'PSAvoidUsingPositionalParameters', + 'PSAvoidShouldContinueWithoutForce', + 'PSAvoidUsingWMICmdlet', + 'PSAvoidUsingWriteHost', + 'PSDSCReturnCorrectTypesForDSCFunctions', + 'PSDSCStandardDSCFunctionsInResource', + 'PSDSCUseIdenticalMandatoryParametersForDSC', + 'PSDSCUseIdenticalParametersForDSC', + 'PSMisleadingBacktick', + 'PSMissingModuleManifestField', + 'PSPossibleIncorrectComparisonWithNull', + 'PSProvideCommentHelp', + 'PSReservedCmdletChar', + 'PSReservedParams', + 'PSUseApprovedVerbs', + 'PSUseCmdletCorrectly', + 'PSUseOutputTypeCorrectly', + 'PSAvoidGlobalVars', + 'PSAvoidUsingConvertToSecureStringWithPlainText', + 'PSAvoidUsingPlainTextForPassword', + 'PSAvoidUsingUsernameAndPasswordParams', + 'PSDSCUseVerboseMessageInDSCResource', + 'PSShouldProcess', + 'PSUseDeclaredVarsMoreThanAssignments', + 'PSUsePSCredentialType', + + <# + This is to test all the DSC Resource Kit custom rules. + The name of the function-blocks of each custom rule start + with 'Measure*'. + #> + 'Measure-*' + ) +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0969e57 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,14 @@ +{ + "powershell.codeFormatting.openBraceOnSameLine": false, + "powershell.codeFormatting.newLineAfterOpenBrace": false, + "powershell.codeFormatting.newLineAfterCloseBrace": true, + "powershell.codeFormatting.whitespaceBeforeOpenBrace": true, + "powershell.codeFormatting.whitespaceBeforeOpenParen": true, + "powershell.codeFormatting.whitespaceAroundOperator": true, + "powershell.codeFormatting.whitespaceAfterSeparator": true, + "powershell.codeFormatting.ignoreOneLineBlock": false, + "powershell.codeFormatting.preset": "Custom", + "files.trimTrailingWhitespace": true, + "files.insertFinalNewline": true, + "powershell.scriptAnalysis.settingsPath": ".vscode\\analyzersettings.psd1" +} diff --git a/DscResources/CommonResourceHelper.psm1 b/DscResources/CommonResourceHelper.psm1 index f1ceee0..f1f9d3a 100644 --- a/DscResources/CommonResourceHelper.psm1 +++ b/DscResources/CommonResourceHelper.psm1 @@ -4,12 +4,12 @@ #> function Test-IsNanoServer { - [OutputType([Boolean])] + [OutputType([System.Boolean])] [CmdletBinding()] param () $isNanoServer = $false - + if (Test-CommandExists -Name 'Get-ComputerInfo') { $computerInfo = Get-ComputerInfo -ErrorAction 'SilentlyContinue' @@ -37,13 +37,13 @@ function Test-IsNanoServer #> function Test-CommandExists { - [OutputType([Boolean])] + [OutputType([System.Boolean])] [CmdletBinding()] - param + param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] - [String] $Name + [System.String] $Name ) $command = Get-Command -Name $Name -ErrorAction 'SilentlyContinue' @@ -67,12 +67,12 @@ function New-InvalidArgumentException ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] - [String] + [System.String] $Message, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] - [String] + [System.String] $ArgumentName ) @@ -102,10 +102,12 @@ function New-InvalidOperationException [CmdletBinding()] param ( + [Parameter()] [ValidateNotNullOrEmpty()] - [String] + [System.String] $Message, + [Parameter()] [ValidateNotNull()] [System.Management.Automation.ErrorRecord] $ErrorRecord @@ -155,7 +157,7 @@ function Get-LocalizedData ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] - [String] + [System.String] $ResourceName ) diff --git a/DscResources/MSFT_Archive/MSFT_Archive.psm1 b/DscResources/MSFT_Archive/MSFT_Archive.psm1 index 19a95a1..3ceea92 100644 --- a/DscResources/MSFT_Archive/MSFT_Archive.psm1 +++ b/DscResources/MSFT_Archive/MSFT_Archive.psm1 @@ -53,7 +53,7 @@ if (-not (Test-IsNanoServer)) Specifies whether or not to validate that a file at the destination with the same name as a file in the archive actually matches that corresponding file in the archive by the specified checksum method. - + If a file does not match it will be considered not present. The default value is false. @@ -113,7 +113,7 @@ function Get-TargetResource if ($PSBoundParameters.ContainsKey('Checksum') -and -not $Validate) { $errorMessage = $script:localizedData.ChecksumSpecifiedAndValidateFalse -f $Checksum, $Path, $Destination - New-InvalidArgumentException -ArgumentName 'Checksum or Validate' -Message $errorMessage + New-InvalidArgumentException -ArgumentName 'Checksum or Validate' -Message $errorMessage } $archiveState = @{ @@ -185,7 +185,7 @@ function Get-TargetResource .SYNOPSIS Expands the archive (.zip) file at the specified path to the specified destination or removes the expanded archive (.zip) file at the specified path from the specified - destination. + destination. .PARAMETER Path The path to the archive file that should be expanded to or removed from the specified @@ -209,7 +209,7 @@ function Get-TargetResource Specifies whether or not to validate that a file at the destination with the same name as a file in the archive actually matches that corresponding file in the archive by the specified checksum method. - + If the file does not match and Ensure is specified as Present and Force is not specified, the resource will throw an error that the file at the destination cannot be overwritten. If the file does not match and Ensure is specified as Present and Force is specified, the @@ -292,7 +292,7 @@ function Set-TargetResource if ($PSBoundParameters.ContainsKey('Checksum') -and -not $Validate) { $errorMessage = $script:localizedData.ChecksumSpecifiedAndValidateFalse -f $Checksum, $Path, $Destination - New-InvalidArgumentException -ArgumentName 'Checksum or Validate' -Message $errorMessage + New-InvalidArgumentException -ArgumentName 'Checksum or Validate' -Message $errorMessage } $psDrive = $null @@ -308,7 +308,7 @@ function Set-TargetResource Assert-DestinationDoesNotExistAsFile -Destination $Destination Write-Verbose -Message ($script:localizedData.SettingArchiveState -f $Path, $Destination) - + $expandArchiveToDestinationParameters = @{ ArchiveSourcePath = $Path Destination = $Destination @@ -391,7 +391,7 @@ function Set-TargetResource Specifies whether or not to validate that a file at the destination with the same name as a file in the archive actually matches that corresponding file in the archive by the specified checksum method. - + If a file does not match it will be considered not present. The default value is false. @@ -830,7 +830,7 @@ function Test-ChecksumIsSha [String] $Checksum ) - + return ($Checksum.Length -ge 'SHA'.Length) -and ($Checksum.Substring(0, 3) -ieq 'SHA') } @@ -939,6 +939,43 @@ function Test-FileHashMatchesArchiveEntryHash return $fileHashMatchesArchiveEntryHash } +<# + .SYNOPSIS + Retrieves the timestamp of the specified file for the specified checksum method + and returns it as a checksum. + + .PARAMETER File + The file to retrieve the timestamp of. + + .PARAMETER Checksum + The checksum method to retrieve the timestamp checksum for. + + .NOTES + The returned string is file timestamp normalized to the format specified in + ConvertTo-CheckSumFromDateTime. +#> +function Get-ChecksumFromFileTimestamp +{ + [OutputType([System.String])] + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [System.IO.FileInfo] + $File, + + [Parameter(Mandatory = $true)] + [ValidateSet('CreatedDate', 'ModifiedDate')] + [System.String] + $Checksum + ) + + $timestamp = Get-TimestampForChecksum @PSBoundParameters + + return ConvertTo-ChecksumFromDateTime -Date $timestamp +} + <# .SYNOPSIS Retrieves the timestamp of the specified file for the specified checksum method. @@ -962,22 +999,80 @@ function Get-TimestampForChecksum [Parameter(Mandatory = $true)] [ValidateSet('CreatedDate', 'ModifiedDate')] - [String] + [System.String] $Checksum ) - $relevantTimestamp = $null - if ($Checksum -ieq 'CreatedDate') { - $relevantTimestamp = $File.CreationTime.DateTime + $relevantTimestamp = 'CreationTime' } elseif ($Checksum -ieq 'ModifiedDate') { - $relevantTimestamp = $File.LastWriteTime.DateTime + $relevantTimestamp = 'LastWriteTime' } - return $relevantTimestamp + return Get-TimestampFromFile -File $File -Timestamp $relevantTimestamp +} + +<# + .SYNOPSIS + Retrieves a timestamp of the specified file. + + .PARAMETER File + The file to retrieve the timestamp from. + + .PARAMETER Timestamp + The timestamp attribute to retrieve. +#> +function Get-TimestampFromFile +{ + [OutputType([System.Datetime])] + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [System.IO.FileInfo] + $File, + + [Parameter(Mandatory = $true)] + [ValidateSet('CreationTime', 'LastWriteTime')] + [System.String] + $Timestamp + ) + + return $File.$Timestamp.DateTime +} + +<# + .SYNOPSIS + Converts a datetime object into the format used for a + checksum. + + .PARAMETER Date + The date to use to generate the checksum. + + .NOTES + The returned date is normalized to the General (G) date format. + https://technet.microsoft.com/en-us/library/ee692801.aspx + + Because the General (G) is localization specific a non-localization + specific format such as ISO9660 could be used in future. +#> +function ConvertTo-ChecksumFromDateTime +{ + [OutputType([System.String])] + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [System.DateTime] + $Date + ) + + return Get-Date -Date $Date -Format 'G' } <# @@ -1063,11 +1158,12 @@ function Test-FileMatchesArchiveEntryByChecksum } else { - $fileTimestampForChecksum = Get-TimestampForChecksum -File $File -Checksum $Checksum + $fileTimestampForChecksum = Get-ChecksumFromFileTimestamp -File $File -Checksum $Checksum $archiveEntryLastWriteTime = Get-ArchiveEntryLastWriteTime -ArchiveEntry $ArchiveEntry + $archiveEntryLastWriteTimeChecksum = ConvertTo-CheckSumFromDateTime -Date $archiveEntryLastWriteTime - if ([DateTime]$fileTimestampForChecksum -eq [DateTime]$archiveEntryLastWriteTime) + if ($fileTimestampForChecksum.Equals($archiveEntryLastWriteTimeChecksum)) { Write-Verbose -Message ($script:localizedData.FileMatchesArchiveEntryByChecksum -f $File.FullName, $archiveEntryFullName, $Checksum) @@ -1278,12 +1374,14 @@ function Copy-ArchiveEntryToDestination $DestinationPath ) - Write-Verbose -Message ($script:localizedData.CopyingArchiveEntryToDestination -f $DestinationPath) - $archiveEntryFullName = Get-ArchiveEntryFullName -ArchiveEntry $ArchiveEntry + Write-Verbose -Message ($script:localizedData.CopyingArchiveEntryToDestination -f $archiveEntryFullName, $DestinationPath) + if (Test-ArchiveEntryIsDirectory -ArchiveEntryName $archiveEntryFullName) { + Write-Verbose -Message ($script:localizedData.CreatingArchiveEntryDirectory -f $DestinationPath) + $null = New-Item -Path $DestinationPath -ItemType 'Directory' } else @@ -1425,7 +1523,7 @@ function Expand-ArchiveToDestination $overwriteArchiveEntry = $false } } - + if ($overwriteArchiveEntry) { if ($Force) @@ -1452,7 +1550,7 @@ function Expand-ArchiveToDestination <# .SYNOPSIS Removes the specified directory from the specified destination path. - + .PARAMETER Directory The partial path under the destination path of the directory to remove. @@ -1580,7 +1678,7 @@ function Remove-ArchiveFromDestination elseif ((-not $archiveEntryIsDirectory) -and $itemAtDestinationIsFile) { $removeArchiveEntry = $true - + if ($PSBoundParameters.ContainsKey('Checksum')) { $removeArchiveEntry = Test-FileMatchesArchiveEntryByChecksum -File $itemAtDestination -ArchiveEntry $archiveEntry -Checksum $Checksum diff --git a/DscResources/MSFT_Archive/en-US/MSFT_Archive.strings.psd1 b/DscResources/MSFT_Archive/en-US/MSFT_Archive.strings.psd1 index f78a400..be6af64 100644 --- a/DscResources/MSFT_Archive/en-US/MSFT_Archive.strings.psd1 +++ b/DscResources/MSFT_Archive/en-US/MSFT_Archive.strings.psd1 @@ -1,57 +1,58 @@ # Localized MSFT_Archive.strings.psd1 ConvertFrom-StringData @' - RetrievingArchiveState = Retrieving the state of the archive with path {0} and destination {1}... - SettingArchiveState = Setting the state of the archive with path {0} and destination {1}... - ArchiveStateSet = The state of the archive with path {0} and destination {1} has been set. - TestingArchiveState = Testing whether or not the state of the archive with path {0} and destination {1} matches the desired state... + RetrievingArchiveState = Retrieving the state of the archive with path "{0}" and destination "{1}"... + SettingArchiveState = Setting the state of the archive with path "{0}" and destination "{1}"... + ArchiveStateSet = The state of the archive with path "{0}" and destination "{1}" has been set. + TestingArchiveState = Testing whether or not the state of the archive with path "{0}" and destination "{1}" matches the desired state... - PathAccessiblePSDriveNotNeeded = The path {0} is accessible. A new PSDrive is not needed. - CreatingPSDrive = Creating a PSDrive to access the path {0} with permissions from the user {1}... - RemovingPSDrive = Removing the mounted PSDrive {0}... + PathAccessiblePSDriveNotNeeded = The path "{0}" is accessible. A new PSDrive is not needed. + CreatingPSDrive = Creating a PSDrive to access the path "{0}" with permissions from the user "{1}"... + RemovingPSDrive = Removing the mounted PSDrive "{0}"... - DestinationExists = A directory already exists at the destination path {0}. - DestinationDoesNotExist = A directory does not exist at the destination path {0}. - CreatingDirectoryAtDestination = Creating the root directory at the destination path {0}... - - TestingIfArchiveExistsAtDestination = Testing if the archive at the destination path {0} exists... - ArchiveExistsAtDestination = The archive at path {0} exists at the destination {1}. - ArchiveDoesNotExistAtDestination = The archive at path {0} does not exist at the destination {1}. + DestinationExists = A directory already exists at the destination path "{0}". + DestinationDoesNotExist = A directory does not exist at the destination path "{0}". + CreatingDirectoryAtDestination = Creating the root directory at the destination path "{0}"... - OpeningArchive = Opening the archive at path {0}... - ClosingArchive = Closing the archive at path {0}... + TestingIfArchiveExistsAtDestination = Testing if the archive at the destination path "{0}" exists... + ArchiveExistsAtDestination = The archive at path "{0}" exists at the destination "{1}". + ArchiveDoesNotExistAtDestination = The archive at path "{0}" does not exist at the destination "{1}". - OpeningArchiveEntry = Opening the archive entry {0}... + OpeningArchive = Opening the archive at path "{0}"... + ClosingArchive = Closing the archive at path "{0}"... - ItemWithArchiveEntryNameExists = An item with the same name as the archive entry exists at the destination path {0}. - ItemWithArchiveEntryNameDoesNotExist = An item with the same name as the archive entry does not exist at the destination path {0}. - ItemWithArchiveEntryNameIsNotDirectory = The item at the destination path {0} has the same name as a directory archive entry but is not a directory. - ItemWithArchiveEntryNameIsNotFile = The item at the destination path {0} has the same name as a file archive entry but is not a file. + OpeningArchiveEntry = Opening the archive entry "{0}"... - TestingIfFileMatchesArchiveEntryByChecksum = Testing if the file at {0} matches the archive entry at {1} by the checksum method {2}... - ComparingHashes = Comparing the hash of the file at {0} to the hash of the archive entry at {1} with the hash algorithm {2}... - FileMatchesArchiveEntryByChecksum = The file at {0} matches the archive entry at {1} by the checksum method {2}. - FileDoesNotMatchArchiveEntryByChecksum = The file at {0} does not match the archive entry at {1} by the checksum method {2}. + ItemWithArchiveEntryNameExists = An item with the same name as the archive entry exists at the destination path "{0}". + ItemWithArchiveEntryNameDoesNotExist = An item with the same name as the archive entry does not exist at the destination path "{0}". + ItemWithArchiveEntryNameIsNotDirectory = The item at the destination path "{0}" has the same name as a directory archive entry but is not a directory. + ItemWithArchiveEntryNameIsNotFile = The item at the destination path "{0}" has the same name as a file archive entry but is not a file. - ExpandingArchiveToDestination = Expanding the archive at {0} to the destination {1}... - CreatingParentDirectory = Creating an archive entry parent directory at the path {0}... - OverwritingItem = Overwriting the item at the path {0}... - CopyingArchiveEntryToDestination = Copying the corresponding archive entry to the path {0}... + TestingIfFileMatchesArchiveEntryByChecksum = Testing if the file at "{0}" matches the archive entry at "{1}" by the checksum method "{2}"... + ComparingHashes = Comparing the hash of the file at "{0}" to the hash of the archive entry at "{1}" with the hash algorithm "{2}"... + FileMatchesArchiveEntryByChecksum = The file at "{0}" matches the archive entry at "{1}" by the checksum method "{2}". + FileDoesNotMatchArchiveEntryByChecksum = The file at "{0}" does not match the archive entry at "{1}" by the checksum method "{2}". - RemovingArchiveFromDestination = Removing archive from the destination path {0}... - RemovingDirectory = Removing the directory at path {0}... - RemovingFile = Removing the file at path {0}... - CouldNotRemoveItemOfIncorrectType = The file at {0} does not match the item type (file, directory, or other) or the archive entry at {1}, so it will not be removed. - ArchiveRemovedFromDestination = Archive removed from the destination path {0}. - - ChecksumSpecifiedAndValidateFalse = The Checksum parameter was specified as {0} but the Validate parameter is set to false for the archive with path {1} and destination {2}. Please specify the Validate parameter as true to use the Checksum parameter. - PathDoesNotContainValidPSDriveRoot = The path {0} cannot be accessed because it does not contain any directories to use as the root of a PSDrive. - ErrorCreatingPSDrive = An error occurred while attempting to create a PSDrive to access the path {0} under the user {1}. - PathDoesNotExistAsLeaf = The path {0} does not exist or is not a path leaf. - DestinationExistsAsFile = A file exists at the desintation path {0}. - ErrorOpeningArchive = An error occurred while attempting to open the archive at path {0}. - ErrorCopyingFromArchiveToDestination = An error occurred while attempting copy from the archive to the destination path {0}. - DirectoryIsNotEmpty = The directory at path {0} is not empty, so it will not be removed. - ErrorComparingHashes = An error occurred while comparing the hash of the file at {0} to the archive entry {1} with the hash algorithm {2}. - ForceNotSpecifiedToOverwriteItem = An item already exists at {0} that does not match the item in the archive at {1}, but the Force parameter has not been specified to overwrite this item. + ExpandingArchiveToDestination = Expanding the archive at "{0}" to the destination "{1}"... + CreatingParentDirectory = Creating an archive entry parent directory at the path "{0}"... + OverwritingItem = Overwriting the item at the path "{0}"... + CreatingArchiveEntryDirectory = Creating an archive entry directory "{0}"... + CopyingArchiveEntryToDestination = Copying the archive entry "{0}" to the destination path "{1}"... + + RemovingArchiveFromDestination = Removing archive from the destination path "{0}"... + RemovingDirectory = Removing the directory at path "{0}"... + RemovingFile = Removing the file at path "{0}"... + CouldNotRemoveItemOfIncorrectType = The file at "{0}" does not match the item type (file, directory, or other) or the archive entry at "{1}", so it will not be removed. + ArchiveRemovedFromDestination = Archive removed from the destination path "{0}". + + ChecksumSpecifiedAndValidateFalse = The Checksum parameter was specified as "{0}" but the Validate parameter is set to false for the archive with path "{1}" and destination "{2}". Please specify the Validate parameter as true to use the Checksum parameter. + PathDoesNotContainValidPSDriveRoot = The path "{0}" cannot be accessed because it does not contain any directories to use as the root of a PSDrive. + ErrorCreatingPSDrive = An error occurred while attempting to create a PSDrive to access the path "{0}" under the user "{1}". + PathDoesNotExistAsLeaf = The path "{0}" does not exist or is not a path leaf. + DestinationExistsAsFile = A file exists at the desintation path "{0}". + ErrorOpeningArchive = An error occurred while attempting to open the archive at path "{0}". + ErrorCopyingFromArchiveToDestination = An error occurred while attempting copy from the archive to the destination path "{0}". + DirectoryIsNotEmpty = The directory at path "{0}" is not empty, so it will not be removed. + ErrorComparingHashes = An error occurred while comparing the hash of the file at "{0}" to the archive entry "{1}" with the hash algorithm "{2}". + ForceNotSpecifiedToOverwriteItem = An item already exists at "{0}" that does not match the item in the archive at "{1}", but the Force parameter has not been specified to overwrite this item. '@ diff --git a/README.md b/README.md index b0f2a6d..e985010 100644 --- a/README.md +++ b/README.md @@ -360,7 +360,7 @@ None #### Read-Only Properties from Get-TargetResource None - + #### Examples * [Create a new User](https://github.com/PowerShell/PSDscResources/blob/master/Examples/Sample_User_CreateUser.ps1) @@ -577,6 +577,32 @@ The following parameters will be the same for each process in the set: ### Unreleased +* Ported fixes from [xPSDesiredStateConfiguration](https://github.com/PowerShell/xPSDesiredStateConfiguration): + * xArchive + * Fix end-to-end tests. + * Update integration tests to meet Pester 4.0.0 standards. + * Update end-to-end tests to meet Pester 4.0.0 standards. + * Update unit and integration tests to meet Pester 4.0.0 standards. + * Wrapped all verbose message parameters with quotes to make identifying + actual paths possible. + * Refactored date/time checksum code to improve testability and ensure + tests can run on machines with localized datetime formats that are not + US. + * Fix 'Get-ArchiveEntryLastWriteTime' to return `[datetime]`. + * Improved verbose logging to make debugging path issues easier. +* Added .gitattributes file to ensure CRLF settings are configured correctly + for the repository. +* Updated '.vscode\settings.json' to refer to AnalyzerSettings.psd1 so that + custom syntax problems are highlighted in Visual Studio Code. +* Fixed style guideline violations in `CommonResourceHelper.psm1`. +* Updated 'appveyor.yml' to meet more recent standards. +* Removed OS image version from 'appveyor.yml' to use default image + ([Issue #127](https://github.com/PowerShell/PSDscResources/issues/127). +* Removed code to install WMF5.1 from 'appveyor.yml' because it is already + installed in AppVeyor images ([Issue #128](https://github.com/PowerShell/PSDscResources/issues/128). +* Removed .vscode from .gitignore so that Visual Studio code environment + settings can be committed. + ### 2.9.0.0 * Added Description and Parameter description for composite resources @@ -584,46 +610,46 @@ The following parameters will be the same for each process in the set: ### 2.8.0.0 * Archive: - * Added handling of directory archive entries that end with a foward slash - * Removed formatting of LastWriteTime timestamp and updated comparison of timestamps to handle dates in different formats + * Added handling of directory archive entries that end with a foward slash + * Removed formatting of LastWriteTime timestamp and updated comparison of timestamps to handle dates in different formats * WindowsProcess: - * Fix unreliable tests + * Fix unreliable tests * Updated Test-IsNanoServer to return false if Get-ComputerInfo fails * Registry: - * Fixed bug when using the full registry drive name (e.g. HKEY\_LOCAL\_MACHINE) and using a key name that includes a drive with forward slashes (e.g. C:/) + * Fixed bug when using the full registry drive name (e.g. HKEY\_LOCAL\_MACHINE) and using a key name that includes a drive with forward slashes (e.g. C:/) ### 2.7.0.0 * MsiPackage - * Parse installation date from registry using invariant culture. - * Fix a bug in unit test failing, when regional setting differs from English-US. + * Parse installation date from registry using invariant culture. + * Fix a bug in unit test failing, when regional setting differs from English-US. ### 2.6.0.0 * Archive: - * Fixed a minor bug in the unit tests where sometimes the incorrect DateTime format was used. + * Fixed a minor bug in the unit tests where sometimes the incorrect DateTime format was used. * Added MsiPackage ### 2.5.0.0 * Enable codecov.io code coverage reporting * Group - * Added support for domain based group members on Nano server. + * Added support for domain based group members on Nano server. * Added the Archive resource * Update Test-IsNanoServer cmdlet to properly test for a Nano server rather than the core version of PowerShell * Registry - * Fixed bug where an error was thrown when running Get-DscConfiguration if the registry already existed + * Fixed bug where an error was thrown when running Get-DscConfiguration if the registry already existed ### 2.4.0.0 * Cleaned User * Updated User to have non-dependent unit tests. * Ported fixes from [xPSDesiredStateConfiguration](https://github.com/PowerShell/xPSDesiredStateConfiguration): - * WindowsProcess: Minor updates to integration tests - * Registry: Fixed support for forward slashes in registry key names + * WindowsProcess: Minor updates to integration tests + * Registry: Fixed support for forward slashes in registry key names * Group: - * Group members in the "NT Authority", "BuiltIn" and "NT Service" scopes should now be resolved without an error. If you were seeing the errors "Exception calling ".ctor" with "4" argument(s): "Server names cannot contain a space character."" or "Exception calling ".ctor" with "2" argument(s): "Server names cannot contain a space character."", this fix should resolve those errors. If you are still seeing one of the errors, there is probably another local scope we need to add. Please let us know. - * The resource will no longer attempt to resolve group members if Members, MembersToInclude, and MembersToExclude are not specified. + * Group members in the "NT Authority", "BuiltIn" and "NT Service" scopes should now be resolved without an error. If you were seeing the errors "Exception calling ".ctor" with "4" argument(s): "Server names cannot contain a space character."" or "Exception calling ".ctor" with "2" argument(s): "Server names cannot contain a space character."", this fix should resolve those errors. If you are still seeing one of the errors, there is probably another local scope we need to add. Please let us know. + * The resource will no longer attempt to resolve group members if Members, MembersToInclude, and MembersToExclude are not specified. * Added Environment ### 2.3.0.0 @@ -633,16 +659,16 @@ The following parameters will be the same for each process in the set: ### 2.2.0.0 * WindowsFeature: - * Added Catch to ignore RuntimeException when importing ServerManager module. This solves the issue described [here](https://social.technet.microsoft.com/Forums/en-US/9fc314e1-27bf-4f03-ab78-5e0f7a662b8f/importmodule-servermanager-some-or-all-identity-references-could-not-be-translated?forum=winserverpowershell). - * Updated unit tests. + * Added Catch to ignore RuntimeException when importing ServerManager module. This solves the issue described [here](https://social.technet.microsoft.com/Forums/en-US/9fc314e1-27bf-4f03-ab78-5e0f7a662b8f/importmodule-servermanager-some-or-all-identity-references-could-not-be-translated?forum=winserverpowershell). + * Updated unit tests. * Added WindowsProcess * CommonTestHelper: - * Added Get-AppVeyorAdministratorCredential. - * Added Set-StrictMode -'Latest' and $errorActionPreference -'Stop'. + * Added Get-AppVeyorAdministratorCredential. + * Added Set-StrictMode -'Latest' and $errorActionPreference -'Stop'. * Service: - * Updated resource module, unit tests, integration tests, and examples to reflect the changes made in xPSDesiredStateConfiguration. + * Updated resource module, unit tests, integration tests, and examples to reflect the changes made in xPSDesiredStateConfiguration. * Group: - * Updated resource module, examples, and integration tests to reflect the changes made in xPSDesiredStateConfiguration. + * Updated resource module, examples, and integration tests to reflect the changes made in xPSDesiredStateConfiguration. * Added Script. * Added GroupSet, ServiceSet, WindowsFeatureSet, WindowsOptionalFeatureSet, and ProcessSet. * Added Set-StrictMode -'Latest' and $errorActionPreference -'Stop' to Group, Service, User, WindowsFeature, WindowsOptionalFeature, WindowsPackageCab. diff --git a/Tests/Integration/MSFT_Archive.EndToEnd.Tests.ps1 b/Tests/Integration/MSFT_Archive.EndToEnd.Tests.ps1 index a00738c..674c8e4 100644 --- a/Tests/Integration/MSFT_Archive.EndToEnd.Tests.ps1 +++ b/Tests/Integration/MSFT_Archive.EndToEnd.Tests.ps1 @@ -134,47 +134,48 @@ Describe 'Archive End to End Tests' { $null = Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment } - Context 'Expand an archive to a destination that does not yet exist' { + Context 'When expanding an archive to a destination that does not yet exist' { $configurationName = 'ExpandArchiveToNonExistentDestination' $destination = Join-Path -Path $TestDrive -ChildPath 'NonExistentDestinationForExpand' It 'Destination should not exist before configuration' { - Test-Path -Path $destination | Should Be $false + Test-Path -Path $destination | Should -Be $false } $archiveParameters = @{ Path = $script:testArchiveFilePath Destination = $destination Ensure = 'Present' + Verbose = $true } It 'Should return false from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $false + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateOnly -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - Context 'Expand an archive to an existing destination with items that are not in the archive' { + Context 'When expanding an archive to an existing destination with items that are not in the archive' { $configurationName = 'ExpandArchiveToDestinationWithOtherItems' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithOtherItemsForExpand' @@ -198,7 +199,7 @@ Describe 'Archive End to End Tests' { $otherItems[$otherFilePath] = $otherFileContent It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } foreach ($otherItemPath in $otherItems.Keys) @@ -210,17 +211,17 @@ Describe 'Archive End to End Tests' { if ($otherItemIsDirectory) { It "Other item under destination $otherItemName should exist as a directory before configuration" { - Test-Path -Path $otherItemPath -PathType 'Container' | Should Be $true + Test-Path -Path $otherItemPath -PathType 'Container' | Should -Be $true } } else { It "Other item under destination $otherItemName should exist as a file before configuration" { - Test-Path -Path $otherItemPath -PathType 'Leaf' | Should Be $true + Test-Path -Path $otherItemPath -PathType 'Leaf' | Should -Be $true } It "Other file under destination $otherItemName should have the expected content before configuration" { - Get-Content -Path $otherItemPath -Raw -ErrorAction 'SilentlyContinue' | Should Be ($otherItemExpectedContent + "`r`n") + Get-Content -Path $otherItemPath -Raw -ErrorAction 'SilentlyContinue' | Should -Be ($otherItemExpectedContent + "`r`n") } } } @@ -229,26 +230,27 @@ Describe 'Archive End to End Tests' { Path = $script:testArchiveFilePath Destination = $destination Ensure = 'Present' + Verbose = $true } It 'Should return false from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $false + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateOnly -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } foreach ($otherItemPath in $otherItems.Keys) @@ -260,27 +262,27 @@ Describe 'Archive End to End Tests' { if ($otherItemIsDirectory) { It "Other item under destination $otherItemName should exist as a directory after configuration" { - Test-Path -Path $otherItemPath -PathType 'Container' | Should Be $true + Test-Path -Path $otherItemPath -PathType 'Container' | Should -Be $true } } else { It "Other item under destination $otherItemName should exist as a file after configuration" { - Test-Path -Path $otherItemPath -PathType 'Leaf' | Should Be $true + Test-Path -Path $otherItemPath -PathType 'Leaf' | Should -Be $true } It "Other file under destination $otherItemName should have the expected after before configuration" { - Get-Content -Path $otherItemPath -Raw -ErrorAction 'SilentlyContinue' | Should Be ($otherItemExpectedContent + "`r`n") + Get-Content -Path $otherItemPath -Raw -ErrorAction 'SilentlyContinue' | Should -Be ($otherItemExpectedContent + "`r`n") } } } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - - Context 'Expand an archive to an existing destination that already contains the same archive files' { + + Context 'When expanding an archive to an existing destination that already contains the same archive files' { $configurationName = 'ExpandArchiveToDestinationWithArchive' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithMatchingArchiveForExpand' @@ -289,45 +291,46 @@ Describe 'Archive End to End Tests' { $null = Expand-Archive -Path $script:testArchiveFilePath -DestinationPath $destination -Force It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } $archiveParameters = @{ Path = $script:testArchiveFilePath Destination = $destination Ensure = 'Present' + Verbose = $true } It 'Should return true from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateOnly -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - Context 'Expand an archive to a destination that contains archive files that do not match by the specified SHA Checksum without Force specified' { + Context 'When expanding an archive to a destination that contains archive files that do not match by the specified SHA Checksum without Force specified' { $configurationName = 'ExpandArchiveToDestinationWithMismatchingArchive' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithMismatchingArchiveWithSHANoForceForExpand' @@ -336,15 +339,15 @@ Describe 'Archive End to End Tests' { $null = Expand-Archive -Path $script:testArchiveFileWithDifferentFileContentPath -DestinationPath $destination -Force It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'File contents of destination should not match the file contents of the archive' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $false } $archiveParameters = @{ @@ -354,39 +357,40 @@ Describe 'Archive End to End Tests' { Validate = $true Checksum = 'SHA-256' Force = $false + Verbose = $true } It 'Should return false from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $false + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false } It 'Should compile and run configuration and throw an error for attempting to overwrite files without Force specified' { # We don't know which file will throw the error, so we will only check that an error was thrown rather than checking the specific error message - { + { . $script:confgurationFilePathValidateAndChecksum -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'File contents of destination should not match the file contents of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $false } It 'Should return false from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $false + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false } } - Context 'Expand an archive to a destination that contains archive files that do not match by the specified SHA Checksum with Force specified' { + Context 'When expanding an archive to a destination that contains archive files that do not match by the specified SHA Checksum with Force specified' { $configurationName = 'ExpandArchiveToDestinationWithMismatchingArchive' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithMismatchingArchiveWithSHAAndForceForExpand' @@ -395,15 +399,15 @@ Describe 'Archive End to End Tests' { $null = Expand-Archive -Path $script:testArchiveFileWithDifferentFileContentPath -DestinationPath $destination -Force It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'File contents of destination should not match the file contents of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $false } $archiveParameters = @{ @@ -413,38 +417,39 @@ Describe 'Archive End to End Tests' { Validate = $true Checksum = 'SHA-256' Force = $true + Verbose = $true } It 'Should return false from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $false + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateAndChecksum -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'File contents of destination should match the file contents of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $true } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - Context 'Expand an archive to a destination that contains archive files that match by the specified SHA Checksum' { + Context 'When expanding an archive to a destination that contains archive files that match by the specified SHA Checksum' { $configurationName = 'ExpandArchiveToDestinationWithMatchingArchive' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithMatchingArchiveWithSHAForExpand' @@ -453,15 +458,15 @@ Describe 'Archive End to End Tests' { $null = Expand-Archive -Path $script:testArchiveFilePath -DestinationPath $destination -Force It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'File contents of destination should match the file contents of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $true } $archiveParameters = @{ @@ -471,38 +476,39 @@ Describe 'Archive End to End Tests' { Validate = $true Checksum = 'SHA-256' Force = $true + Verbose = $true } It 'Should return true from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateAndChecksum -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'File contents of destination should match the file contents of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $true } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - - Context 'Remove an expanded archive from an existing destination that contains only the expanded archive' { + + Context 'When removing an expanded archive from an existing destination that contains only the expanded archive' { $configurationName = 'RemoveArchiveAtDestinationWithArchive' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithMatchingArchiveForRemove' @@ -511,45 +517,46 @@ Describe 'Archive End to End Tests' { $null = Expand-Archive -Path $script:testArchiveFilePath -DestinationPath $destination -Force It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } $archiveParameters = @{ Path = $script:testArchiveFilePath Destination = $destination Ensure = 'Absent' + Verbose = $true } It 'Should return false from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $false + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateOnly -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should not match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $false } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - Context 'Remove an expanded archive from an existing destination that contains the expanded archive and other files' { + Context 'When removing an expanded archive from an existing destination that contains the expanded archive and other files' { $configurationName = 'RemoveArchiveAtDestinationWithArchiveAndOtherFiles' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithMatchingArchiveAndOtherFilesForRemove' @@ -575,7 +582,7 @@ Describe 'Archive End to End Tests' { $otherItems[$otherFilePath] = $otherFileContent It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } foreach ($otherItemPath in $otherItems.Keys) @@ -587,45 +594,46 @@ Describe 'Archive End to End Tests' { if ($otherItemIsDirectory) { It "Other item under destination $otherItemName should exist as a directory before configuration" { - Test-Path -Path $otherItemPath -PathType 'Container' | Should Be $true + Test-Path -Path $otherItemPath -PathType 'Container' | Should -Be $true } } else { It "Other item under destination $otherItemName should exist as a file before configuration" { - Test-Path -Path $otherItemPath -PathType 'Leaf' | Should Be $true + Test-Path -Path $otherItemPath -PathType 'Leaf' | Should -Be $true } It "Other file under destination $otherItemName should have the expected content before configuration" { - Get-Content -Path $otherItemPath -Raw -ErrorAction 'SilentlyContinue' | Should Be ($otherItemExpectedContent + "`r`n") + Get-Content -Path $otherItemPath -Raw -ErrorAction 'SilentlyContinue' | Should -Be ($otherItemExpectedContent + "`r`n") } } } It 'File structure of destination should match the file structure of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } $archiveParameters = @{ Path = $script:testArchiveFilePath Destination = $destination Ensure = 'Absent' + Verbose = $true } It 'Should return false from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $false + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateOnly -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } foreach ($otherItemPath in $otherItems.Keys) @@ -637,112 +645,114 @@ Describe 'Archive End to End Tests' { if ($otherItemIsDirectory) { It "Other item under destination $otherItemName should exist as a directory before configuration" { - Test-Path -Path $otherItemPath -PathType 'Container' | Should Be $true + Test-Path -Path $otherItemPath -PathType 'Container' | Should -Be $true } } else { It "Other item under destination $otherItemName should exist as a file before configuration" { - Test-Path -Path $otherItemPath -PathType 'Leaf' | Should Be $true + Test-Path -Path $otherItemPath -PathType 'Leaf' | Should -Be $true } It "Other file under destination $otherItemName should have the expected content before configuration" { - Get-Content -Path $otherItemPath -Raw -ErrorAction 'SilentlyContinue' | Should Be ($otherItemExpectedContent + "`r`n") + Get-Content -Path $otherItemPath -Raw -ErrorAction 'SilentlyContinue' | Should -Be ($otherItemExpectedContent + "`r`n") } } } It 'File structure of destination should not match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $false } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - Context 'Remove an expanded archive from an existing destination that does not contain any archive files' { + Context 'When removing an expanded archive from an existing destination that does not contain any archive files' { $configurationName = 'RemoveArchiveAtDestinationWithoutArchive' $destination = Join-Path -Path $TestDrive -ChildPath 'EmptyDestinationForRemove' $null = New-Item -Path $destination -ItemType 'Directory' It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should not match the file structure of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $false } $archiveParameters = @{ Path = $script:testArchiveFilePath Destination = $destination Ensure = 'Absent' + Verbose = $true } It 'Should return true from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateOnly -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should not match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $false } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - Context 'Remove an expanded archive from a destination that does not exist' { + Context 'When removing an expanded archive from a destination that does not exist' { $configurationName = 'RemoveArchiveFromMissingDestination' $destination = Join-Path -Path $TestDrive -ChildPath 'NonexistentDestinationForRemove' It 'Destination should not exist before configuration' { - Test-Path -Path $destination | Should Be $false + Test-Path -Path $destination | Should -Be $false } $archiveParameters = @{ Path = $script:testArchiveFilePath Destination = $destination Ensure = 'Absent' + Verbose = $true } It 'Should return true from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateOnly -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should not exist after configuration' { - Test-Path -Path $destination | Should Be $false + Test-Path -Path $destination | Should -Be $false } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - Context 'Remove an archive from a destination that contains archive files that do not match by the specified SHA Checksum' { + Context 'When removing an archive from a destination that contains archive files that do not match by the specified SHA Checksum' { $configurationName = 'RemoveArchiveFromDestinationWithMismatchingArchiveWithSHA' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithMismatchingArchiveWithSHAForRemove' @@ -751,15 +761,15 @@ Describe 'Archive End to End Tests' { $null = Expand-Archive -Path $script:testArchiveFileWithDifferentFileContentPath -DestinationPath $destination -Force It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'File contents of destination should not match the file contents of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $false } $archiveParameters = @{ @@ -769,38 +779,39 @@ Describe 'Archive End to End Tests' { Validate = $true Checksum = 'SHA-256' Force = $true + Verbose = $true } It 'Should return true from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateAndChecksum -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true } It 'File contents of destination should not match the file contents of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $false } It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } - Context 'Remove an archive from a destination that contains archive files that match by the specified SHA Checksum' { + Context 'When removing an archive from a destination that contains archive files that match by the specified SHA Checksum' { $configurationName = 'RemoveArchiveFromDestinationWithMatchingArchiveWithSHA' $destination = Join-Path -Path $TestDrive -ChildPath 'DestinationWithMatchingArchiveWithSHAForRemove' @@ -809,11 +820,11 @@ Describe 'Archive End to End Tests' { $null = Expand-Archive -Path $script:testArchiveFilePath -DestinationPath $destination -Force It 'Destination should exist before configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure and contents of destination should match the file contents of the archive before configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $true } $archiveParameters = @{ @@ -823,30 +834,31 @@ Describe 'Archive End to End Tests' { Validate = $true Checksum = 'SHA-256' Force = $true + Verbose = $true } It 'Should return false from Test-TargetResource with the same parameters before configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $false + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false } - It 'Should compile and run configuration' { - { + It 'Should compile and apply the MOF without throwing an exception' { + { . $script:confgurationFilePathValidateAndChecksum -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @archiveParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw + Start-DscConfiguration -Path $TestDrive -ErrorAction Stop -Wait -Force -Verbose + } | Should -Not -Throw } It 'Destination should exist after configuration' { - Test-Path -Path $destination | Should Be $true + Test-Path -Path $destination | Should -Be $true } It 'File structure of destination should not match the file structure of the archive after configuration' { - Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should Be $false + Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $false } It 'Should return false from Test-TargetResource with the same parameters after configuration' { - MSFT_Archive\Test-TargetResource @archiveParameters | Should Be $true + MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true } } } diff --git a/Tests/Integration/MSFT_Archive.Integration.Tests.ps1 b/Tests/Integration/MSFT_Archive.Integration.Tests.ps1 index 06aea9c..d3562aa 100644 --- a/Tests/Integration/MSFT_Archive.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_Archive.Integration.Tests.ps1 @@ -29,7 +29,7 @@ Describe 'Archive Integration Tests' { $null = Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment } - Context 'Expand a basic archive' { + Context 'When expanding a basic archive' { $zipFileName = 'BasicArchive1' $subfolderName = 'Folder1' @@ -46,35 +46,35 @@ Describe 'Archive Integration Tests' { $destinationDirectoryPath = Join-Path -Path $TestDrive -ChildPath $destinationDirectoryName It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } It 'Test-TargetResource with Ensure as Present should return false before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should Not Throw + { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should -Not -Throw } It 'File structure and contents of the destination should match the file structure and contents of the archive after Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true } It 'Test-TargetResource with Ensure as Present should return true after Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false after Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } } - Context 'Remove a basic archive' { + Context 'When removing a basic archive' { $zipFileName = 'BasicArchive2' $subfolderName = 'Folder1' @@ -93,35 +93,35 @@ Describe 'Archive Integration Tests' { $null = Expand-Archive -Path $zipFilePath -DestinationPath $destinationDirectoryPath -Force It 'File structure and contents of the destination should match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true } It 'Test-TargetResource with Ensure as Present should return true before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should Not Throw + { Set-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should -Not -Throw } It 'File structure and contents of the destination should not match the file structure and contents of the archive after Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } It 'Test-TargetResource with Ensure as Present should return false after Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true after Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } } - Context 'Expand an archive with nested directories' { + Context 'When expanding an archive with nested directories' { $zipFileName = 'NestedArchive1' $zipFileStructure = @{ @@ -164,35 +164,35 @@ Describe 'Archive Integration Tests' { $destinationDirectoryPath = Join-Path -Path $TestDrive -ChildPath $destinationDirectoryName It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } It 'Test-TargetResource with Ensure as Present should return false before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should Not Throw + { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should -Not -Throw } It 'File structure and contents of the destination should match the file structure and contents of the archive after Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true } It 'Test-TargetResource with Ensure as Present should return true after Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false after Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } } - Context 'Remove an archive with nested directories' { + Context 'When removing an archive with nested directories' { $zipFileName = 'NestedArchive2' $zipFileStructure = @{ @@ -237,35 +237,35 @@ Describe 'Archive Integration Tests' { $null = Expand-Archive -Path $zipFilePath -DestinationPath $destinationDirectoryPath -Force It 'File structure and contents of the destination should match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true } It 'Test-TargetResource with Ensure as Present should return true before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should Not Throw + { Set-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should -Not -Throw } It 'File structure and contents of the destination should not match the file structure and contents of the archive after Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } It 'Test-TargetResource with Ensure as Present should return false after Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true after Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } } - Context 'Expand an archive when another archive with the same timestamp exists in the same folder' { + Context 'When expanding an archive when another archive with the same timestamp exists in the same folder' { $zipFileName1 = 'SameTimestamp1' $zipFileStructure1 = @{ @@ -295,51 +295,51 @@ Describe 'Archive Integration Tests' { $destinationDirectoryPath = Join-Path -Path $TestDrive -ChildPath $destinationDirectoryName It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath1 -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath1 -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } It 'Test-TargetResource with Ensure as Present should return false for specified archive before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true for specified archive before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should -Be $true } It 'Test-TargetResource with Ensure as Present should return false for other archive with same timestamp with before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true for other archive with same timestamp before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should -Be $true } It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Present' -Path $zipFilePath1 -Destination $destinationDirectoryPath } | Should Not Throw + { Set-TargetResource -Ensure 'Present' -Path $zipFilePath1 -Destination $destinationDirectoryPath } | Should -Not -Throw } It 'File structure and contents of the destination should match the file structure and contents of the archive after Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath1 -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $zipFileSourcePath1 -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true } It 'Test-TargetResource with Ensure as Present should return true for specified archive after Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false for specified archive after Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Present should return false for other archive with same timestamp with before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true for other archive with same timestamp before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should -Be $true } } - Context 'Remove an archive with an extra file in a nested directory' { + Context 'When removing an archive with an extra file in a nested directory' { $zipFileName = 'NestedArchiveWithAdd' $zipFileStructure = @{ @@ -371,44 +371,44 @@ Describe 'Archive Integration Tests' { $null = Set-Content -Path $newFilePath -Value 'Fake text' It 'File structure and contents of the destination should match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true } It 'Test-TargetResource with Ensure as Present should return true before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } It 'Extra file should be present before Set-TargetResource' { - Test-Path -Path $newFilePath | Should Be $true + Test-Path -Path $newFilePath | Should -Be $true } It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should Not Throw + { Set-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath } | Should -Not -Throw } - + It 'File structure and contents of the destination should not match the file structure and contents of the archive after Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } It 'Test-TargetResource with Ensure as Present should return false after Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true after Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true } It 'Extra file should be present after Set-TargetResource' { - Test-Path -Path $newFilePath | Should Be $true + Test-Path -Path $newFilePath | Should -Be $true } } - + $possibleChecksumValues = @( 'SHA-1', 'SHA-256', 'SHA-512', 'CreatedDate', 'ModifiedDate' ) - + $zipFileName = 'ChecksumWithModifiedFile' $fileToEditName = 'File1' $fileNotToEditName = 'File2' @@ -422,8 +422,8 @@ Describe 'Archive Integration Tests' { $zipFileSourcePath = $zipFilePath.Replace('.zip', '') foreach ($possibleChecksumValue in $possibleChecksumValues) - { - Context "Expand an archive with an edited file, Validate and Force specified, and Checksum specified as $possibleChecksumValue" { + { + Context "When expanding an archive with an edited file, Validate and Force specified, and Checksum specified as $possibleChecksumValue" { $destinationDirectoryName = 'ExpandModifiedArchiveWithCheck' $destinationDirectoryPath = Join-Path -Path $TestDrive -ChildPath $destinationDirectoryName @@ -431,6 +431,7 @@ Describe 'Archive Integration Tests' { # This foreach loop with the Open-Archive call is needed to set the timestamps of the files at the destination correctly $destinationChildItems = Get-ChildItem -Path $destinationDirectoryPath -Recurse -File + foreach ($destinationChildItem in $destinationChildItems) { $correspondingZipItemPath = $destinationChildItem.FullName.Replace($destinationDirectoryPath + '\', '') @@ -438,7 +439,9 @@ Describe 'Archive Integration Tests' { try { - $matchingArchiveEntry = $archive.Entries | Where-Object -FilterScript {$_.FullName -eq $correspondingZipItemPath } + $matchingArchiveEntry = $archive.Entries | Where-Object -FilterScript { + $_.FullName -eq $correspondingZipItemPath + } $archiveEntryLastWriteTime = $matchingArchiveEntry.LastWriteTime.DateTime } finally @@ -451,19 +454,23 @@ Describe 'Archive Integration Tests' { } It 'Test-TargetResource with Ensure as Present should return true before file edit' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false before file edit' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false } $fileToEditPath = Join-Path -Path $destinationDirectoryPath -ChildPath $fileToEditName It 'File to edit should exist at the destination before Set-TargetResource' { - Test-Path -Path $fileToEditPath | Should Be $true + Test-Path -Path $fileToEditPath | Should -Be $true } + $fileBeforeEdit = Get-Item -Path $fileToEditPath + $lastWriteTimeBeforeEdit = $fileBeforeEdit.LastWriteTime + $creationTimeBeforeEdit = $fileBeforeEdit.CreationTime + $null = Set-Content -Path $fileToEditPath -Value 'Different false text' -Force Set-ItemProperty -Path $fileToEditPath -Name 'LastWriteTime' -Value ([DateTime]::MaxValue) Set-ItemProperty -Path $fileToEditPath -Name 'CreationTime' -Value ([DateTime]::MaxValue) @@ -471,65 +478,65 @@ Describe 'Archive Integration Tests' { $fileAfterEdit = Get-Item -Path $fileToEditPath It 'Edited file at the destination should have different content than the same file in the archive before Set-TargetResource' { - Get-Content -Path $fileToEditPath -Raw | Should Not Be ($zipFileStructure[$fileToEditName] + "`r`n") + Get-Content -Path $fileToEditPath -Raw | Should -Not -Be ($zipFileStructure[$fileToEditName] + "`r`n") } It 'Edited file at the destination should have different last write time than the same file in the archive before Set-TargetResource' { - [DateTime]($fileAfterEdit.LastWriteTime.DateTime) -eq [DateTime]($archiveEntryLastWriteTime) | Should Be $false + $fileAfterEdit.LastWriteTime | Should -Not -Be $lastWriteTimeBeforeEdit } It 'Edited file at the destination should have different creation time than the last write time of the the same file in the archive before Set-TargetResource' { - $fileAfterEdit.CreationTime | Should Not Be $archiveEntryLastWriteTime + $fileAfterEdit.CreationTime | Should -Not -Be $lastWriteTimeBeforeEdit } It 'Test-TargetResource with Ensure as Present should return false before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true } It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue -Force $true } | Should Not Throw - } - - It 'Edited file should exist at the destination after Set-TargetResource' { - Test-Path -Path $fileToEditPath | Should Be $true - } - - It 'Edited file at the destination should have the same content as the same file in the archive after Set-TargetResource' { - Get-Content -Path $fileToEditPath -Raw | Should Be ($zipFileStructure[$fileToEditName] + "`r`n") + { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue -Force $true } | Should -Not -Throw } $fileAfterSetTargetResource = Get-Item -Path $fileToEditPath + It 'Edited file should exist at the destination after Set-TargetResource' { + Test-Path -Path $fileToEditPath | Should -Be $true + } + + It 'Edited file at the destination should have the same content as the same file in the archive after Set-TargetResource' { + Get-Content -Path $fileToEditPath -Raw | Should -Be ($zipFileStructure[$fileToEditName] + "`r`n") + } + It 'Edited file at the destination should have the same last write time as the same file in the archive after Set-TargetResource' { - [DateTime]($fileAfterSetTargetResource.LastWriteTime.DateTime) -eq [DateTime]($archiveEntryLastWriteTime) | Should Be $true + $fileAfterSetTargetResource.LastWriteTime | Should -Be $lastWriteTimeBeforeEdit } It 'Edited file at the destination should have the same creation time as last write time of the the same file in the archive after Set-TargetResource' { - [DateTime]($fileAfterSetTargetResource.CreationTime.DateTime) -eq [DateTime]($archiveEntryLastWriteTime) | Should Be $true + $fileAfterSetTargetResource.CreationTime | Should -Be $lastWriteTimeBeforeEdit } It 'Test-TargetResource with Ensure as Present should return true after Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false after Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false } It 'File structure and contents of the destination should match the file structure and contents of the archive after Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $true + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true } } - Context "Expand an archive with an edited file, Validate specfied, Force not specified, and Checksum specified as $possibleChecksumValue" { + Context "When expanding an archive with an edited file, Validate specfied, Force not specified, and Checksum specified as $possibleChecksumValue" { $destinationDirectoryName = 'ExpandModifiedArchiveWithCheckFail' $destinationDirectoryPath = Join-Path -Path $TestDrive -ChildPath $destinationDirectoryName @@ -537,6 +544,7 @@ Describe 'Archive Integration Tests' { # This foreach loop with the Open-Archive call is needed to set the timestamps of the files at the destination correctly $destinationChildItems = Get-ChildItem -Path $destinationDirectoryPath -Recurse -File + foreach ($destinationChildItem in $destinationChildItems) { $correspondingZipItemPath = $destinationChildItem.FullName.Replace($destinationDirectoryPath + '\', '') @@ -544,7 +552,9 @@ Describe 'Archive Integration Tests' { try { - $matchingArchiveEntry = $archive.Entries | Where-Object -FilterScript {$_.FullName -eq $correspondingZipItemPath } + $matchingArchiveEntry = $archive.Entries | Where-Object -FilterScript { + $_.FullName -eq $correspondingZipItemPath + } $archiveEntryLastWriteTime = $matchingArchiveEntry.LastWriteTime.DateTime } finally @@ -557,19 +567,23 @@ Describe 'Archive Integration Tests' { } It 'Test-TargetResource with Ensure as Present should return true before file edit' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false before file edit' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false } $fileToEditPath = Join-Path -Path $destinationDirectoryPath -ChildPath $fileToEditName It 'File to edit should exist at the destination before Set-TargetResource' { - Test-Path -Path $fileToEditPath | Should Be $true + Test-Path -Path $fileToEditPath | Should -Be $true } + $fileBeforeEdit = Get-Item -Path $fileToEditPath + $lastWriteTimeBeforeEdit = $fileBeforeEdit.LastWriteTime + $creationTimeBeforeEdit = $fileBeforeEdit.CreationTime + $null = Set-Content -Path $fileToEditPath -Value 'Different false text' -Force Set-ItemProperty -Path $fileToEditPath -Name 'LastWriteTime' -Value ([DateTime]::MaxValue) Set-ItemProperty -Path $fileToEditPath -Name 'CreationTime' -Value ([DateTime]::MaxValue) @@ -577,35 +591,33 @@ Describe 'Archive Integration Tests' { $fileAfterEdit = Get-Item -Path $fileToEditPath It 'Edited file at the destination should have different content than the same file in the archive before Set-TargetResource' { - Get-Content -Path $fileToEditPath -Raw | Should Not Be ($zipFileStructure[$fileToEditName] + "`r`n") + Get-Content -Path $fileToEditPath -Raw | Should -Not -Be ($zipFileStructure[$fileToEditName] + "`r`n") } It 'Edited file at the destination should have different last write time than the same file in the archive before Set-TargetResource' { - [DateTime]($fileAfterEdit.LastWriteTime.DateTime) -eq [DateTime]($archiveEntryLastWriteTime) | Should Be $false + $fileAfterEdit.LastWriteTime | Should -Not -Be $lastWriteTimeBeforeEdit } It 'Edited file at the destination should have different creation time than the last write time of the the same file in the archive before Set-TargetResource' { - $fileAfterEdit.CreationTime.DateTime -eq $archiveEntryLastWriteTime | Should Be $false + $fileAfterEdit.CreationTime | Should -Not -Be $lastWriteTimeBeforeEdit } It 'Test-TargetResource with Ensure as Present should return false before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true } It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } - It 'Set-TargetResource should throw an error that the resource cannot overwrite the destination without Force specified' { - { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue } | Should Throw - } + { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue } | Should -Throw } - Context "Remove an archive with an edited file, Validate specified, and Checksum specified as $possibleChecksumValue" { + Context "When removing an archive with an edited file, Validate specified, and Checksum specified as $possibleChecksumValue" { $destinationDirectoryName = 'RemoveModifiedArchiveWithCheck' $destinationDirectoryPath = Join-Path -Path $TestDrive -ChildPath $destinationDirectoryName @@ -613,6 +625,7 @@ Describe 'Archive Integration Tests' { # This foreach loop with the Open-Archive call is needed to set the timestamps of the files at the destination correctly $destinationChildItems = Get-ChildItem -Path $destinationDirectoryPath -Recurse -File + foreach ($destinationChildItem in $destinationChildItems) { $correspondingZipItemPath = $destinationChildItem.FullName.Replace($destinationDirectoryPath + '\', '') @@ -620,7 +633,9 @@ Describe 'Archive Integration Tests' { try { - $matchingArchiveEntry = $archive.Entries | Where-Object -FilterScript {$_.FullName -eq $correspondingZipItemPath } + $matchingArchiveEntry = $archive.Entries | Where-Object -FilterScript { + $_.FullName -eq $correspondingZipItemPath + } $archiveEntryLastWriteTime = $matchingArchiveEntry.LastWriteTime.DateTime } finally @@ -633,86 +648,90 @@ Describe 'Archive Integration Tests' { } It 'Test-TargetResource with Ensure as Present should return true before file edit' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $true + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true } It 'Test-TargetResource with Ensure as Absent should return false before file edit' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $false + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false } $fileToEditPath = Join-Path -Path $destinationDirectoryPath -ChildPath $fileToEditName It 'File to edit should exist at the destination before Set-TargetResource' { - Test-Path -Path $fileToEditPath | Should Be $true + Test-Path -Path $fileToEditPath | Should -Be $true } + $fileBeforeEdit = Get-Item -Path $fileToEditPath + $lastWriteTimeBeforeEdit = $fileBeforeEdit.LastWriteTime + $creationTimeBeforeEdit = $fileBeforeEdit.CreationTime + $null = Set-Content -Path $fileToEditPath -Value 'Different false text' -Force - $null = Set-ItemProperty -Path $fileToEditPath -Name 'LastWriteTime' -Value ([DateTime]::MaxValue) - $null = Set-ItemProperty -Path $fileToEditPath -Name 'CreationTime' -Value ([DateTime]::MaxValue) + Set-ItemProperty -Path $fileToEditPath -Name 'LastWriteTime' -Value ([DateTime]::MaxValue) + Set-ItemProperty -Path $fileToEditPath -Name 'CreationTime' -Value ([DateTime]::MaxValue) $fileAfterEdit = Get-Item -Path $fileToEditPath It 'Edited file at the destination should have the edited content' { - Get-Content -Path $fileToEditPath -Raw | Should Be ('Different false text' + "`r`n") + Get-Content -Path $fileToEditPath -Raw | Should -Be ('Different false text' + "`r`n") } It 'Edited file at the destination should have different last write time than the same file in the archive after file edit and before Set-TargetResource' { - [DateTime]($fileAfterEdit.LastWriteTime.DateTime) -eq [DateTime]($archiveEntryLastWriteTime) | Should Be $false + $fileAfterEdit.LastWriteTime | Should -Not -Be $lastWriteTimeBeforeEdit } It 'Edited file at the destination should have different creation time than the last write time of the the same file in the archive after file edit before Set-TargetResource' { - $fileAfterEdit.CreationTime.DateTime -eq $archiveEntryLastWriteTime | Should Be $false + $fileAfterEdit.CreationTime | Should -Not -Be $lastWriteTimeBeforeEdit } It 'Test-TargetResource with Ensure as Present should return false before Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true before Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true } It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue } | Should Not Throw - } - - It 'Edited file should exist at the destination after Set-TargetResource' { - Test-Path -Path $fileToEditPath | Should Be $true - } - - It 'Edited file at the destination should have the edited content' { - Get-Content -Path $fileToEditPath -Raw | Should Be ('Different false text' + "`r`n") + { Set-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue } | Should -Not -Throw } $fileAfterSetTargetResource = Get-Item -Path $fileToEditPath + It 'Edited file should exist at the destination after Set-TargetResource' { + Test-Path -Path $fileToEditPath | Should -Be $true + } + + It 'Edited file at the destination should have the edited content' { + Get-Content -Path $fileToEditPath -Raw | Should -Be ('Different false text' + "`r`n") + } + It 'Edited file at the destination should have different last write time than the same file in the archive after Set-TargetResource' { - [DateTime]($fileAfterSetTargetResource.LastWriteTime.DateTime) -eq [DateTime]($archiveEntryLastWriteTime) | Should Be $false + $fileAfterEdit.LastWriteTime | Should -Not -Be $lastWriteTimeBeforeEdit } It 'Edited file at the destination should have different creation time than the last write time of the the same file in the archive after Set-TargetResource' { - $fileAfterSetTargetResource.CreationTime.DateTime -eq $archiveEntryLastWriteTime | Should Be $false + $fileAfterEdit.CreationTime | Should -Not -Be $lastWriteTimeBeforeEdit } It 'Test-TargetResource with Ensure as Present should return false after Set-TargetResource' { - Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $false + Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false } It 'Test-TargetResource with Ensure as Absent should return true after Set-TargetResource' { - Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should Be $true + Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true } It 'File structure and contents of the destination should not match the file structure and contents of the archive after Set-TargetResource' { - Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should Be $false + Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false } } } - Context 'Archive name contains a bracket' { + Context 'When expanding an archive when the archive name contains a bracket' { $zipFileName = 'ReturnCorrectValue[' $zipFileStructure = @{ @@ -726,15 +745,15 @@ Describe 'Archive Integration Tests' { $destination = Join-Path -Path $TestDrive -ChildPath 'ArchiveNameWithBracket' It 'Set-TargetResource should not throw' { - { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destination } | Should Not Throw + { Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destination } | Should -Not -Throw } It 'Get-TargetResource should not throw' { - { $null = Get-TargetResource -Path $zipFilePath -Destination $destination } | Should Not Throw + { $null = Get-TargetResource -Path $zipFilePath -Destination $destination } | Should -Not -Throw } It 'Test-TargetResource should not throw' { - { $null = Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destination } | Should Not Throw + { $null = Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destination } | Should -Not -Throw } } } diff --git a/appveyor.yml b/appveyor.yml index 4f75df0..1ad961f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,21 +2,12 @@ # environment configuration # #---------------------------------# version: 2.4.{build}.0 -os: Visual Studio 2015 install: - git clone https://github.com/PowerShell/DscResource.Tests - - ps: Import-Module -Name .\Tests\TestHelpers\WMF5Dot1Installation.psm1 -Force - - ps: Install-Wmf5Dot1 - - ps: Start-Sleep 5 - - ps: Restart-Computer -Force - - ps: Start-Sleep 5 - - ps: Write-Verbose -Message "Returned after restart with PSVersion $($PSVersionTable.PSVersion)" -Verbose - - ps: if ($PSVersionTable.PSVersion -lt [Version] '5.1') - { - throw 'WMF 5.1 install failed' - } - - ps: Import-Module "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" - - ps: Invoke-AppveyorInstallTask + - ps: | + $moduleName = 'PSDscResources' + Import-Module "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" + Invoke-AppveyorInstallTask #---------------------------------# # build configuration # @@ -30,13 +21,23 @@ build: false test_script: - ps: | - Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo + Invoke-AppveyorTestScriptTask ` + -Type 'Default' ` + -CodeCoverage ` + -CodeCovIo ` + -DisableConsistency ` + -ExcludeTag @() + +after_test: + - ps: | + Import-Module -Name "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" + Invoke-AppveyorAfterTestTask ` + -ResourceModuleName $moduleName #---------------------------------# # deployment configuration # #---------------------------------# -# scripts to run before deployment deploy_script: - ps: | Invoke-AppveyorAfterTestTask