-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Set-Service and New-Service test coverage #4785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| @@ -0,0 +1,163 @@ | |||
| Describe "Set/New-Service cmdlet tests" -Tags "Feature","RequireAdminOnWindows" { | |||
| BeforeAll { | |||
| $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is indentation in the file? 2 or 4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be due to VSCode. Let me check my editor settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reformatted the whole file so it should at least be consistent
iSazonov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with one minor comment.
|
|
||
| It "Set-Service parameter validation for invalid values: <script>" -TestCases @( | ||
| @{script = {Set-Service foo -StartupType bar}; | ||
| errorid = "CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.SetServiceCommand" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix, I see another issue lower that I'll fix as well
|
@SteveL-MSFT Is the PR ready to merge or we should wait? |
|
@iSazonov let's merge this and move onto another PR. Thanks! |
iSazonov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave a comment
| ) { | ||
| param($name, $parameter, $value) | ||
| $parameters = @{$parameter = $value; Name = $name; Binary = "$PSHOME\powershell.exe"; ErrorAction = "Stop"} | ||
| { New-Service @parameters } | ShouldBeErrorId "CouldNotNewService,Microsoft.PowerShell.Commands.NewServiceCommand" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SteveL-MSFT We skipped -ErrorAction Stop 😕 #4800
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iSazonov it's there in the @parameter hash literal. The porblem is with the TestCase
@{name = 'badstarttype'; parameter = "StartupType"; value = "System"}
-------------------------------------------------------------^
System is actually valid for StartupType so that would not result in a Throw. I'm not sure if this is a faulty TestCase or if there is something wrong with New-Service
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The New-Service code doesn't allow System.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll submit a PR soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that's the case, then there is a bug in New-Service that is not throwing CouldNotNewService,Microsoft.PowerShell.Commands.NewServiceCommand when System is provided.
https://ci.appveyor.com/project/PowerShell/powershell/build/6.0.0-beta.6-5148/tests
Running
New-Service -StartupType System -Name badstarttype -BinaryPathName "$PSHOME\powershell.exe" -ErrorAction StopYields this for me
FailFast: bad StartupType
at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
at System.Management.Automation.Diagnostics.Assert(Boolean condition, String whyThisShouldNeverHappen, String detailMessage) in C:\github\PowerShell\src\System.Management.Automation\utils\assert.cs:line 196
at System.Management.Automation.Diagnostics.Assert(Boolean condition, String whyThisShouldNeverHappen) in C:\github\PowerShell\src\System.Management.Automation\utils\assert.cs:line 131
at Microsoft.PowerShell.Commands.NewServiceCommand.BeginProcessing() in C:\github\PowerShell\src\Microsoft.PowerShell.Commands.Management\commands\management\Service.cs:line 2018
at System.Management.Automation.Cmdlet.DoBeginProcessing() in C:\github\PowerShell\src\System.Management.Automation\engine\cmdlet.cs:line 164
at System.Management.Automation.CommandProcessorBase.DoBegin() in C:\github\PowerShell\src\System.Management.Automation\engine\CommandProcessorBase.cs:line 500
at System.Management.Automation.CommandProcessor.DoBegin() in C:\github\PowerShell\src\System.Management.Automation\engine\CommandProcessor.cs:line 272
at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream) in C:\github\PowerShell\src\System.Management.Automation\engine\pipeline.cs:line 1050
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input) in C:\github\PowerShell\src\System.Management.Automation\engine\pipeline.cs:line 489
at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext) in C:\github\PowerShell\src\System.Management.Automation\engine\runtime\Operations\MiscOps.cs:line 455
at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame) in C:\github\PowerShell\src\System.Management.Automation\engine\interpreter\CallInstruction.Generated.cs:line 569
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in C:\github\PowerShell\src\System.Management.Automation\engine\interpreter\ControlFlowInstructions.cs:line 356
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in C:\github\PowerShell\src\System.Management.Automation\engine\interpreter\ControlFlowInstructions.cs:line 356
at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame) in C:\github\PowerShell\src\System.Management.Automation\engine\interpreter\Interpreter.cs:line 111
at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0) in C:\github\PowerShell\src\System.Management.Automation\engine\interpreter\LightLambda.Generated.cs:line 78
at System.Management.Automation.DlrScriptCommandProcessor.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess) in C:\github\PowerShell\src\System.Management.Automation\engine\ScriptCommandProcessor.cs:line 516
at System.Management.Automation.DlrScriptCommandProcessor.Complete() in C:\github\PowerShell\src\System.Management.Automation\engine\ScriptCommandProcessor.cs:line 417
at System.Management.Automation.CommandProcessorBase.DoComplete() in C:\github\PowerShell\src\System.Management.Automation\engine\CommandProcessorBase.cs:line 614
at System.Management.Automation.Internal.PipelineProcessor.DoCompleteCore(CommandProcessorBase commandRequestingUpstreamCommandsToStop) in C:\github\PowerShell\src\System.Management.Automation\engine\pipeline.cs:line 607
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input) in C:\github\PowerShell\src\System.Management.Automation\engine\pipeline.cs:line 519
at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper() in C:\github\PowerShell\src\System.Management.Automation\engine\hostifaces\LocalPipeline.cs:line 426
at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc() in C:\github\PowerShell\src\System.Management.Automation\engine\hostifaces\LocalPipeline.cs:line 622
at System.Threading.Thread.ThreadMain_ThreadStart()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Environment.FailFast(System.String, System.Exception)
at System.Management.Automation.Diagnostics.Assert(Boolean, System.String, System.String)
at System.Management.Automation.Diagnostics.Assert(Boolean, System.String)
at Microsoft.PowerShell.Commands.NewServiceCommand.BeginProcessing()
at System.Management.Automation.Cmdlet.DoBeginProcessing()
at System.Management.Automation.CommandProcessorBase.DoBegin()
at System.Management.Automation.CommandProcessor.DoBegin()
at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean)
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(System.Object)
at System.Management.Automation.PipelineOps.InvokePipeline(System.Object, Boolean, System.Management.Automation.CommandParameterInternal[][], System.Management.Automation.Language.CommandBaseAst[], System.Management.Automation.CommandRedirection[][], System.Management.Automation.Language.FunctionContext)
at System.Management.Automation.Interpreter.ActionCallInstruction`6[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Run(System.Management.Automation.Interpreter.InterpretedFrame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(System.Management.Automation.Interpreter.InterpretedFrame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(System.Management.Automation.Interpreter.InterpretedFrame)
at System.Management.Automation.Interpreter.Interpreter.Run(System.Management.Automation.Interpreter.InterpretedFrame)
at System.Management.Automation.Interpreter.LightLambda.RunVoid1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon)
at System.Management.Automation.DlrScriptCommandProcessor.RunClause(System.Action`1<System.Management.Automation.Language.FunctionContext>, System.Object, System.Object)
at System.Management.Automation.DlrScriptCommandProcessor.Complete()
at System.Management.Automation.CommandProcessorBase.DoComplete()
at System.Management.Automation.Internal.PipelineProcessor.DoCompleteCore(System.Management.Automation.CommandProcessorBase)
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(System.Object)
at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()
at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()
at System.Threading.Thread.ThreadMain_ThreadStart()
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
and then crashes PowerShell.
If I build for Release, it creates the service with Automatic StartType.
So.. successful test! It's failing because there is a bug in New-Service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't repro locally for me on WS2016. AppVeyor is using WS2012R2, will need to investigate this later. Leaving for a flight to Open Source Summit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@markekraus can you open an issue? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SteveL-MSFT Have fun! Issue #4803 created
| @{parameter = "Status" ; value = "Running"}, | ||
| @{parameter = "Status" ; value = "Stopped"}, | ||
| @{parameter = "Status" ; value = "Paused"}, | ||
| @{parameter = "InputObject" ; value = (Get-Service | Select-Object -First 1)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is failed on Unix #4800
We should move (Get-Service | Select-Object -First 1) to BeforeAll.
Last part of #4147