Skip to content

Commit

Permalink
(#221) Inconsistent Logic in xWebsite
Browse files Browse the repository at this point in the history
The Test-TargetResource function in the xWebSite resource used
inconsistent logic in the way that it would test a property for
compliance and then report non-compliance.

Some tests would use the `$PSBoundParameters` variable to check for
parameters to be tested, others would use `[String]::isNullOrEmpty()`

Some tests would set the `$inDesiredState` variable, write a verbose
message and move on, and others would write the verbose message and
use the `return` keyward to immediately exit the function and stop
testing additional properties.

The desired style should use `$PSBoundParameters` and the
`$inDesiredState` variable consistently, so that all properties are
tested for troubleshooting purposes, and to promote conciseness and
reasability

Resolves #221
  • Loading branch information
RandomNoun7 committed Feb 27, 2020
1 parent 89dfe48 commit bd4dab4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md)
does not contain 'dsccommunity'.
- Changed the VS Code project settings to trim trailing whitespace for
markdown files too.
- Ensure that Test-TargetResourse in xWebSite tests all properties before
returning true or false, and that it uses a consistent style. ([issue #221](https://github.com/PowerShell/xWebAdministration/issues/550))

### Fixed

Expand Down
22 changes: 11 additions & 11 deletions source/DSCResources/MSFT_xWebSite/MSFT_xWebSite.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ function Test-TargetResource
}

# Check Physical Path property
if ([String]::IsNullOrEmpty($PhysicalPath) -eq $false -and `
if ($PSBoundParameters.ContainsKey('PhysicalPath') -and `
$website.PhysicalPath -ne $PhysicalPath)
{
$inDesiredState = $false
Expand All @@ -827,7 +827,8 @@ function Test-TargetResource
}

# Check State
if ($PSBoundParameters.ContainsKey('State') -and $website.State -ne $State)
if ($PSBoundParameters.ContainsKey('State') -and `
$website.State -ne $State)
{
$inDesiredState = $false
Write-Verbose -Message ($script:localizedData.VerboseTestTargetFalseState `
Expand Down Expand Up @@ -956,27 +957,27 @@ function Test-TargetResource
# Check Log Format
if ($LogFormat -ne $website.logfile.LogFormat)
{
$inDesiredState = $false
Write-Verbose -Message ($script:localizedData.VerboseTestTargetFalseLogFormat `
-f $Name)
return $false
}
}

# Check LogFlags
if ($PSBoundParameters.ContainsKey('LogFlags') -and `
(-not (Compare-LogFlags -Name $Name -LogFlags $LogFlags)))
{
$inDesiredState = $false
Write-Verbose -Message ($script:localizedData.VerboseTestTargetFalseLogFlags)
return $false
}

# Check LogPath
if ($PSBoundParameters.ContainsKey('LogPath') -and `
($LogPath -ne $website.logfile.directory))
{
$inDesiredState = $false
Write-Verbose -Message ($script:localizedData.VerboseTestTargetFalseLogPath `
-f $Name)
return $false
}

# Check LogPeriod
Expand All @@ -988,47 +989,46 @@ function Test-TargetResource
Write-Verbose -Message ($script:localizedData.WarningLogPeriod `
-f $Name)
}

$inDesiredState = $false
Write-Verbose -Message ($script:localizedData.VerboseTestTargetFalseLogPeriod `
-f $Name)
return $false
}

# Check LogTruncateSize
if ($PSBoundParameters.ContainsKey('LogTruncateSize') -and `
($LogTruncateSize -ne $website.logfile.LogTruncateSize))
{
$inDesiredState = $false
Write-Verbose -Message ($script:localizedData.VerboseTestTargetFalseLogTruncateSize `
-f $Name)
return $false
}

# Check LoglocalTimeRollover
if ($PSBoundParameters.ContainsKey('LoglocalTimeRollover') -and `
($LoglocalTimeRollover -ne `
([System.Convert]::ToBoolean($website.logfile.LocalTimeRollover))))
{
$inDesiredState = $false
Write-Verbose -Message ($script:localizedData.VerboseTestTargetFalseLoglocalTimeRollover `
-f $Name)
return $false
}

# Check LogTargetW3C
if ($PSBoundParameters.ContainsKey('LogTargetW3C') -and `
($LogTargetW3C -ne $website.logfile.LogTargetW3C))
{
$inDesiredState = $false
Write-Verbose -Message ($script:localizedData.VerboseTestTargetFalseLogTargetW3C `
-f $Name)
return $false
}

# Check LogCustomFields if needed
if ($PSBoundParameters.ContainsKey('LogCustomFields') -and `
(-not (Test-LogCustomField -Site $Name -LogCustomField $LogCustomFields)))
{
$inDesiredState = $false
Write-Verbose -Message ($script:localizedData.VerboseTestTargetUpdateLogCustomFields `
-f $Name)
return $false
}
}

Expand Down

0 comments on commit bd4dab4

Please sign in to comment.