From a954f9f98c7ab631e5dd8d0bcacbe6348f3799f4 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Thu, 2 Nov 2017 14:17:45 -0700 Subject: [PATCH] Change line ending in Rename-Computer.Tests.ps1 to LF (#5314) --- .../Rename-Computer.Tests.ps1 | 158 +++++++++--------- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Rename-Computer.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Rename-Computer.Tests.ps1 index 91d167a43c..86c96add0b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Rename-Computer.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Rename-Computer.Tests.ps1 @@ -1,79 +1,79 @@ -$RenameTesthook = "TestRenameComputer" -$RenameResultName = "TestRenameComputerResults" -$DefaultResultValue = 0 - -try -{ - # set up for testing - $PSDefaultParameterValues["it:skip"] = ! $IsWindows - Enable-Testhook -testhookName $RenameTesthook - # we also set TestStopComputer - Enable-Testhook -testhookName TestStopComputer - - # TEST START HERE - Describe "Rename-Computer" -Tag Feature { - # if we throw in BeforeEach, the test will fail and the stop will not be called - BeforeEach { - if ( ! (Test-TesthookIsSet -testhookName $RenameTesthook) ) { - throw "Testhook '${TesthookName}' is not set" - } - } - - AfterEach { - Set-TesthookResult -testhookName $RenameResultName -value $defaultResultValue - } - - It "Should rename the local computer" { - Set-TesthookResult -testhookName $RenameResultName -value $defaultResultValue - $newname = "mynewname" - $result = Rename-Computer -ErrorAction Stop -ComputerName . -NewName "$newname" -Pass -WarningAction SilentlyContinue - $result.HasSucceeded | should be $true - $result.NewComputerName | should be $newname - } - - # we can't really look for the string "reboot" as it will change - # when translated. We are guaranteed that the old computer name will - # be present, so we'll look for that - It "Should produce a reboot warning when renaming computer" { - Set-TesthookResult -testhookName $RenameResultName -value $defaultResultValue - $newname = "mynewname" - $result = Rename-Computer -ErrorAction Stop -ComputerName . -NewName "$newname" -Pass -WarningAction SilentlyContinue -WarningVariable WarnVar - $WarnVar.Message | should match $result.OldComputerName - } - - It "Should not produce a reboot warning when renaming a computer with the reboot flag" { - Set-TesthookResult -testhookName $RenameResultName -value $defaultResultValue - $newname = "mynewname" - $result = Rename-Computer -ErrorAction Stop -ComputerName . -NewName "$newname" -Pass -WarningAction SilentlyContinue -WarningVariable WarnVar -Restart - $result.HasSucceeded | should be $true - $result.NewComputerName | should be $newname - $WarnVar | should BeNullOrEmpty - } - - - Context "Rename-Computer Error Conditions" { - $testcases = - @{ OldName = "." ; NewName = "localhost" ; ExpectedError = "FailToRenameComputer,Microsoft.PowerShell.Commands.RenameComputerCommand" }, - @{ OldName = "." ; NewName = "." ; ExpectedError = "InvalidNewName,Microsoft.PowerShell.Commands.RenameComputerCommand" }, - @{ OldName = "." ; NewName = "::1" ; ExpectedError = "InvalidNewName,Microsoft.PowerShell.Commands.RenameComputerCommand" }, - @{ OldName = "." ; NewName = "127.0.0.1" ; ExpectedError = "InvalidNewName,Microsoft.PowerShell.Commands.RenameComputerCommand" }, - @{ OldName = "." ; NewName = ${env:ComputerName} ; ExpectedError = "NewNameIsOldName,Microsoft.PowerShell.Commands.RenameComputerCommand" }, - @{ OldName = "." ; NewName = ${env:ComputerName} + "." + ${env:USERDNSDOMAIN} ; ExpectedError = "InvalidNewName,Microsoft.PowerShell.Commands.RenameComputerCommand" }, - @{ OldName = ".\$#" ; NewName = "NewName"; ExpectedError = "AddressResolutionException,Microsoft.PowerShell.Commands.RenameComputerCommand" } - - It "Renaming '' to '' creates the right error" -testcase $testcases { - param ( $OldName, $NewName, $ExpectedError ) - Set-TesthookResult -testhookName $RenameResultName -value 0x1 - { Rename-Computer -ComputerName $OldName -NewName $NewName -ErrorAction Stop } | ShouldBeErrorId $ExpectedError - } - } - } - -} -finally -{ - $PSDefaultParameterValues.Remove("it:skip") - Disable-Testhook -testhookName $RenameTestHook - Disable-Testhook -testhookName TestStopComputer - Set-TesthookResult -testhookName $RenameResultName -value 0 -} +$RenameTesthook = "TestRenameComputer" +$RenameResultName = "TestRenameComputerResults" +$DefaultResultValue = 0 + +try +{ + # set up for testing + $PSDefaultParameterValues["it:skip"] = ! $IsWindows + Enable-Testhook -testhookName $RenameTesthook + # we also set TestStopComputer + Enable-Testhook -testhookName TestStopComputer + + # TEST START HERE + Describe "Rename-Computer" -Tag Feature { + # if we throw in BeforeEach, the test will fail and the stop will not be called + BeforeEach { + if ( ! (Test-TesthookIsSet -testhookName $RenameTesthook) ) { + throw "Testhook '${TesthookName}' is not set" + } + } + + AfterEach { + Set-TesthookResult -testhookName $RenameResultName -value $defaultResultValue + } + + It "Should rename the local computer" { + Set-TesthookResult -testhookName $RenameResultName -value $defaultResultValue + $newname = "mynewname" + $result = Rename-Computer -ErrorAction Stop -ComputerName . -NewName "$newname" -Pass -WarningAction SilentlyContinue + $result.HasSucceeded | should be $true + $result.NewComputerName | should be $newname + } + + # we can't really look for the string "reboot" as it will change + # when translated. We are guaranteed that the old computer name will + # be present, so we'll look for that + It "Should produce a reboot warning when renaming computer" { + Set-TesthookResult -testhookName $RenameResultName -value $defaultResultValue + $newname = "mynewname" + $result = Rename-Computer -ErrorAction Stop -ComputerName . -NewName "$newname" -Pass -WarningAction SilentlyContinue -WarningVariable WarnVar + $WarnVar.Message | should match $result.OldComputerName + } + + It "Should not produce a reboot warning when renaming a computer with the reboot flag" { + Set-TesthookResult -testhookName $RenameResultName -value $defaultResultValue + $newname = "mynewname" + $result = Rename-Computer -ErrorAction Stop -ComputerName . -NewName "$newname" -Pass -WarningAction SilentlyContinue -WarningVariable WarnVar -Restart + $result.HasSucceeded | should be $true + $result.NewComputerName | should be $newname + $WarnVar | should BeNullOrEmpty + } + + + Context "Rename-Computer Error Conditions" { + $testcases = + @{ OldName = "." ; NewName = "localhost" ; ExpectedError = "FailToRenameComputer,Microsoft.PowerShell.Commands.RenameComputerCommand" }, + @{ OldName = "." ; NewName = "." ; ExpectedError = "InvalidNewName,Microsoft.PowerShell.Commands.RenameComputerCommand" }, + @{ OldName = "." ; NewName = "::1" ; ExpectedError = "InvalidNewName,Microsoft.PowerShell.Commands.RenameComputerCommand" }, + @{ OldName = "." ; NewName = "127.0.0.1" ; ExpectedError = "InvalidNewName,Microsoft.PowerShell.Commands.RenameComputerCommand" }, + @{ OldName = "." ; NewName = ${env:ComputerName} ; ExpectedError = "NewNameIsOldName,Microsoft.PowerShell.Commands.RenameComputerCommand" }, + @{ OldName = "." ; NewName = ${env:ComputerName} + "." + ${env:USERDNSDOMAIN} ; ExpectedError = "InvalidNewName,Microsoft.PowerShell.Commands.RenameComputerCommand" }, + @{ OldName = ".\$#" ; NewName = "NewName"; ExpectedError = "AddressResolutionException,Microsoft.PowerShell.Commands.RenameComputerCommand" } + + It "Renaming '' to '' creates the right error" -testcase $testcases { + param ( $OldName, $NewName, $ExpectedError ) + Set-TesthookResult -testhookName $RenameResultName -value 0x1 + { Rename-Computer -ComputerName $OldName -NewName $NewName -ErrorAction Stop } | ShouldBeErrorId $ExpectedError + } + } + } + +} +finally +{ + $PSDefaultParameterValues.Remove("it:skip") + Disable-Testhook -testhookName $RenameTestHook + Disable-Testhook -testhookName TestStopComputer + Set-TesthookResult -testhookName $RenameResultName -value 0 +}