-
Notifications
You must be signed in to change notification settings - Fork 54
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
xCluster: Refactored unit test #82
Conversation
@johlju, |
Codecov Report
@@ Coverage Diff @@
## dev #82 +/- ##
=================================
+ Coverage 57% 64% +7%
=================================
Files 6 6
Lines 293 292 -1
=================================
+ Hits 168 188 +20
+ Misses 125 104 -21 |
@bgelens or @RichardSiddaway Whenever you have a chance, could you review this one? 😄 |
@bgelens if possible, could you fit this one into your schedule? Back at it now, can fix any review comments you find! 😄 |
Excuse all the nitpicking 😉 I've maybe overdone it for this PR a bit but I thought it would be best to map all the obvious shortcomings straight away Reviewed 8 of 8 files at r1. .markdownlint.json, line 2 at r1 (raw file):
Not sure about this... E.g. I don't use this extension. I'd like your opinion @PlagueHO should we / shouldn't we do stuff like this besides the formatting rules for the ps ext? CHANGELOG.md, line 60 at r1 (raw file):
Is this the way to go instead of creating stubs in the tests themselves? DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 7 at r1 (raw file):
Should be comment based help with synopsis and parameters DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 14 at r1 (raw file):
Mandatory = $true (I'm not a fan of this one, but it's what needs to be done) DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 15 at r1 (raw file):
Parameter Names should be moved to newline DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 17 at r1 (raw file):
Mandatory = $true DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 18 at r1 (raw file):
Parameter Names should be moved to newline DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 20 at r1 (raw file):
Mandatory = $true DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 21 at r1 (raw file):
Parameter Names should be moved to newline DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 24 at r1 (raw file):
positional bindindg DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 25 at r1 (raw file):
$null should be on the left of the evaluation DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 27 at r1 (raw file):
Should output a descent constructed exception so it can be tested. (other modules make use of helper function to achieve this. See example at xHyper-V DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 36 at r1 (raw file):
Should output a descent constructed exception so it can be tested. (other modules make use of helper function to achieve this. See example at xHyper-V DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 39 at r1 (raw file):
Positional binding for Get-ClusterParameter. Should include the parameter instead DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 51 at r1 (raw file):
The use of the return keyword serves no purpose here and can be removed. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 53 at r1 (raw file):
Missing the DomainAdministratorCredential key. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 58 at r1 (raw file):
Should be comment based help with synopsis and parameters DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 64 at r1 (raw file):
Mandatory = $true DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 65 at r1 (raw file):
Parameter Names should be moved to newline DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 67 at r1 (raw file):
Mandatory = $true DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 68 at r1 (raw file):
Parameter Names should be moved to newline DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 70 at r1 (raw file):
Mandatory = $true DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 71 at r1 (raw file):
Parameter Names should be moved to newline DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 78 at r1 (raw file):
positional binding DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 81 at r1 (raw file):
Should output a descent constructed exception so it can be tested. (other modules make use of helper function to achieve this. See example at xHyper-V DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 110 at r1 (raw file):
Should output a descent constructed exception so it can be tested. (other modules make use of helper function to achieve this. See example at xHyper-V DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 117 at r1 (raw file):
Overall, should implement localization for messages. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 135 at r1 (raw file):
positional binding DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 154 at r1 (raw file):
should be comment based help DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 167 at r1 (raw file):
Mandatory = $true DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 168 at r1 (raw file):
Parameter Names should be moved to newline DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 170 at r1 (raw file):
Mandatory = $true DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 171 at r1 (raw file):
Parameter Names should be moved to newline DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 173 at r1 (raw file):
Mandatory = $true DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 174 at r1 (raw file):
Parameter Names should be moved to newline DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 181 at r1 (raw file):
positional binding DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 182 at r1 (raw file):
$null should be on the left DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 184 at r1 (raw file):
Should output a descent constructed exception so it can be tested. (other modules make use of helper function to achieve this. See example at xHyper-V Tests/Unit/MSFT_xCluster.Tests.ps1, line 16 at r1 (raw file):
TODO should be removed Tests/Unit/MSFT_xCluster.Tests.ps1, line 41 at r1 (raw file):
I would prefer ConvertTo-SecureString -String 'dummyPassw0rd' -AsPlainText -Force over using the pipeline Tests/Unit/MSFT_xCluster.Tests.ps1, line 42 at r1 (raw file):
positional binding Tests/Unit/MSFT_xCluster.Tests.ps1, line 131 at r1 (raw file):
the BeforeEach isn't necessary Tests/Unit/MSFT_xCluster.Tests.ps1, line 171 at r1 (raw file):
Not necessary Tests/Unit/MSFT_xCluster.Tests.ps1, line 243 at r1 (raw file):
Not necessary Tests/Unit/MSFT_xCluster.Tests.ps1, line 262 at r1 (raw file):
not necessary Tests/Unit/MSFT_xCluster.Tests.ps1, line 285 at r1 (raw file):
Still the case? Tests/Unit/MSFT_xCluster.Tests.ps1, line 314 at r1 (raw file):
Not necessary Tests/Unit/MSFT_xCluster.Tests.ps1, line 378 at r1 (raw file):
Not necessary Tests/Unit/Stubs/FailoverClusters.stubs.psm1, line 18 at r1 (raw file):
Should style guideline be applied to this file? In case not, I'm not evaluating it now 😄 Comments from Reviewable |
That was a good review! I was hoping to wait for the style changes for the next PR though 😉 I didn't want to make to many changes at once. 😄 I commented on some, and I will fix the rest of the review comments. My plan was this
Review status: all files reviewed at latest revision, 49 unresolved discussions, some commit checks failed. .markdownlint.json, line 2 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
This extension is the same that is used by the common test to test for lint errors. So my plan is that this one is here to help fixing lint errors before PR is sent in (if contributors is using VS Code, and the markdownlint extension). Though, I all for discussing if this should be a general thing (part of the formatting rules) or if it should not be in the repos at all. We have a discussion here as as well, that is somewhat connected to this; PowerShell/DscResource.Tests#98. But today I'm leaning towards have the rules in this file exactly as common test is testing them. In this issue I'm talking about "overrides" because of the big technical debt I had in xSQLServer. But the technical debt has since then been lowered significantly, so if a month or so I think we can do there what I'm trying to do here. :) CHANGELOG.md, line 60 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
I think this is better because the stub file is auto-generated, using the exact parameters. And the same stub can be reused and not duplicating code in several tests. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 27 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Could we fix this when we add localization? DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 36 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Could we fix this when we add localization? DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 51 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
I would rather use the return keyword to be clear that we are returning the hash table, that will also correlate with the OutputType. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 81 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Could we fix this when we add localization? DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 110 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Could we fix this when we add localization? DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 117 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Could we fix this when we add localization? DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 184 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Could we fix this when we add localization? Tests/Unit/MSFT_xCluster.Tests.ps1, line 131 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
It's necessary to use "dynamic mocks", setting a variable will change the mocks behaviour. For this to work the mock need to run before each It-block. So I rather use this logic throughout to be consequent. Tests/Unit/MSFT_xCluster.Tests.ps1, line 171 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
It's necessary to use "dynamic mocks", setting a variable will change the mocks behaviour. For this to work the mock need to run before each It-block. So I rather use this logic throughout to be consequent. Tests/Unit/MSFT_xCluster.Tests.ps1, line 243 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
It's necessary to use "dynamic mocks", setting a variable will change the mocks behaviour. For this to work the mock need to run before each It-block. So I rather use this logic throughout to be consequent. Tests/Unit/MSFT_xCluster.Tests.ps1, line 262 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
It's necessary to use "dynamic mocks", setting a variable will change the mocks behaviour. For this to work the mock need to run before each It-block. So I rather use this logic throughout to be consequent. Tests/Unit/MSFT_xCluster.Tests.ps1, line 285 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Yes, updated issue #79. I will fix this in a later PR (if someone else does not beat me to it). :) Tests/Unit/MSFT_xCluster.Tests.ps1, line 314 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
It's necessary to use "dynamic mocks", setting a variable will change the mocks behaviour. For this to work the mock need to run before each It-block. So I rather use this logic throughout to be consequent. Tests/Unit/MSFT_xCluster.Tests.ps1, line 378 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
It's necessary to use "dynamic mocks", setting a variable will change the mocks behaviour. For this to work the mock need to run before each It-block. So I rather use this logic throughout to be consequent. Tests/Unit/Stubs/FailoverClusters.stubs.psm1, line 18 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Nah, I think not. I don't think you should review this file since it generate dynamically from the script that is part of this PR. Comments from Reviewable |
Thanks for clarifying some of the points. I acknowledged everything that can be moved to later PRs as stated in your comment 😄 Review status: all files reviewed at latest revision, 35 unresolved discussions, some commit checks failed. .markdownlint.json, line 2 at r1 (raw file): Previously, johlju (Johan Ljunggren) wrote…
I started using the extension because of this and I must say, it's really helpful!
I'm still in doubt if we need to add these files to the repo's. It basically says we endorse (prefer) the use of vs code + extension x, y, z. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 51 at r1 (raw file): Previously, johlju (Johan Ljunggren) wrote…
Indeed personal. IMO If you want to be explicit about what is going on, it's better to use Still, one could argue for testing purposes it would be a good thing you can Assert that Write-Output is called (with return this is not possible I think). So yes, my preference is, use anything besides return unless return is used to influence the behavior of execution of code paths. Tests/Unit/MSFT_xCluster.Tests.ps1, line 131 at r1 (raw file): Previously, johlju (Johan Ljunggren) wrote…
OK. Makes sense. Thanks for clarifying 😄 Comments from Reviewable |
Review status: all files reviewed at latest revision, 34 unresolved discussions, some commit checks failed. .markdownlint.json, line 2 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
I added MD013 because that is disabled by default. I think the other are enable by default? I understand how you are thinking, and I agree in general, but I think this is a special case since we are using the same code in the common test as the vs-code extension is using. We essentially helping the user to get past the common tests by making sure the extension is configured correctly. Also. The issue below will enable the use of this file to override the behavior of the common test But I can remove it now and we can see if we need to add it in the future. 😄 Comments from Reviewable |
Review status: 5 of 9 files reviewed at latest revision, 34 unresolved discussions. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 7 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 14 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 15 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 17 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 18 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 20 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 21 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 24 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 25 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 39 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 51 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Good points! I'm agreeing with you. 😄. Removed. Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 53 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 58 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 64 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 65 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 67 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 68 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 70 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 71 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 78 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 135 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 154 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 167 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 168 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 170 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 171 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 173 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 174 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 181 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 182 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. Tests/Unit/MSFT_xCluster.Tests.ps1, line 16 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. Tests/Unit/MSFT_xCluster.Tests.ps1, line 41 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. Tests/Unit/MSFT_xCluster.Tests.ps1, line 42 at r1 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. .markdownlint.json, line 2 at r1 (raw file): Previously, johlju (Johan Ljunggren) wrote…
Done. Comments from Reviewable |
@bgelens Will I was in the progress of fixing style changes, I did a few more. 😄 |
Looking good! Just missing 1 decoration. Reviewed 5 of 5 files at r2. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 345 at r2 (raw file):
This param is mandatory. Should be decorated as such Comments from Reviewable |
- Added new stubs for FailoverClusters module (Tests\Unit\Stubs\FailoverClusters.stubs.psm1) to be able to run unit tests on a computer that does not have or can install Failover Clustering PowerShell module. - Added a script file (Tests\Unit\Stubs\Write-ModuleStubFile.ps1) to be able to rebuild the stub file (FailoverClusters.stubs.psm1) whenever needed. - Added settings file for VS Code extension markdownlint (.markdownlint.json). This will help keeping the line-length (MD013) in markdown file for contributors using VS Code.
- Refactored the unit test for this resource to use stubs and increase coverage (issue dsccommunity#73). - Removed the password file (MSFT_xCluster.password.txt) which seemed unnecessary. - Test-TargetResource now throws and error if domain name cannot be evaluated (issue dsccommunity#72). - Set-TargetResource now correctly throws and error if domain name cannot be evaluated (issue dsccommunity#71).
Review status: 7 of 9 files reviewed at latest revision, 1 unresolved discussion. DSCResources/MSFT_xCluster/MSFT_xCluster.psm1, line 345 at r2 (raw file): Previously, bgelens (Ben Gelens) wrote…
Done. Comments from Reviewable |
@bgelens Could you sing off on the last change when you got a chance, 😄 Thanks for reviewing!! |
Reviewed 1 of 1 files at r3, 1 of 1 files at r4. Comments from Reviewable |
When I was about to merge this one I saw that I missed removing .markdownlint.json from the CHANGELOG.md. I will merge this one as soon as the tests passes. Reviewed 4 of 8 files at r1, 3 of 5 files at r2, 1 of 1 files at r4, 1 of 1 files at r5. Comments from Reviewable |
Pull Request (PR) description
(Tests\Unit\Stubs\FailoverClusters.stubs.psm1) to be able to run unit tests
on a computer that does not have or can install Failover Clustering
PowerShell module.
to rebuild the stub file (FailoverClusters.stubs.psm1) whenever needed.
This will help keeping the line-length (MD013) in markdown file for contributors
using VS Code.
(issue xCluster: Unit tests does not use the correct template and folder structure is wrong #73).
(issue xCluster: Test-TargetResource never throws an error if domain name can't be evaluated #72).
evaluated (issue xCluster: Set-TargetResource never throws an error if domain name can't be evaluated #71).
This Pull Request (PR) fixes the following issues:
Fixes #73
Fixes #72
Fixes #71
Task list:
This change is