github.com/cloudfoundry-incubator/stembuild@v0.0.0-20211223202937-5b61d62226c6/modules/BOSH.Registry/BOSH.Registry.Tests.ps1 (about)

     1  Remove-Module -Name BOSH.Registry -ErrorAction Ignore
     2  Import-Module ./BOSH.Registry.psm1
     3  
     4  Describe "BOSH.Registry" {
     5      BeforeEach {
     6          $newItemReturn = [pscustomobject]@{"NewPath" = "HKCU:/Path/created";}
     7          Mock New-Item { $newItemReturn } -ModuleName BOSH.Registry
     8          # reset for our -parameterfilter mock
     9          Mock New-Item { $newItemReturn } -ModuleName BOSH.Registry -ParameterFilter { $PSBoundParameters['ErrorAction'] -eq "Stop" }
    10      }
    11  
    12      It "Set-InternetExplorerRegistries applies internet explorer settings when valid policy files are generated" {
    13          Mock Invoke-LGPO-Build-Pol-From-Text { 0 } -ModuleName BOSH.Registry
    14          Mock Invoke-LGPO-Apply-Policies  { 0 } -ModuleName BOSH.Registry
    15  
    16          Set-InternetExplorerRegistries
    17  
    18          Assert-MockCalled Invoke-LGPO-Build-Pol-From-Text -Exactly 2 -Scope It -ModuleName BOSH.Registry
    19          Assert-MockCalled Invoke-LGPO-Apply-Policies -Exactly 1 -Scope It -ModuleName BOSH.Registry
    20      }
    21      It "Set-InternetExplorerRegistries errors out when policy application fails" {
    22          Mock Invoke-LGPO-Build-Pol-From-Text { 0 } -ModuleName BOSH.Registry
    23          Mock Invoke-LGPO-Apply-Policies  { 1 } -ModuleName BOSH.Registry
    24  
    25          { Set-InternetExplorerRegistries } | Should -Throw "Error Applying IE policy:"
    26  
    27          Assert-MockCalled Invoke-LGPO-Build-Pol-From-Text -Exactly 2 -Scope It -ModuleName BOSH.Registry
    28          Assert-MockCalled Invoke-LGPO-Apply-Policies -Exactly 1 -Scope It -ModuleName BOSH.Registry
    29      }
    30  
    31      It "Set-InternetExplorerRegistries errors out when User policy generation fails and does not attempt policy application" {
    32          Mock Invoke-LGPO-Build-Pol-From-Text { 0 } -ModuleName BOSH.Registry -ParameterFilter {
    33              $LGPOTextReadPath -like "*machine.txt"
    34          }
    35          Mock Invoke-LGPO-Build-Pol-From-Text { 1 } -ModuleName BOSH.Registry -ParameterFilter {
    36              $LGPOTextReadPath -like "*user.txt"
    37          }
    38  
    39          { Set-InternetExplorerRegistries } | Should -Throw "Generating IE policy: User"
    40  
    41          Assert-MockCalled Invoke-LGPO-Build-Pol-From-Text -Exactly 2 -Scope It -ModuleName BOSH.Registry
    42          Assert-MockCalled Invoke-LGPO-Apply-Policies -Exactly 0 -Scope It -ModuleName BOSH.Registry
    43      }
    44  
    45      It "Set-InternetExplorerRegistries errors out when Machine policy generation fails and does not attempt policy application" {
    46          Mock Invoke-LGPO-Build-Pol-From-Text { 1 } -ModuleName BOSH.Registry -ParameterFilter {
    47              $LGPOTextReadPath -like "*machine.txt"
    48          }
    49  
    50          { Set-InternetExplorerRegistries } | Should -Throw "Generating IE policy: Machine"
    51  
    52          Assert-MockCalled Invoke-LGPO-Build-Pol-From-Text -Exactly 1 -Scope It -ModuleName BOSH.Registry
    53          Assert-MockCalled Invoke-LGPO-Apply-Policies -Exactly 0 -Scope It -ModuleName BOSH.Registry
    54      }
    55  
    56      It "Set-InternetExplorerRegistries doesn't call Invoke-LGPO-Build-Pol-From-Text if New-Item call for Machine Directory fails" {
    57          # ErrorAction Parameterfilter is present to ensure we only throw an error on a New-Item call that is configured to throw errors
    58          Mock New-Item { Throw 'some error' } -ModuleName BOSH.Registry -ParameterFilter {
    59              $Path -like "*Machine" -and
    60              $PSBoundParameters['ErrorAction'] -eq "Stop"
    61          }
    62  
    63          { Set-InternetExplorerRegistries } | Should -Throw
    64  
    65          Assert-MockCalled Invoke-LGPO-Build-Pol-From-Text -Exactly 0 -Scope It -ModuleName BOSH.Registry
    66          Assert-MockCalled Invoke-LGPO-Apply-Policies -Exactly 0 -Scope It -ModuleName BOSH.Registry
    67      }
    68  
    69  
    70      It "Set-InternetExplorerRegistries doesn't call Invoke-LGPO-Build-Pol-From-Text if New-Item call for User Directory fails" {
    71          # ErrorAction Parameterfilter is present to ensure we only throw an error on a New-Item call that is configured to throw errors
    72          Mock New-Item { Throw 'some error' } -ModuleName BOSH.Registry -ParameterFilter {
    73              $Path -like "*User" -and
    74                      $PSBoundParameters['ErrorAction'] -eq "Stop"
    75          }
    76  
    77          { Set-InternetExplorerRegistries } | Should -Throw
    78  
    79          Assert-MockCalled Invoke-LGPO-Build-Pol-From-Text -Exactly 1 -Scope It -ModuleName BOSH.Registry
    80          Assert-MockCalled Invoke-LGPO-Apply-Policies -Exactly 0 -Scope It -ModuleName BOSH.Registry
    81      }
    82  }