8000 Fix wrong output for `New-Service` in variable assignment and `-OutVariable` by kvprasoon · Pull Request #10444 · PowerShell/PowerShell · GitHub 8000
[go: up one dir, main page]

Skip to content

Conversation

@kvprasoon
Copy link
Contributor
@kvprasoon kvprasoon commented Aug 25, 2019

New-Service cmdlet's output doesn't have all properties when assigned to a variable or using -OutVariable.

PR Checklist

@kvprasoon
Copy link
Contributor Author
kvprasoon commented Aug 25, 2019

Disclaimer: Novice in c# and really don't know the impact of the change, the code change was by referring similar usage in the same file.

@kvprasoon
Copy link
Contributor Author

CI failure seems to be something different.

@vexx32
Copy link
Collaborator
vexx32 commented Aug 25, 2019

@kvprasoon you might need to look at how the test is constructed. If the test is expecting the object to be disposed, it might explain why the tests are erroring out.

@KirkMunro
Copy link
Contributor

@kvprasoon Of the three errors, I think the last failure may be expected based on how your test is written.

When you create a new service with a $null display name, the display name gets assigned the value in the name field. If you look at the error output, it indicates you're checking if the display name is $null and that fails because the actual value of the display name is the service name value. You'll have to update your Pester test for display name to ensure that it checks against the value of the name property if the display name is $null.

For the first two errors, they indicate that the display name is null when it is not. I wonder if there is a timing issue (i.e. I wonder if the service display name property value does not show up immediately after creating the service). You should try creating some services outside of Pester, show their properties when the new service objects come back, then invoke Get-Service to get the services, and see if the properties are set the way you expect as well. Plus, experiment with timing of those a bit.

@kvprasoon
Copy link
Contributor Author

@KirkMunro @vexx32 , My earlier comment was for the previous commit, for latest one (not current), the output doesn't contain description and the StartupType in output is StartType, corrected it.


if ($displayname) {
$service.displayname | Should -Be $displayname
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than make this check conditional such that it only runs some of the time, how about just making it check for the appropriate value and having it run all the time?

$service.displayname | Should -Be $(if ($displayname) {$displayname} else {$name})

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the idea, but not really a fan of that particular syntax.

Maybe:

$testvalue = if ($DisplayName) { $displayname } else { $name }
$service.Displayname | should -BeExactly $testvalue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is absolutely nothing wrong with using a subexpression here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't say it was wrong, just overly long and complicated for a single line. 🙂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't disagree more, and the suggestion that the proposed line was "overly long and complicated" is misinformation.

With a condition as simple as this one, it is far better to keep the code focused on the tests being executed by having the condition inline than have more code to look over and more variables to think about.

As an added bonus, once we get a null-coalescing operator, inline code such as what was proposed becomes much, much simpler.

Copy link
Contributor Author
@kvprasoon kvprasoon Aug 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than make this check conditional such that it only runs some of the time, how about just making it check for the appropriate value and having it run all the time?

$service.displayname | Should -Be $(if ($displayname) {$displayname} else {$name})

This will implicitly add the check, if DisplayName is null, then ServiceName becomes DisplayName

Copy link
Contributor
@KirkMunro KirkMunro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adityapatwardhan adityapatwardhan changed the title Fix: Wrong output for New-Service in variable assignment and -OutVariable Fix wrong output for New-Service in variable assignment and -OutVariable Sep 3, 2019
@adityapatwardhan adityapatwardhan merged commit f687702 into PowerShell:master Sep 3, 2019
@kvprasoon kvprasoon deleted the new-srv-bug branch September 3, 2019 18:15
@TravisEz13 TravisEz13 added this to the 7.0.0-preview.4 milestone Sep 5, 2019
@TravisEz13 TravisEz13 added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Sep 5, 2019
TravisEz13 pushed a commit to TravisEz13/PowerShell that referenced this pull request Sep 14, 2019
@ghost
Copy link
ghost commented Sep 19, 2019

🎉v7.0.0-preview.4 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

0