Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opt in to Localization Validation - Fixes #206 #208

Merged
merged 11 commits into from
Jul 6, 2019
Merged
3 changes: 2 additions & 1 deletion .MetaTestOptIn.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"Common Tests - Custom Script Analyzer Rules",
"Common Tests - Validate Example Files To Be Published",
"Common Tests - Validate Markdown Links",
"Common Tests - Relative Path Length"
"Common Tests - Relative Path Length",
"Common Tests - Validate Localization"
]
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

## Unreleased

- Removed suppression of `PSUseShouldProcessForStateChangingFunctions` PSSA rule
because it is no longer required.
- Combined all `StorageDsc.ResourceHelper` module functions into
`StorageDsc.Common` module and removed `StorageDsc.ResourceHelper`.
- Opted into Common Tests 'Common Tests - Validate Localization' -
fixes [Issue #206](https://github.com/PowerShell/StorageDsc/issues/206).
- Refactored tests for `StorageDsc.Common` to meet latest standards.
- Minor style corrections.
- Removed unused localization strings from resources.

## 4.7.0.0

- DiskAccessPath:
Expand Down
111 changes: 52 additions & 59 deletions DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.psm1

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
CreatingPartitionMessage = Creating partition on disk with {0} '{1}' with drive letter '{2}' using {3}.
FormattingVolumeMessage = Formatting the volume as '{0}'.
SuccessfullyInitializedMessage = Successfully initialized '{0}'.
ChangingDriveLetterMessage = The volume already exists, changing drive letter '{0}' to '{1}'.
AssigningDriveLetterMessage = Assigning drive letter '{0}'.
ChangingVolumeLabelMessage = Changing volume '{0}' label to '{1}'.
NewPartitionIsReadOnlyMessage = New partition '{2}' on disk with {0} '{1}' is readonly. Waiting for it to become writable.
Expand Down
90 changes: 39 additions & 51 deletions DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
CreatingPartitionMessage = Creating partition on disk with {0} '{1}' using {2}.
FormattingVolumeMessage = Formatting the volume as '{0}'.
SuccessfullyInitializedMessage = Successfully initialized volume and assigned to access path '{0}'.
ChangingDriveLetterMessage = The volume already exists, changing access path '{0}' to '{1}'.
AssigningDriveLetterMessage = Assigning access path '{0}'.
ChangingVolumeLabelMessage = Changing Volume assigned to access path '{0}' label to '{1}'.
NewPartitionIsReadOnlyMessage = New partition '{1}' on disk with {0} '{1}' is readonly. Waiting for it to become writable.
TestingDiskMessage = Testing disk with {0} '{1}' status for access path '{2}'.
Expand Down
62 changes: 24 additions & 38 deletions DSCResources/MSFT_MountImage/MSFT_MountImage.psm1
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
# Suppressed as per PSSA Rule Severity guidelines for unit/integration tests:
# https://github.com/PowerShell/DscResources/blob/master/PSSARuleSeverities.md
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
param ()

$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules'

$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules'

# Import the Storage Common Modules
Import-Module -Name (Join-Path -Path $modulePath `
-ChildPath (Join-Path -Path 'StorageDsc.Common' `
-ChildPath 'StorageDsc.Common.psm1'))

# Import the Storage Resource Helper Module
# Import the Storage Common Module.
Import-Module -Name (Join-Path -Path $modulePath `
-ChildPath (Join-Path -Path 'StorageDsc.ResourceHelper' `
-ChildPath 'StorageDsc.ResourceHelper.psm1'))
-ChildPath (Join-Path -Path 'StorageDsc.Common' `
-ChildPath 'StorageDsc.Common.psm1'))

# Import Localization Strings
$localizedData = Get-LocalizedData `
-ResourceName 'MSFT_MountImage' `
-ResourcePath (Split-Path -Parent $Script:MyInvocation.MyCommand.Path)
# Import Localization Strings.
$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_MountImage'

<#
.SYNOPSIS
Expand All @@ -42,7 +28,7 @@ function Get-TargetResource

Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($localizedData.GettingMountedImageMessage `
$($script:localizedData.GettingMountedImageMessage `
-f $ImagePath)
) -join '' )

Expand Down Expand Up @@ -149,7 +135,7 @@ function Set-TargetResource

Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($localizedData.SettingMountedImageMessage `
$($script:localizedData.SettingMountedImageMessage `
-f $ImagePath)
) -join '' )

Expand Down Expand Up @@ -180,7 +166,7 @@ function Set-TargetResource
# The disk image is mounted to the wrong DriveLetter -remount disk
Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($localizedData.DismountingImageMessage `
$($script:localizedData.DismountingImageMessage `
-f $ImagePath,$currentState.DriveLetter)
) -join '' )

Expand All @@ -199,7 +185,7 @@ function Set-TargetResource
# The access mode is wrong -remount disk
Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($localizedData.DismountingImageMessage `
$($script:localizedData.DismountingImageMessage `
-f $ImagePath,$currentState.DriveLetter)
) -join '' )

Expand All @@ -213,7 +199,7 @@ function Set-TargetResource
{
Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($localizedData.MountingImageMessage `
$($script:localizedData.MountingImageMessage `
-f $ImagePath,$normalizedDriveLetter)
) -join '' )

Expand All @@ -228,7 +214,7 @@ function Set-TargetResource
# It is mounted so dismount it
Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($localizedData.DismountingImageMessage `
$($script:localizedData.DismountingImageMessage `
-f $ImagePath,$currentState.DriveLetter)
) -join '' )

Expand Down Expand Up @@ -288,7 +274,7 @@ function Test-TargetResource

Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($localizedData.TestingMountedImageMessage `
$($script:localizedData.TestingMountedImageMessage `
-f $DriveLetter)
) -join '' )

Expand All @@ -309,7 +295,7 @@ function Test-TargetResource
# The disk image isn't mounted
Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($localizedData.ImageIsNotMountedButShouldBeMessage `
$($script:localizedData.ImageIsNotMountedButShouldBeMessage `
-f $ImagePath,$normalizedDriveLetter)
) -join '' )
return $false
Expand All @@ -320,7 +306,7 @@ function Test-TargetResource
# The disk image is mounted to the wrong DriveLetter
Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($localizedData.ImageIsMountedToTheWrongDriveLetterMessage `
$($script:localizedData.ImageIsMountedToTheWrongDriveLetterMessage `
-f $ImagePath,$currentState.DriveLetter,$normalizedDriveLetter)
) -join '' )
return $false
Expand All @@ -335,7 +321,7 @@ function Test-TargetResource
{
Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($localizedData.VHDAccessModeMismatchMessage `
$($script:localizedData.VHDAccessModeMismatchMessage `
-f $ImagePath,$normalizedDriveLetter,$currentState.Access,$Access)
) -join '' )
return $false
Expand All @@ -346,7 +332,7 @@ function Test-TargetResource
# The Disk Image is mounted to the expected Drive - nothing to change.
Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($localizedData.ImageIsMountedAndShouldBeMessage `
$($script:localizedData.ImageIsMountedAndShouldBeMessage `
-f $ImagePath,$normalizedDriveLetter)
) -join '' )
}
Expand All @@ -358,7 +344,7 @@ function Test-TargetResource
# The disk image is mounted
Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($localizedData.ImageIsMountedButShouldNotBeMessage `
$($script:localizedData.ImageIsMountedButShouldNotBeMessage `
-f $ImagePath,$currentState.DriveLetter)
) -join '' )
return $false
Expand All @@ -367,7 +353,7 @@ function Test-TargetResource
# The image is not mounted and should not be
Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($localizedData.ImageIsNotMountedAndShouldNotBeMessage `
$($script:localizedData.ImageIsNotMountedAndShouldNotBeMessage `
-f $ImagePath)
) -join '' )
} # if
Expand Down Expand Up @@ -436,23 +422,23 @@ function Test-ParameterValid
{
# The DriveLetter should not be set if Ensure is Absent
New-InvalidOperationException `
-Message ($localizedData.InvalidParameterSpecifiedError -f `
-Message ($script:localizedData.InvalidParameterSpecifiedError -f `
'Absent','DriveLetter')
} # if

if ($PSBoundParameters.ContainsKey('StorageType'))
{
# The StorageType should not be set if Ensure is Absent
New-InvalidOperationException `
-Message ($localizedData.InvalidParameterSpecifiedError -f `
-Message ($script:localizedData.InvalidParameterSpecifiedError -f `
'Absent','StorageType')
} # if

if ($PSBoundParameters.ContainsKey('Access'))
{
# The Access should not be set if Ensure is Absent
New-InvalidOperationException `
-Message ($localizedData.InvalidParameterSpecifiedError -f `
-Message ($script:localizedData.InvalidParameterSpecifiedError -f `
'Absent','Access')
} # if
}
Expand All @@ -462,7 +448,7 @@ function Test-ParameterValid
{
# The file specified by ImagePath should be found
New-InvalidOperationException `
-Message ($localizedData.DiskImageFileNotFoundError -f `
-Message ($script:localizedData.DiskImageFileNotFoundError -f `
$ImagePath)
} # if

Expand All @@ -475,7 +461,7 @@ function Test-ParameterValid
{
# Drive letter is not specified but Ensure is present.
New-InvalidOperationException `
-Message ($localizedData.InvalidParameterNotSpecifiedError -f `
-Message ($script:localizedData.InvalidParameterNotSpecifiedError -f `
'Present','DriveLetter')
} # if
} # if
Expand Down Expand Up @@ -569,7 +555,7 @@ function Mount-DiskImageToLetter
{
Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($localizedData.ChangingImageDriveLetterMessage `
$($script:localizedData.ChangingImageDriveLetterMessage `
-f $ImagePath,$currentDriveLetter,$normalizedDriveLetter)
) -join '' )

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
ConvertFrom-StringData @'
GettingMountedImageMessage = Getting Mounted Drive for image file '{0}'.

SettingMountedImageMessage = Setting Mounted Drive for image file '{0}'.
DismountingImageMessage = The image file '{0}' is being dismounted from drive '{1}'.

TestingMountedImageMessage = Testing Mounted Drive for image file '{0}'.
ImageIsNotMountedButShouldBeMessage = The image file '{0}' is not mounted to drive '{1}' but should be. Change required.
ImageIsMountedToTheWrongDriveLetterMessage = The image file '{0}' is mounted as drive '{1}' but should be mounted as drive '{2}'. Change required.
VHDAccessModeMismatchMessage = The image file '{0}' is mounted to drive '{1}' but the access is '{2}' and should be '{3}'. Change required.
ImageIsMountedAndShouldBeMessage = The image file '{0}' is mounted to drive '{1}' and should be.
ImageIsMountedButShouldNotBeMessage = The image file '{0}' is mounted to drive '{1}' but should not be. Change required.
ImageIsNotMountedAndShouldNotBeMessage = The image file '{0}' is not mounted and should not be.

TestingMountedImageError = Testing Mounted Drive for image file '{0}'.
InvalidParameterSpecifiedError = Ensure is '{0}' but '{1}' was specified.
InvalidParameterNotSpecifiedError = Ensure is '{0}' but '{1}' was not specified.
DiskImageFileNotFoundError = The image file '{0}' could not be found.

MountingImageMessage = The image file '{0}' is being mounted as drive '{1}'.
ChangingImageDriveLetterMessage = The image file '{0}' mounted as drive '{1}' will be changed to '{2}'.
'@
Loading