FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix wrong output for `New-Service` in variable assignment and `-OutVariable` by kvprasoon · Pull Request #10444 · PowerShell/PowerShell · GitHub

Fix wrong output for New-Service in variable assignment and -OutVariable - #10444

Merged
Aditya Patwardhan (adityapatwardhan) merged 9 commits into
PowerShell:masterfrom
kvprasoon:new-srv-bug
Sep 3, 2019
Merged

Fix wrong output for New-Service in variable assignment and -OutVariable#10444
Aditya Patwardhan (adityapatwardhan) merged 9 commits into
PowerShell:masterfrom
kvprasoon:new-srv-bug

Conversation

PRASOON KARUNAN V (kvprasoon) commented Aug 25, 2019
edited
Loading

Copy link
Copy Markdown
Contributor

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

PR Checklist

PRASOON KARUNAN V (kvprasoon) commented Aug 25, 2019
edited
Loading

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor Author

CI failure seems to be something different.

Copy link
Copy Markdown
Collaborator

PRASOON KARUNAN V (@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.

Copy link
Copy Markdown
Contributor

PRASOON KARUNAN V (@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.

Copy link
Copy Markdown
Contributor Author

Kirk Munro (@KirkMunro) Rain Sallow (/u/ta11ow) (@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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

There is absolutely nothing wrong with using a subexpression here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

PRASOON KARUNAN V (kvprasoon) Aug 26, 2019
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Kirk Munro (KirkMunro) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

Aditya Patwardhan (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
Aditya Patwardhan (adityapatwardhan) merged commit f687702 into PowerShell:master Sep 3, 2019
Travis Plunk (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
Travis Plunk (TravisEz13) pushed a commit to TravisEz13/PowerShell that referenced this pull request Sep 14, 2019

Copy link
Copy Markdown

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

Handy links:

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj/PowerShell that referenced this pull request Aug 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL