-
-
Notifications
You must be signed in to change notification settings - Fork 468
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
Unable to Mock New-SCPhysicalComputerConfig #1496
Comments
Thanks for reporting. Could you share the callstack of the error please? I don't have that cmdlet. |
I think this is it:
|
Hmm, okay which module is that coming from? Is that your module? Is it public somewhere so I can replicate? |
It's from VirtualMachineManager module. We are using SCVMM 2016. The cmdlet is New-SCPhysicalComputerConfig. And this what I'm trying to do:
And module I'm testing it's running the cmdlet with the following parameters:
I hope this helps and thanks for you help. |
I ran into an error similar to this, when trying to mock the I think the problem is that it is looking for a constructor for an enum used in an attribute on one of the parameters. Or something like that:
My version info:
I was able to work around it by using # Because Start-BitsTransfer is soooo slow, and we don't actually need to exercise it.
Mock Start-BitsTransfer -RemoveParameterValidation 'CertStoreLocation' {
Copy-Item $Source[0] $Destination[0]
} |
This is caused by the built-in proxy command generator doing it wrong. (We had few similar cases where it generates code that cannot be run, e.g. because it tries to re-define read-only variables.) In this instance it does not correctly define the enum values in the validation: $m = New-Object System.Management.Automation.CommandMetaData (Get-Command Start-BitsTransfer)
[System.Management.Automation.ProxyCommand]::Create($m)
....
[Parameter(ParameterSetName='NewFromParams')]
[ValidateRange(CurrentUser, LocalMachineEnterprise)]
[Microsoft.BackgroundIntelligentTransfer.Management.CertStoreLocationValue]
${CertStoreLocation}, This fails with the same error: function f {
param (
[ValidateRange(CurrentUser, LocalMachineEnterprise)]
[Microsoft.BackgroundIntelligentTransfer.Management.CertStoreLocationValue]
${CertStoreLocation}
)
}
f This passes: function f {
param (
[ValidateRange([Microsoft.BackgroundIntelligentTransfer.Management.CertStoreLocationValue]::CurrentUser, [Microsoft.BackgroundIntelligentTransfer.Management.CertStoreLocationValue]::LocalMachineEnterprise)]
[Microsoft.BackgroundIntelligentTransfer.Management.CertStoreLocationValue]
${CertStoreLocation}
)
}
f
function f {
param (
[ValidateRange('CurrentUser', 'LocalMachineEnterprise')]
[Microsoft.BackgroundIntelligentTransfer.Management.CertStoreLocationValue]
${CertStoreLocation}
)
}
f We need someone clever to rewrite the ast when the parameter is enum and the values are not quoted. |
@jazzdelightsme thanks for the repro. |
Thanks. I've reported the issue in the PowerShell-repo Update: Just to clarify, this will also be fixed in the next Pester-release (probably 5.4.0). See related PR. |
1. General summary of the issue
When trying to mock New-SCPhysicalComputerConfig I keep throwing the following error:
I've even tried to use real data on the parameters, to the point where the command works correctly and the object is created in SCVMM when not mocking it. But mocking with this real data I keep getting the above error.
2. Describe Your Environment
Pester version : 4.10.1 C:\Program Files\WindowsPowerShell\Modules\Pester\4.10.1\Pester.psd1
PowerShell version : 5.1.14393.3471
OS version : Microsoft Windows NT 10.0.14393.0
3. Expected Behavior
Mock should work
4.Current Behavior
Throws the following error:
The text was updated successfully, but these errors were encountered: