Add ShouldProcess to New-FileCatalog and Test-FileCatalog (#3074)
* Add ShouldProcess to New-FileCatalog and Test-FileCatalog Close #3068 Add support `-WhatIf` and `-Confirm` to `New-FileCatalog` and add a test. `Test-FileCatalog` has a common code base with `New-FileCatalog` so it automatically get the same. I believe that adding a separate test in this case doesn't make sense. * Fiz after code review Remove _ShouldProcess Add var in test
This commit is contained in:
parent
88c8be75f2
commit
e10cbff354
|
@ -95,20 +95,27 @@ namespace Microsoft.PowerShell.Commands
|
|||
{
|
||||
foreach (PathInfo tempPath in SessionState.Path.GetResolvedPSPathFromPSPath(p))
|
||||
{
|
||||
paths.Add(tempPath.ProviderPath);
|
||||
if (ShouldProcess(tempPath.ProviderPath))
|
||||
{
|
||||
paths.Add(tempPath.ProviderPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string drive = null;
|
||||
|
||||
// resolve catalog destination Path
|
||||
if (!SessionState.Path.IsPSAbsolute(catalogFilePath, out drive) && !System.IO.Path.IsPathRooted(catalogFilePath))
|
||||
// We add 'paths.Count > 0' to support 'ShouldProcess()'
|
||||
if (paths.Count > 0 )
|
||||
{
|
||||
catalogFilePath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(catalogFilePath);
|
||||
}
|
||||
string drive = null;
|
||||
|
||||
PerformAction(paths, catalogFilePath);
|
||||
// resolve catalog destination Path
|
||||
if (!SessionState.Path.IsPSAbsolute(catalogFilePath, out drive) && !System.IO.Path.IsPathRooted(catalogFilePath))
|
||||
{
|
||||
catalogFilePath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(catalogFilePath);
|
||||
}
|
||||
|
||||
PerformAction(paths, catalogFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -42,6 +42,27 @@ Describe "Test suite for NewFileCatalogAndTestFileCatalogCmdlets" -Tags "CI" {
|
|||
|
||||
Context "NewAndTestCatalogTests PositiveTestCases when validation Succeeds" {
|
||||
|
||||
It "NewFileCatalogWithSingleFile with WhatIf" {
|
||||
|
||||
$sourcePath = Join-Path $testDataPath '\CatalogTestFile1.mof'
|
||||
# use existant Path for the directory when .cat file name is not specified
|
||||
$catalogPath = $testDataPath
|
||||
$catalogFile = $catalogPath + "\catalog.cat"
|
||||
|
||||
try
|
||||
{
|
||||
$null = New-FileCatalog -Path $sourcePath -CatalogFilePath $catalogPath -WhatIf
|
||||
$result = Test-Path -Path $catalogFile
|
||||
}
|
||||
finally
|
||||
{
|
||||
Remove-Item $catalogFile -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
# Validate result properties
|
||||
$result | Should Be $false
|
||||
}
|
||||
|
||||
It "NewFileCatalogFolder" {
|
||||
|
||||
$sourcePath = Join-Path $testDataPath 'UserConfigProv\DSCResources\scriptdsc'
|
||||
|
|
Loading…
Reference in a new issue