Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
Stop-Computer.Tests.ps174 linesDownload Raw Back to Microsoft.PowerShell.Management
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4# note these will manipulate private data in the PowerShell engine which will5# enable us to not actually stop the system, but return right before we do6$stopTesthook = "TestStopComputer"7$stopTesthookResultName = "TestStopComputerResults"8$DefaultResultValue = 09 10try11{12    # set up for testing13    Enable-Testhook -testhookName $stopTesthook14 15    Describe "Stop-Computer" -Tag Feature {16        # if we throw in BeforeEach, the test will fail and the stop will not be called17        BeforeEach {18            if ( ! (Test-TesthookIsSet -testhookName $stopTesthook) ) {19                throw "Testhook '${stopTesthook}' is not set"20            }21        }22 23        AfterEach {24            Set-TesthookResult -testhookName $stopTesthookResultName -Value $defaultResultValue25        }26 27        It "Should stop the local computer" {28            Set-TesthookResult -testhookName $stopTesthookResultName -Value $defaultResultValue29            Stop-Computer -ErrorAction Stop | Should -BeNullOrEmpty30        }31 32        It "Should support -Computer parameter" -Skip:(!$IsWindows) {33            Set-TesthookResult -testhookName $stopTesthookResultName -Value $defaultResultValue34            $computerNames = "localhost","${env:COMPUTERNAME}"35            Stop-Computer -Computer $computerNames -ErrorAction Stop | Should -BeNullOrEmpty36        }37 38        It "Should support WsmanAuthentication types" -Skip:(!$IsWindows) {39            $authChoices = "Default","Basic","Negotiate","CredSSP","Digest","Kerberos"40            foreach ( $auth in $authChoices ) {41                Stop-Computer -WsmanAuthentication $auth | Should -BeNullOrEmpty42            }43        }44 45        Context "Stop-Computer Error Conditions" {46            It "Should return the proper error when it occurs" {47                Set-TesthookResult -testhookName $stopTesthookResultName -Value 0x30000048                Stop-Computer -ErrorVariable StopError 2> $null49                $StopError.Exception.Message | Should -Match 0x30000050            }51        }52    }53 54}55finally56{57    $PSDefaultParameterValues.Remove("it:skip")58    Disable-Testhook -testhookName $stopTesthook59    Set-TesthookResult -testhookName $stopTesthookResultName -Value $DefaultResultValue60}61 62Describe 'Non-admin on Unix' {63    BeforeAll {64        $skip = $false65        if ($IsWindows -or [environment]::IsPrivilegedProcess -or ($null -eq (Get-Command shutdown -CommandType Application -ErrorAction Ignore))) {66            $skip = $true67        }68    }69 70    It 'Reports error if not run under sudo' -Skip:($skip) {71        { Stop-Computer -ErrorAction Stop } | Should -Throw -ErrorId "CommandFailed,Microsoft.PowerShell.Commands.StopComputerCommand"72    }73}74