Skip to content

Commit

Permalink
Merge pull request #1445 from ChristophHannappel/fix/SPSearchCrawlerI…
Browse files Browse the repository at this point in the history
…mpactRule

SPSearchCrawlerImpactRule: Does throw if Rule does not exist.
  • Loading branch information
ykuijs authored Dec 27, 2024
2 parents fd20715 + 9965010 commit e039c98
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 48 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- SPShellAdmins
- Fixed that the Member comparison was not case insensitive.

- SPSearchCrawlerImpactRule
- Ressource threw an error if the Crawler Impact Rule did not exist when
running the Get Method

## [5.5.0] - 2024-04-22

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function Get-TargetResource
}
else
{
$crawlerImpactRule = Get-SPEnterpriseSearchSiteHitRule -Identity $params.Name -SearchService $params.ServiceAppName
$crawlerImpactRule = Get-SPEnterpriseSearchSiteHitRule -SearchService $params.ServiceAppName | Where-Object -FilterScript { $_.Site -eq $params.Name }
if ($null -eq $crawlerImpactRule)
{
return $nullReturn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function Invoke-TestSetup

$script:testEnvironment = Initialize-TestEnvironment `
-DSCModuleName $script:DSCModuleName `
-DSCResourceName $script:DSCResourceFullName `
-DscResourceName $script:DSCResourceFullName `
-ResourceType 'Mof' `
-TestType 'Unit'
}
Expand All @@ -49,7 +49,7 @@ try
InModuleScope -ModuleName $script:DSCResourceFullName -ScriptBlock {
Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture {
BeforeAll {
Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope
Invoke-Command -Scriptblock $Global:SPDscHelper.InitializeScript -NoNewScope

# Initialize tests
$getTypeFullName = "Microsoft.Office.Server.Search.Administration.SearchServiceApplication"
Expand All @@ -61,16 +61,16 @@ try
Mock -CommandName Get-SPServiceApplication -MockWith {
return @(
New-Object -TypeName "Object" |
Add-Member -MemberType ScriptMethod `
-Name GetType `
-Value {
New-Object -TypeName "Object" |
Add-Member -MemberType NoteProperty `
-Name FullName `
-Value $getTypeFullName `
-PassThru
} `
-PassThru -Force)
Add-Member -MemberType ScriptMethod `
-Name GetType `
-Value {
New-Object -TypeName "Object" |
Add-Member -MemberType NoteProperty `
-Name FullName `
-Value $getTypeFullName `
-PassThru
} `
-PassThru -Force)
}

function Add-SPDscEvent
Expand Down Expand Up @@ -101,7 +101,7 @@ try
BeforeAll {
$testParams = @{
ServiceAppName = "Search Service Application"
Name = "http://site.sharepoint.com"
Name = "site.sharepoint.com"
RequestLimit = 8
Ensure = "Present"
}
Expand Down Expand Up @@ -135,7 +135,7 @@ try
BeforeAll {
$testParams = @{
ServiceAppName = "Search Service Application"
Name = "http://site.sharepoint.com"
Name = "site.sharepoint.com"
RequestLimit = 8
Ensure = "Present"
}
Expand All @@ -147,15 +147,15 @@ try
}

Mock -CommandName Get-SPEnterpriseSearchSiteHitRule -MockWith {
return @{
Name = $testParams.Name
return [pscustomobject]@{
Site = $testParams.Name
HitRate = $testParams.RequestLimit
Behavior = "0"
Behavior = 0
}
}
}

It "Should return absent from the Get method" {
It "Should return Present from the Get method" {
(Get-TargetResource @testParams).Ensure | Should -Be "Present"
}

Expand All @@ -174,7 +174,7 @@ try
BeforeAll {
$testParams = @{
ServiceAppName = "Search Service Application"
Name = "http://site.sharepoint.com"
Name = "site.sharepoint.com"
Ensure = "Absent"
}

Expand All @@ -185,33 +185,24 @@ try
}

Mock -CommandName Get-SPEnterpriseSearchSiteHitRule -MockWith {
return @{
Name = $testParams.Name
HitRate = $testParams.RequestLimit
}
return $null
}
}

It "Should return present from the Get method" {
(Get-TargetResource @testParams).Ensure | Should -Be "Present"
}

It "Should return false when the Test method is called" {
Test-TargetResource @testParams | Should -Be $false
(Get-TargetResource @testParams).Ensure | Should -Be "Absent"
}

It "Should remove the search Site hit rule in the set method" {
Set-TargetResource @testParams
Assert-MockCalled Remove-SPEnterpriseSearchSiteHitRule

It "Should return true when the Test method is called" {
Test-TargetResource @testParams | Should -Be $true
}
}

Context -Name "When crawler impact requestlimit rule shouldn't exist and does exist" -Fixture {
BeforeAll {
$testParams = @{
ServiceAppName = "Search Service Application"
Name = "http://site.sharepoint.com"
Name = "site.sharepoint.com"
Ensure = "Absent"
}

Expand Down Expand Up @@ -244,7 +235,7 @@ try
BeforeAll {
$testParams = @{
ServiceAppName = "Search Service Application"
Name = "http://site.sharepoint.com"
Name = "site.sharepoint.com"
Ensure = "Absent"
}

Expand All @@ -271,7 +262,7 @@ try
BeforeAll {
$testParams = @{
ServiceAppName = "Search Service Application"
Name = "http://site.sharepoint.com"
Name = "site.sharepoint.com"
RequestLimit = 8
WaitTime = 60
Ensure = "Present"
Expand All @@ -290,7 +281,7 @@ try
BeforeAll {
$testParams = @{
ServiceAppName = "Search Service Application"
Name = "http://site.sharepoint.com"
Name = "site.sharepoint.com"
WaitTime = 300
Ensure = "Present"
}
Expand Down Expand Up @@ -324,7 +315,7 @@ try
BeforeAll {
$testParams = @{
ServiceAppName = "Search Service Application"
Name = "http://site.sharepoint.com"
Name = "site.sharepoint.com"
WaitTime = 300
Ensure = "Present"
}
Expand All @@ -336,27 +327,21 @@ try
}

Mock -CommandName Get-SPEnterpriseSearchSiteHitRule -MockWith {
return @{
Name = $testParams.Name
return [pscustomobject]@{
Site = $testParams.Name
HitRate = $testParams.WaitTime
Behavior = "1"
Behavior = 1
}
}
}

It "Should return absent from the Get method" {
It "Should return Present from the Get method" {
(Get-TargetResource @testParams).Ensure | Should -Be "Present"
}

It "Should return true when the Test method is called" {
Test-TargetResource @testParams | Should -Be $true
}

It "Should update a new search Site hit rule in the set method" {
Set-TargetResource @testParams
Assert-MockCalled Remove-SPEnterpriseSearchSiteHitRule
Assert-MockCalled New-SPEnterpriseSearchSiteHitRule
}
}
}
}
Expand Down

0 comments on commit e039c98

Please sign in to comment.