Compare commits
414 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a2d724a54c | |||
| f06157c75e | |||
| d413374c09 | |||
| 1513cd4f4b | |||
| 1daac508b2 | |||
| a22d9e3416 | |||
| 06e81b46d6 | |||
| af33715f02 | |||
| 912bca0f9c | |||
| 4ac951607b | |||
| d3d01f892f | |||
| 84b7922156 | |||
| 0eaf89608b | |||
| 50e03b36f5 | |||
| 4531d2d53b | |||
| e6e6be9ede | |||
| 5c2dd620d8 | |||
| a5a91febcf | |||
| bb5dbaa0d4 | |||
| e6b5777e64 | |||
| ddee165575 | |||
| f0279633dd | |||
| 139e52f3e2 | |||
| eea6e95988 | |||
| 0630cbb20e | |||
| 682750fc6d | |||
| 9dc9aa92d0 | |||
| 23e0b8a665 | |||
| ae53dcd4d2 | |||
| ced5671ab2 | |||
| cb528df3d4 | |||
| c91d53ecad | |||
| 8d8cb58558 | |||
| 2dad347544 | |||
| 6f798fd96a | |||
| 649e7413a7 | |||
| af6e81267b | |||
| b6d8083b69 | |||
| 9d4b4d3533 | |||
| 510f0b9ed7 | |||
| 9561936be7 | |||
| 961eafb945 | |||
| aa73534d7f | |||
| 56bbe59ea7 | |||
| 5f786775dc | |||
| 14ef5048e4 | |||
| d7e46bd263 | |||
| c64c82f8bc | |||
| a59feb2d5f | |||
| d9e1063654 | |||
| d9e6c74f27 | |||
| df82bc26ca | |||
| dbde9aa4c2 | |||
| 7dcb6539a5 | |||
| 3621ddef8d | |||
| 5b4a25b66d | |||
| 5a2c01341c | |||
| c477d40364 | |||
| 494c45b02c | |||
| 8318229cf4 | |||
| 7427ffe707 | |||
| 713c94461c | |||
| 0872f1a655 | |||
| a072905253 | |||
| 41fddf5f13 | |||
| 136d1b2c76 | |||
| a25bf3adfe | |||
| 93c55bdd07 | |||
| 5627992a04 | |||
| 7fc7edff86 | |||
| 6f1e582ceb | |||
| 0f1b4302bb | |||
| ea8d6f096d | |||
| ddae22fb9f | |||
| 6903ccc99b | |||
| 7ce6369ad7 | |||
| 2d453ef608 | |||
| 363b6e727c | |||
| f4c1cf630a | |||
| 348fcbd28c | |||
| 3000a2b013 | |||
| 52609bf64a | |||
| e021a7bab0 | |||
| c3ad8dd415 | |||
| f81a22ca80 | |||
| de1a85cecd | |||
| d3acba3967 | |||
| 512d5bbd74 | |||
| 9ad9cb7f1e | |||
| a55b0cd467 | |||
| aab22cf266 | |||
| 906d35186f | |||
| c7c3428dd5 | |||
| e90d2a23cc | |||
| 925ecaf224 | |||
| 32403ec3e3 | |||
| 73540faeb9 | |||
| 932262e33a | |||
| 1e84f5aea0 | |||
| 7befc7d21e | |||
| cdad0c5e79 | |||
| 291aae9dcd | |||
| f8f0d980d0 | |||
| b72099559c | |||
| 6046103da0 | |||
| cccd45b7fd | |||
| 77b7e1c376 | |||
| 8f735bee62 | |||
| de505debf9 | |||
| bc570e9005 | |||
| 804a60be77 | |||
| 1e678214b1 | |||
| ba0b12e83c | |||
| b33b07b524 | |||
| d4b4d1b4d7 | |||
| fbe3f4d031 | |||
| 26cfb832a4 | |||
| 865ca1dd39 | |||
| 2887f6d450 | |||
| 5613b97eef | |||
| 3a2e8f4ee7 | |||
| 380ac5c841 | |||
| c2a0ac9fa0 | |||
| ba2bed6b53 | |||
| 5ec0ddce62 | |||
| 83f00e00ee | |||
| 63a1ab928e | |||
| e6ead11891 | |||
| aecd4fd1d5 | |||
| 8dcee4068a | |||
| b0d68ea224 | |||
| 22b0da87b9 | |||
| fc3c08637b | |||
| 4894084292 | |||
| 781368398c | |||
| 4271afd5b4 | |||
| 6c2b029014 | |||
| e47458b2df | |||
| d38f206824 | |||
| ed6024fe63 | |||
| 8b213ede25 | |||
| 6620246e4c | |||
| 71610ce9fe | |||
| fb45693fb1 | |||
| 8578c775dd | |||
| b186c561e6 | |||
| ae6a80b48d | |||
| 9fafe4b58b | |||
| c1b7c490ff | |||
| 589a3b7d6e | |||
| 9913c96d65 | |||
| fe4d8cf4dd | |||
| e35939e592 | |||
| c422e26903 | |||
| e37444249e | |||
| 616cdcf7a2 | |||
| e7658fcfec | |||
| a306391a14 | |||
| 83e9551692 | |||
| 7fbc550390 | |||
| e3cba682c7 | |||
| 96b3e65be2 | |||
| d15111a883 | |||
| 90434b56a2 | |||
| 85e60adac1 | |||
| 0d6bc39c86 | |||
| ad2073f404 | |||
| e12bf9d85e | |||
| a5f3ad4de0 | |||
| 77fb3c8f67 | |||
| b2e5fe7b5c | |||
| f34f21bb85 | |||
| 536a62f792 | |||
| df83277c06 | |||
| d55bc3e4b3 | |||
| 7488e7999f | |||
| dcba2b04a9 | |||
| bd94bfe5db | |||
| fb722661a7 | |||
| 6121940563 | |||
| 64fa03e4ea | |||
| 86854442ef | |||
| bc46a512cd | |||
| 0a84246d8e | |||
| f299aecb9b | |||
| 646476e74e | |||
| 285a82f280 | |||
| fbe9fb2af8 | |||
| 1af70b8c80 | |||
| 0ef71c25bb | |||
| 78e1cdb981 | |||
| 1a66d4e64b | |||
| 2fef1dbc42 | |||
| b00ededc7f | |||
| 8e5ced9b87 | |||
| 69fb384c89 | |||
| a8b9ec3a00 | |||
| 355be7c1e5 | |||
| c94f04de77 | |||
| f4807f94fb | |||
| d39777cbb0 | |||
| 8b43856558 | |||
| 83879a51e7 | |||
| 2d1fb8e4db | |||
| e774cd861d | |||
| a660aa29b3 | |||
| 82458712f0 | |||
| bae9eb9b99 | |||
| 2ea7092b91 | |||
| de08f0eece | |||
| 3e980dc195 | |||
| eccc5f27f3 | |||
| e516a24e38 | |||
| 07f92583f8 | |||
| c2f554dca1 | |||
| 8bd865d83d | |||
| 02e50d9cd6 | |||
| 7fc0a5f579 | |||
| ce5a64c683 | |||
| 1317a6c039 | |||
| 169e628c7b | |||
| d35d9d7cf4 | |||
| a891a4914d | |||
| 71352cae7b | |||
| b0edd9026f | |||
| 7cde687d70 | |||
| 569d9e264c | |||
| 40331c26f9 | |||
| 526093afc6 | |||
| dc4dd1ad05 | |||
| 779ee1415e | |||
| 13592df6aa | |||
| fad3ca0e27 | |||
| 52782aa1e5 | |||
| bc02e796d6 | |||
| 4c32bbe057 | |||
| cc9e53ac44 | |||
| 37165e18a7 | |||
| 772848beef | |||
| 18185612bb | |||
| ecab2500c7 | |||
| fde7f67e45 | |||
| e19f9b34f5 | |||
| a36a7cb37a | |||
| 1e80bb06fb | |||
| 4c98b75134 | |||
| a7efc7c717 | |||
| 02f1c89d86 | |||
| 5b9243a02f | |||
| 1962dda15c | |||
| 801553178e | |||
| 6c92dff447 | |||
| 003396998c | |||
| 05783a1f37 | |||
| 270470f858 | |||
| 579ba7a063 | |||
| 2cb35165a9 | |||
| 82cf4cb732 | |||
| 9d21eb6409 | |||
| abadc86ae8 | |||
| f094263882 | |||
| c47614727a | |||
| 7cad7eaf75 | |||
| d6862f75d1 | |||
| 5b8a89e1a3 | |||
| d6562de9bf | |||
| cdae203993 | |||
| 213b6029e4 | |||
| 11ab03be0a | |||
| 5f978d7b1a | |||
| 5c76c4c58c | |||
| 8b3a3b3b0b | |||
| 63d56cf862 | |||
| 10785df8a9 | |||
| 8a1593ceba | |||
| 1ca3d6704b | |||
| b4a7df970c | |||
| 3d8acf03f6 | |||
| 07de073bf1 | |||
| 7641d28307 | |||
| 30422d0421 | |||
| 4a0885f731 | |||
| 28d66806a5 | |||
| 42b923cef5 | |||
| 5984bc93c9 | |||
| 528bc66bcd | |||
| e706470395 | |||
| 29a79bbb92 | |||
| f907acd14a | |||
| 90a17045af | |||
| e1ba8412ff | |||
| 0a90d51735 | |||
| 9d34086e40 | |||
| 842c7ceeec | |||
| d78fc28b1c | |||
| 28fb42d56a | |||
| 0657607f3a | |||
| 32f6a6eebc | |||
| 6cc2e8d61d | |||
| b9598e7e0b | |||
| a9ea273d55 | |||
| f5c81a0766 | |||
| 3a8e742aad | |||
| 7b07fb0fd7 | |||
| a4e3961bd7 | |||
| 551eac5d5a | |||
| 916fbb6c4c | |||
| 5c2e16d5c6 | |||
| 8b0def7c50 | |||
| 73884ef022 | |||
| fd1619351e | |||
| 4e7d30ef33 | |||
| 2769489939 | |||
| baf6aa50ee | |||
| c96836c000 | |||
| 51a1e0fb03 | |||
| c6b37c24a6 | |||
| 1d6c2289e8 | |||
| ad6b154d85 | |||
| 28fabd592c | |||
| e751202010 | |||
| b5a637fe60 | |||
| b294f3e6ad | |||
| 1be09bd734 | |||
| e07b99613e | |||
| 6a924067c9 | |||
| d2eddea4bc | |||
| 5e12656a4a | |||
| 96803e1ad5 | |||
| 79542e8f7f | |||
| c8da651200 | |||
| c578ec428e | |||
| 6bc6f902fd | |||
| fc3a2a0193 | |||
| aaa505c790 | |||
| 7fe361dba7 | |||
| 356572a1f8 | |||
| 878622d3e2 | |||
| c83462d03c | |||
| ba1e1c309e | |||
| 21bc81b0ec | |||
| 8267474d8a | |||
| fee7cd9723 | |||
| efea494475 | |||
| 9be00e68b1 | |||
| 928d6ef4a1 | |||
| e1720dd4f7 | |||
| 202c865fe8 | |||
| 6df14f7a8d | |||
| 5213614299 | |||
| a39f2638d1 | |||
| 37016076fd | |||
| c05a527982 | |||
| ff54a92f92 | |||
| b82912605e | |||
| 3e3a433843 | |||
| 047e701f55 | |||
| 6b1486b74d | |||
| 213329801a | |||
| 55fb683dc3 | |||
| 075a78436d | |||
| a6d81aca44 | |||
| 9f2a6c42cd | |||
| a78f827804 | |||
| a526045662 | |||
| 6a6b073ada | |||
| b11c497ead | |||
| 344e7836f9 | |||
| 1e64d9d7f3 | |||
| 9ab97f2786 | |||
| 997ab90035 | |||
| 86ac714c22 | |||
| 0c4643a76e | |||
| 1cfc07260f | |||
| 82dbe7ae48 | |||
| 670fbdbba8 | |||
| 2e6a37bd5f | |||
| 1c17ca3e96 | |||
| 6b05af2db4 | |||
| 40326da05f | |||
| db91acb770 | |||
| 562d1210e6 | |||
| d7ee3eab12 | |||
| 19b645bccc | |||
| e6c5effe7c | |||
| 235434fe20 | |||
| dd144d3c47 | |||
| 4fee466cc8 | |||
| f1afbe6748 | |||
| 5eae4857cf | |||
| e930f996d6 | |||
| 9a010244b4 | |||
| 7339366f7d | |||
| 7f5fb6c1ac | |||
| 46951b76ba | |||
| 06b6bb09d7 | |||
| ddb639ad6b | |||
| 4d7d1391ff | |||
| cb991b3d0c | |||
| 80c82b99e0 | |||
| 90cf88b5cb | |||
| ef1584032e | |||
| 1fd92008ac | |||
| 0a2e6974f0 | |||
| b2c3548d01 | |||
| 0b1f2c4d1b | |||
| b7d4664d6b | |||
| 44ed5767ea | |||
| 83649fb72a | |||
| 9d579a5785 | |||
| ad8f06c6e1 | |||
| 148b33c1e3 | |||
| a8025f4be1 | |||
| 9c16c2c6e2 |
@@ -0,0 +1,62 @@
|
||||
# How to contribute
|
||||
|
||||
Contributions to ZertoApiWrapper are highly encouraged and desired.
|
||||
Below are some guidelines that will help make the process as smooth as possible.
|
||||
|
||||
## Getting Started
|
||||
|
||||
- Make sure you have a [GitHub account](https://github.com/signup/free)
|
||||
- Submit a new issue, assuming one does not already exist.
|
||||
- Clearly describe the issue including steps to reproduce when it is a bug.
|
||||
- Make sure you fill in the earliest version that you know has the issue.
|
||||
- Fork the repository on GitHub
|
||||
|
||||
## Suggesting Enhancements
|
||||
|
||||
I want to know what you think is missing from ZertoApiWrapper and how it can be made better.
|
||||
|
||||
- When submitting an issue for an enhancement, please be as clear as possible about why you think the enhancement is needed and what the benefit of it would be.
|
||||
|
||||
## Making Changes
|
||||
|
||||
- From your fork of the repository, create a topic branch where work on your change will take place.
|
||||
- To quickly create a topic branch based on master; `git checkout -b my_contribution master`.
|
||||
Please avoid working directly on the `master` branch.
|
||||
- Make commits of logical units.
|
||||
- Check for unnecessary whitespace with `git diff --check` before committing.
|
||||
- Please follow the prevailing code conventions in the repository.
|
||||
Differences in style make the code harder to understand for everyone.
|
||||
- Make sure your commit messages are in the proper format.
|
||||
|
||||
```
|
||||
Add more cowbell to Get-Something.ps1
|
||||
|
||||
The functionality of Get-Something would be greatly improved if there was a little
|
||||
more 'pizzazz' added to it. I propose a cowbell. Adding more cowbell has been
|
||||
shown in studies to both increase one's mojo, and cement one's status
|
||||
as a rock legend.
|
||||
```
|
||||
|
||||
- Make sure you have added all the necessary Pester tests for your changes.
|
||||
- Run _all_ Pester tests in the module to assure nothing else was accidentally broken.
|
||||
|
||||
## Documentation
|
||||
|
||||
I am infallible and as such my documenation needs no corectoin.
|
||||
In the highly unlikely event that that is _not_ the case, commits to update or add documentation are highly apprecaited.
|
||||
|
||||
## Submitting Changes
|
||||
|
||||
- Push your changes to a topic branch in your fork of the repository.
|
||||
- Submit a pull request to the main repository.
|
||||
- Once the pull request has been reviewed and accepted, it will be merged with the master branch.
|
||||
- Celebrate
|
||||
|
||||
## Additional Resources
|
||||
|
||||
- [General GitHub documentation](https://help.github.com/)
|
||||
- [GitHub forking documentation](https://guides.github.com/activities/forking/)
|
||||
- [GitHub pull request documentation](https://help.github.com/send-pull-requests/)
|
||||
- [GitHub Flow guide](https://guides.github.com/introduction/flow/)
|
||||
- [GitHub's guide to contributing to open source projects](https://guides.github.com/activities/contributing-to-open-source/)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<!--- Provide a general summary of the issue in the Title above -->
|
||||
|
||||
## Expected Behavior
|
||||
<!--- If you're describing a bug, tell us what should happen -->
|
||||
<!--- If you're suggesting a change/improvement, tell us how it should work -->
|
||||
|
||||
## Current Behavior
|
||||
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
|
||||
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
|
||||
|
||||
## Possible Solution
|
||||
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
|
||||
<!--- or ideas how to implement the addition or change -->
|
||||
|
||||
## Steps to Reproduce (for bugs)
|
||||
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
|
||||
<!--- reproduce this bug. Include code to reproduce, if relevant -->
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
4.
|
||||
|
||||
## Context
|
||||
<!--- How has this issue affected you? What are you trying to accomplish? -->
|
||||
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
|
||||
|
||||
## Your Environment
|
||||
<!--- Include as many relevant details about the environment you experienced the bug in -->
|
||||
* Module version used:
|
||||
* Operating System and PowerShell version:
|
||||
* Zerto Virtual Manager Version:
|
||||
@@ -0,0 +1,37 @@
|
||||
<!--- Provide a general summary of your changes in the Title above -->
|
||||
|
||||
## Description
|
||||
<!--- Describe your changes in detail -->
|
||||
|
||||
## Related Issue
|
||||
<!--- This project only accepts pull requests related to open issues -->
|
||||
<!--- If suggesting a new feature or change, please discuss it in an issue first -->
|
||||
<!--- If fixing a bug, there should be an issue describing it with steps to reproduce -->
|
||||
<!--- Please link to the issue here: -->
|
||||
|
||||
## Motivation and Context
|
||||
<!--- Why is this change required? What problem does it solve? -->
|
||||
|
||||
## How Has This Been Tested?
|
||||
<!--- Please describe in detail how you tested your changes. -->
|
||||
<!--- Include details of your testing environment, and the tests you ran to -->
|
||||
<!--- see how your change affects other areas of the code, etc. -->
|
||||
|
||||
## Screenshots (if appropriate):
|
||||
|
||||
## Types of changes
|
||||
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
|
||||
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] New feature (non-breaking change which adds functionality)
|
||||
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
|
||||
|
||||
## Checklist:
|
||||
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
|
||||
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
|
||||
- [ ] My code follows the code style of this project.
|
||||
- [ ] My change requires a change to the documentation.
|
||||
- [ ] I have updated the documentation accordingly.
|
||||
- [ ] I have read the **CONTRIBUTING** document.
|
||||
- [ ] I have added tests to cover my changes.
|
||||
- [ ] All new and existing tests passed.
|
||||
|
||||
+4
-2
@@ -1,7 +1,9 @@
|
||||
|
||||
*.zip
|
||||
temp/*
|
||||
Tests/Public/TestResults.xml
|
||||
Tests/TestResults.xml
|
||||
BuiltTestResults.xml
|
||||
SourceTestResults.xml
|
||||
publish/*
|
||||
CodeCoverage.xml
|
||||
scratch
|
||||
.DS_Store
|
||||
|
||||
Vendored
+6
-1
@@ -1,4 +1,9 @@
|
||||
{
|
||||
"files.trimTrailingWhitespace": true,
|
||||
"terminal.integrated.shell.windows": "c:/Program Files/PowerShell/6/pwsh.exe"
|
||||
"files.insertFinalNewline": true,
|
||||
"editor.insertSpaces": true,
|
||||
"editor.tabSize": 4,
|
||||
"powershell.codeFormatting.preset": "OTBS",
|
||||
"terminal.integrated.shell.windows": "c:/Program Files/PowerShell/7/pwsh.exe",
|
||||
"powershell.codeFormatting.addWhitespaceAroundPipe": true
|
||||
}
|
||||
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project is transitioning to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [1.5.3]
|
||||
|
||||
### Zerto Virtual Manager
|
||||
|
||||
#### Fixed
|
||||
|
||||
* Fixed an [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/112) where `New-ZertoVpg` would fail when specifying the local site as the target site.
|
||||
* Updated the method where a Site Identifer is obtained during the `New-ZertoVpg` execution that would occasionally fail on some versions of PowerShell.
|
||||
|
||||
#### Updated
|
||||
|
||||
* Updated `New-ZertoVpg` function [help documentation](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/New-ZertoVpg.md) to more clearly specify the return value and the requirement to pass it into the `Save-ZertoVpgSetting` function to commit the VPG.
|
||||
|
||||
## [1.5.2]
|
||||
|
||||
### Zerto Virtual Manager
|
||||
|
||||
#### Fixed
|
||||
|
||||
* Fixed an issue when attempting to export more than 100 VPGs with the `Export-ZertoVpg` function that would cause an error.
|
||||
|
||||
## [1.5.1]
|
||||
|
||||
### Zerto Virtual Manager
|
||||
|
||||
#### Fixed
|
||||
|
||||
* Fixed an [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/108) with `New-ZertoVpg` where when specifying a single host as a recovery target, the host identifier was not properly assigned. - Thanks @jonsouzerto!
|
||||
* Fixed an [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/86) with `Invoke-ZertoMoveVpg` where parameters should have been mandatory in certain workflows. - Thanks @gdbarron!
|
||||
|
||||
## [1.5.0]
|
||||
|
||||
### Zerto Virtual Manager
|
||||
|
||||
#### New
|
||||
|
||||
* Added `Add-ZertoVpgVm` function to the module. Read the [help file](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Add-ZertoVpgVm.md) for more information.
|
||||
* Added `Remove-ZertoVpgVm` function to the module. Read the [help file](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Remove-ZertoVpgVm.md) for more information.
|
||||
|
||||
#### Fixed
|
||||
|
||||
* Fixed an [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/103) with `Add-ZertoPeerSite` where there was an incorrect settings validator on the `-targetHost` parameter where it would not accept a hostname.
|
||||
|
||||
## [1.4.3]
|
||||
|
||||
### Zerto Virtual Manager
|
||||
|
||||
#### Updated
|
||||
|
||||
* Updated `Connect-ZertoServer` with a `-AutoReconnect` switch to allow the auto reconnection of a session that has timed-out.
|
||||
* Updated `New-ZertoVpg` to have a Default Parameter Set of `recoveryHostDatastore` should no parameters be passed when calling the function.
|
||||
* Updated `New-ZertoVpg -recoverySite` parameter to be case-insensitive
|
||||
|
||||
#### Fixed
|
||||
|
||||
* Fixed an [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/96) with `Set-ZertoLicense` so that ShouldProcess functions properly.
|
||||
* Fixed an [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/95) when attempting to connect to an unlicensed site.
|
||||
|
||||
## [1.4.2]
|
||||
|
||||
### Zerto Virtual Manager
|
||||
|
||||
#### Fixed
|
||||
|
||||
* Updated `Get-ZertoEvent` to translate a vpg name parameter to a vpgIdentifier per the API documentation
|
||||
* Updated `Invoke-ZertoMoveCommit` to ensure that when one of the parameter switches is defined, all required parameters are sent to avoid conflicts with parameters passed with the `Invoke-ZertoMove` command.
|
||||
* Updated `Start-ZertoCloneVpg` to fix an issue where an error would be thrown if an operation specified a subset of VMs to be cloned.
|
||||
|
||||
## [1.4.1]
|
||||
|
||||
### General
|
||||
|
||||
* Removed RELEASENOTES and converted to a CHANGELOG format.
|
||||
* Updated the build process to follow Semantic Versioning.
|
||||
* Updated the build process to use the latest Pester Version (4.10.1)
|
||||
* Updated the build process to use the latest PS Script Analyzer Version (1.19.0)
|
||||
* Updated the Tests Files to use a more modern method of grabbing the PSScriptPath
|
||||
|
||||
### Zerto Virtual Manager
|
||||
|
||||
* Refactored `Copy-ZertoVpg` functionality to leverage identifier and name maps and eliminate `where-object` searches.
|
||||
* Updated `Get-ZertoEvent` parameter to fall in line with the filter parameter name in the API documentation. Moved the old parameter name to an alias to ensure that existing functionality continues to work.
|
||||
|
||||
## [1.4.0.20200410]
|
||||
|
||||
### Zerto Virtual Manager
|
||||
|
||||
* Addressed a reported [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/60) in the `Get-ZertoRecoveryReport` function where the `-VpgIdentifier` parameter was not working. This parameter is not accepted by the API as a valid filter and is ignored. This parameter has been removed from the function.
|
||||
* Addressed a reported [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/61) where the `Export-ZertoVpgNicSetting` function would not properly execute when run against a VM with no NICs attached.
|
||||
* In reviewing the `Export-ZertoVpgNicSetting`, a review of the `Import-ZertoVpgNicSetting` was completed and it was determined to update the import logic based on various test cases. Along with this, it is now possible to reset the NIC settings to the default state with the `Import-ZertoVpgNicSetting` command. Please review the [Import-ZertoVpgNicSetting help](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Import-ZertoVmNicSetting.md) to review the updated options and import logic.
|
||||
* Refactored the `Checkpoint-ZertoVpg` command to allow pipeline input (ByValue and ByProperty) for the VpgName parameter.
|
||||
* Corrected a parameter typo in the `Get-ZertoVpgSetting` function. The misspelt parameter was added as an alias to ensure any existing scripts using the parameter continue to function.
|
||||
* Refactored the `Get-ZertoVpg` command to remove repetitive commands and variables that are no longer required.
|
||||
* Moved `Invoke-ZertoRestRequest` and `Invoke-ZARestRequest` to be public functions. As there become more and more scenarios where there are not prebuilt functions to accomplish complex specialized tasks, it became apparent that these functions could be leveraged to make the experience and workflow easier.
|
||||
* Updated the `Install-ZertoVra` logic to ensure that the target datastore is available on the target host. There isn't currently any method to validate the target network, but if that becomes available in a later version of the API, the function will be updated.
|
||||
* Updated the `Install-ZertoVra` function to allow for installation of the VRA using the host password method. Please review the [Install-ZertoVra](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Install-ZertoVra.md) documentation for syntax and examples.
|
||||
* Updated the `Edit-ZertoVra` function to allow for modification of the associated ESX host password if the need arises. Please review the [Edit-ZertoVra](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Edit-ZertoVra.md) documentation for syntax and examples.
|
||||
* Added a new function, `Set-ZertoUserCredential`, to allow the updating of the username and password used to connect the Zerto Virtual Manager to the paired hypervisor. Please see the [Set-ZertoUserCredential](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Set-ZertoUserCredential.md) help for additional information.
|
||||
* With the release of [Zerto 8.0](https://www.zerto.com/zerto-8-0-general-availability/) some additional API endpoints have become available.
|
||||
* Updated `Get-ZertoVirtualizationSite` to add the `-repository` parameter to enable returning information for LTR repositories.
|
||||
* Updated `Get-ZertoVpgSetting` to add the `-ltr` parameter to enable returning information for current LTR settings for the selected VPG.
|
||||
|
||||
### Zerto Analytics
|
||||
|
||||
* Added several functions for the newly added [Zerto Analytics](https://analytics.zerto.com) Planner.
|
||||
* `Get-ZAPlannerSite` Help can be found here: [Get-ZAPlannerSite](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Get-ZAPlannerSite.md)
|
||||
* `Get-ZAPlannerStatsReport` Help can be found here: [Get-ZAPlannerStatsReport](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Get-ZAPlannerStatsReport.md)
|
||||
* `Get-ZAPlannerJournalSizeReport` Help can be found here: [Get-ZAPlannerJournalSizeReport](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Get-ZAPlannerJournalSizeReport.md)
|
||||
* `Get-ZAPlannerNetworkPerformanceReport` Help can be found here: [Get-ZAPlannerNetworkPerformanceReport](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Get-ZAPlannerNetworkPerformanceReport.md)
|
||||
* `Get-ZAPlannerWanReport` Help can be found here: [Get-ZAPlannerWanReport](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Get-ZAPlannerWanReport.md)
|
||||
* `Get-ZAPlannerZcasReport` Help can be found here: [Get-ZAPlannerZcasReport](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Get-ZAPlannerZcasReport.md)
|
||||
* Created `Get-ZAProtectedVm` and `Get-ZAProtectedVmReport` functions to leverage the newly released Zerto Analytics APIs for this data. Help files can be found here: [Get-ZAProtectedVm](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Get-ZAProtectedVm.md) and [Get-ZAProtectedVmReport](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Get-ZAProtectedVmReport.md)
|
||||
|
||||
## [1.3.0.20191201]
|
||||
|
||||
### Zerto Virtual Manager
|
||||
|
||||
* [Zerto version 7.5 has been released.](https://s3.amazonaws.com/zertodownload_docs/Latest/Zerto%20Virtual%20Replication%20Release%20Notes.pdf) As part of this release Zerto has added API functionality that requires the following updates.
|
||||
* A token is now required to pair two sites together. The need is discussed in [Issue 46](https://github.com/ZertoPublic/ZertoApiWrapper/issues/46). To implement this change a `-token` parameter has been added to the `Add-ZertoPeerSite` function.
|
||||
* A new function has been added; `New-ZertoPairingToken`. This function will allow users to generate a pairing authentication token from the target ZVM to be used in the pairing process. [Issue 47](https://github.com/ZertoPublic/ZertoApiWrapper/issues/47) covers additional details.
|
||||
* A new function has been added; `Invoke-ZertoEvacuateVra`. This function will allow users to evacuate a target VRA by specifying a Host Name, VRA Name, or VRA Identifier. All VMs currently replicating to the specified location will be migrated to different targets. [Issue 51](https://github.com/ZertoPublic/ZertoApiWrapper/issues/51)
|
||||
* A function has been added; `Copy-ZertoVpg`. This function will allow users to copy the settings of a single VPG and add new VMs to it. There is currently no customization beyond specifying the VMs to be placed in the newly created VPG. Should additional edits \ updates be required, they should be done post creation. [Issue 54](https://github.com/ZertoPublic/ZertoApiWrapper/issues/54)
|
||||
* Fixed [issue 57](https://github.com/ZertoPublic/ZertoApiWrapper/issues/57) where a `Start-ZertoFailoverTest` would throw an error complaining about validating the body parameter. This has been fixed and tested against Zerto Virtual Manager 7.5 Update 1 with Windows PowerShell 5.1 and PowerShell Core 6.2.
|
||||
|
||||
## [1.2.0.20190801]
|
||||
|
||||
### Zerto Virtual Manager
|
||||
|
||||
* Added two functions to aid in bulk updating of NIC information for protected VMs. ([Issue 38](https://github.com/ZertoPublic/ZertoApiWrapper/issues/38))
|
||||
* [Export-ZertoVmNicSetting](https://github.com/ZertoPublic/ZertoApiWrapper/blob/Master/docs/Export-ZertoVmNicSettings.md)
|
||||
* [Import-ZertoVmNicSetting](https://github.com/ZertoPublic/ZertoApiWrapper/blob/Master/docs/Import-ZertoVmNicSettings.md)
|
||||
* Fixed an [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/43) where a VPG being created with a single VM member would not be parsed by the API correctly using PowerShell 5.1
|
||||
|
||||
### Zerto Analytics
|
||||
|
||||
* Fixed an [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/36) where the Zerto Analytics Rest Request function was not checking for the token before attempting a connection.
|
||||
* Fixed an [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/40) where the `Get-ZAVpg` method would return a 404 error when a `-vpgIdentifier` parameter was specified.
|
||||
|
||||
### General Updates
|
||||
|
||||
* Updated the way that tests are invoked and parsed to ensure that both source and built module files are tested. This will ensure that what is being shipped passes all tests along with testing of the source files.
|
||||
* Added additional parameter validation tests to several of the functions. On-going effort to complete stand alone unit testing of each function.
|
||||
|
||||
## [Initial Release]
|
||||
|
||||
### Zerto Virtual Manager
|
||||
|
||||
* Updated `Invoke-ZertoRestRequest` to work in Powershell 5.1 as well as Powershell core
|
||||
|
||||
### Zerto Analytics
|
||||
|
||||
* Implemented Zerto Analytics Functionality. Please see [Getting Started with Zerto Analytics](https://github.com/ZertoPublic/ZertoApiWrapper/wiki/Getting-Started-with-Zerto-Analytics)
|
||||
@@ -4,8 +4,8 @@ PowerShell wrapper for Zerto Virtual Manager API
|
||||
|
||||
## Current Build Status
|
||||
|
||||
[](https://app.codacy.com/app/wcarroll/ZertoApiWrapper?utm_source=github.com&utm_medium=referral&utm_content=wcarroll/ZertoApiWrapper&utm_campaign=Badge_Grade_Settings)
|
||||
[](https://dev.azure.com/ZertoPublic/ZertoApiWrapper/_build/latest?definitionId=1&branchName=master)
|
||||
[](https://www.powershellgallery.com/packages/ZertoApiWrapper)
|
||||
|
||||
## Legal Disclaimer
|
||||
|
||||
@@ -20,23 +20,22 @@ This code is still under development! Please use carefully and if you encounter
|
||||
## Installing the Module
|
||||
|
||||
This module can be installed directly from the [PowerShell Gallery](https://www.powershellgallery.com/packages/ZertoApiWrapper) with the following command.
|
||||
`PS> Install-Module -name ZertoApiWrapper
|
||||
|
||||
```PowerShell
|
||||
PS> Install-Module -name ZertoApiWrapper
|
||||
```
|
||||
|
||||
## Getting Started
|
||||
|
||||
* [Getting Started with Zerto Virtual Manager and the ZertoApiWrapper](https://github.com/ZertoPublic/ZertoApiWrapper/wiki/Getting-Stated-with-Zerto-Virtual-Manager)
|
||||
* [Getting Started with Zerto Virtual Manager and the ZertoApiWrapper](https://github.com/ZertoPublic/ZertoApiWrapper/wiki/Getting-Started-with-Zerto-Virtual-Manager)
|
||||
* [Getting Started with Zerto Analytics and the ZertoApiWrapper](https://github.com/ZertoPublic/ZertoApiWrapper/wiki/Getting-Started-with-Zerto-Analytics)
|
||||
|
||||
## Recent Updates
|
||||
|
||||
* June 16th, 2019: Added functionality for Zerto Analytics.
|
||||
* May 31st, 2019: Implement logic to allow use of this module in both Windows PowerShell 5.1 and PowerShell Core.
|
||||
* March 15th, 2019: Implement Export and Import Functionality. Please See [Export-ZertoVpg Help](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Export-ZertoVpg.md) and [Import-ZertoVpg Help](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Import-ZertoVpg.md) for assistance. No current pre-seed support.
|
||||
* March 11th, 2019: Create basic VPG completed. Please see [New-ZertoVpg Help](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/New-ZertoVpg.md)
|
||||
All recent updates can now be tracked via the [Change Log](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/CHANGELOG.md).
|
||||
|
||||
## TODO
|
||||
|
||||
* Complete Help Markdown Files
|
||||
* JFLR Functionality
|
||||
* Create VPG (Per-VM modification and Backup Settings)
|
||||
* Edit VPG
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
|
||||
|
||||
## Initial Release
|
||||
|
||||
### Zerto Virtual Manager
|
||||
|
||||
* Updated `Invoke-ZertoRestRequest` to work in Powershell 5.1 as well as Powershell core
|
||||
|
||||
### Zerto Analytics
|
||||
|
||||
* Implemented Zerto Analytics Functionality. Please see [Getting Started with Zerto Analytics](https://github.com/ZertoPublic/ZertoApiWrapper/wiki/Getting-Started-with-Zerto-Analytics)
|
||||
@@ -0,0 +1,70 @@
|
||||
#Requires -Modules Pester
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
InModuleScope -ModuleName ZertoApiWrapper {
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "have a mandatory parameter for the Input Object" {
|
||||
Get-Command $global:function | Should -HaveParameter InputObject -Mandatory -Type PSCustomObject
|
||||
}
|
||||
|
||||
It "Input Object should not accecpt a Null or Empty value" {
|
||||
$myObj = [PSCustomObject]@{ }
|
||||
{ Get-Map -InputObject $myObj -Key "Key" -Value "Value" } | Should Throw
|
||||
{ Get-Map -InputObject $null -Key "Key" -Value "Value" } | Should Throw
|
||||
{ Get-Map -InputObject "" -Key "Key" -Value "Value" } | Should Throw
|
||||
}
|
||||
|
||||
It "have a mandatory string parameter for the Map Key" {
|
||||
Get-Command $global:function | Should -HaveParameter Key -Mandatory -Type String
|
||||
}
|
||||
|
||||
It "The Map variable should not accecpt a Null or Empty value" {
|
||||
$myObj = [PSCustomObject]@{one = 1; two = 2 }
|
||||
{ Get-Map -InputObject $myObj -Key "" -Value "Value" } | Should Throw
|
||||
{ Get-Map -InputObject $null -Key $null -Value "Value" } | Should Throw
|
||||
{ Get-Map -InputObject $myObj -Key 1 -Value "Value" } | Should Throw
|
||||
}
|
||||
|
||||
It "The Value variable should not accecpt a Null or Empty value" {
|
||||
$myObj = [PSCustomObject]@{one = 1; two = 2 }
|
||||
{ Get-Map -InputObject $myObj -Key "Key" -Value "" } | Should Throw
|
||||
{ Get-Map -InputObject $myObj -Key "Key" -Value $null } | Should Throw
|
||||
{ Get-Map -InputObject $myObj -Key "Key" -Value 1 } | Should Throw
|
||||
}
|
||||
|
||||
It "have a mandatory string parameter for the Map Value" {
|
||||
Get-Command $global:function | Should -HaveParameter Value -Mandatory -Type String
|
||||
}
|
||||
|
||||
It "should have an Output type of Hashtable" {
|
||||
(Get-Command $global:function).OutputType.Name | Should -Match "Hashtable"
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Function Tests" {
|
||||
$myObj = Get-Content "$global:here/Mocks/ProtectedVMs.json" | ConvertFrom-Json
|
||||
BeforeEach {
|
||||
$MyMap = Get-Map -InputObject $MyObj -Key "vmIdentifier" -Value "vmName"
|
||||
}
|
||||
It "Returned object should be a hashtable" {
|
||||
$myMap | Should -BeOfType Hashtable
|
||||
}
|
||||
|
||||
It "should return a hashtable with 3 entries" {
|
||||
$myMap.count | Should -Be 3
|
||||
}
|
||||
|
||||
It "should be properly mapped" {
|
||||
$myMap["vmid.12"] | Should -Be "ExchangeMailbox"
|
||||
$myMap["vmid.13"] | Should -Be "ExchangeApplication"
|
||||
$myMap["vmid.14"] | Should -Be "ExchangeWeb"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name function -Scope Global
|
||||
Remove-Variable -Name here -Scope Global
|
||||
@@ -1,30 +1,74 @@
|
||||
$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper'
|
||||
$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.'
|
||||
$file = Get-ChildItem "$filePath\$fileName"
|
||||
#Requires -Modules Pester
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
. $file.FullName
|
||||
$singleBoolItemTest = @{"BoolItem" = $True}
|
||||
$oneItemTest = @{"OneItem" = "Test"}
|
||||
$twoItemTest = @{"OneItem" = "Test"; "SecondItem" = "Yours"}
|
||||
$boolItemTest = @{"OneItem" = "Test"; "BoolItem" = $true}
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Describe $file.BaseName -Tag Unit {
|
||||
it "file should exist" {
|
||||
$file.Fullname | should exist
|
||||
}
|
||||
InModuleScope -ModuleName ZertoApiWrapper {
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "has a mandatory hashtable parameter for the filterTable" {
|
||||
Get-Command $global:function | Should -HaveParameter filterTable -Mandatory -Type Hashtable
|
||||
}
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file.Fullname -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
It "FilterTable should not accecpt a Null or Empty parameter" {
|
||||
{ Get-ZertoApiFilter -filtertable (@{ }) } | Should Throw
|
||||
{ Get-ZertoApiFilter -filtertable "" } | Should Throw
|
||||
{ Get-ZertoApiFilter -filtertable $null } | Should Throw
|
||||
}
|
||||
|
||||
it "converts bool to text" {
|
||||
Get-ZertoApiFilter -filtertable $singleBoolItemTest | should -Be "?BoolItem=True"
|
||||
It "should have an Output type of String" {
|
||||
(Get-Command $global:function).OutputType.Name | Should -Match "String"
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Function Unit Tests" {
|
||||
BeforeAll {
|
||||
$singleBoolItemTest = @{"BoolItem" = $True }
|
||||
$oneItemTest = @{ OneItem = "Test" }
|
||||
$twoItemTest = @{
|
||||
OneItem = "Test"
|
||||
SecondItem = "Yours"
|
||||
}
|
||||
$commonParamTest = @{
|
||||
Debug = $True
|
||||
ErrorAction = "Stop"
|
||||
ErrorVariable = "ErrVar"
|
||||
InformationAction = "Continue"
|
||||
InformationVariable = "InfoVar"
|
||||
OutVariable = "OutVar"
|
||||
OutBuffer = "OutBuff"
|
||||
PipelineVariable = "PipeVar"
|
||||
Verbose = $false
|
||||
WarningAction = "SilentlyContinue"
|
||||
WarningVariable = "WarnVar"
|
||||
WhatIf = $True
|
||||
Confirm = $false
|
||||
OneItem = "Test"
|
||||
}
|
||||
}
|
||||
|
||||
It "converts bool to text" {
|
||||
Get-ZertoApiFilter -filtertable $singleBoolItemTest | Should -Be "?BoolItem=True"
|
||||
}
|
||||
|
||||
It "one item test" {
|
||||
Get-ZertoApiFilter -filtertable $oneItemTest | Should -Be "?OneItem=Test"
|
||||
}
|
||||
|
||||
It "should ignore CommonParameters" {
|
||||
Get-ZertoApiFilter -filtertable $commonParamTest | Should -Be "?OneItem=Test"
|
||||
}
|
||||
|
||||
It "should process a filter table with more than one item" {
|
||||
$returnString = Get-ZertoApiFilter -filtertable $twoItemTest
|
||||
$returnString | Should -match "^\?"
|
||||
$returnString | Should -match "&"
|
||||
$returnString | Should -match "OneItem=Test"
|
||||
$returnString | Should -match "SecondItem=Yours"
|
||||
}
|
||||
}
|
||||
}
|
||||
it "one item test" {
|
||||
Get-ZertoApiFilter -filtertable $oneItemTest | should be "?OneItem=Test"
|
||||
}
|
||||
#TODO:: Figure out multi-item tests
|
||||
}
|
||||
|
||||
Remove-Variable -Name function -Scope Global
|
||||
Remove-Variable -Name here -Scope Global
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper'
|
||||
$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.'
|
||||
$file = Get-ChildItem "$filePath\$fileName"
|
||||
. $file.FullName
|
||||
|
||||
Describe $file.BaseName -Tag Unit {
|
||||
it "file should exist" {
|
||||
$file.FullName | should exist
|
||||
}
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file.FullName -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper'
|
||||
$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.'
|
||||
$file = Get-ChildItem "$filePath\$fileName"
|
||||
. $file.FullName
|
||||
|
||||
Describe $file.BaseName -Tag Unit {
|
||||
it "file should exist" {
|
||||
$file.FullName | should exist
|
||||
}
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file.FullName -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
[
|
||||
{
|
||||
"VMname": "ExchangeMailbox",
|
||||
"VMIdentifier": "vmid.12"
|
||||
},
|
||||
{
|
||||
"VMName": "ExchangeApplication",
|
||||
"VmIdentifier": "vmid.13"
|
||||
},
|
||||
{
|
||||
"VMName": "ExchangeWeb",
|
||||
"VmIdentifier": "vmid.14"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1,76 +1,94 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -Leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
|
||||
It "Is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
BeforeAll {
|
||||
$script:ScriptBlock = (Get-Command $global:function).ScriptBlock
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
it "Has a mandatory string parameter for the target host" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter TargetHost -Mandatory -Type String
|
||||
It "$global:function should have exactly 16 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 16
|
||||
}
|
||||
|
||||
it "Will not take a non-ip address as a 'TargetHost'" {
|
||||
{Add-ZertoPeerSite -targetHost 'MyZVMHost' -targetPort '9081'} | should -Throw
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.266' -targetPort '9081'} | should -Throw
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1' -targetPort '9081'} | should -Throw
|
||||
{Add-ZertoPeerSite -targetHost $null -targetPort '9081'} | should -Throw
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'targetHost'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'targetPort'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' }
|
||||
@{ParameterName = 'token'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
it "Has a non-mandatory string parameter for the target port with default value of 9081" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter TargetPort -Not -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter TargetPort -Type Int32
|
||||
Get-Command $file.BaseName | Should -HaveParameter TargetPort -DefaultValue 9081
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
it "Will not take a non-int as a port" {
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 'string'} | should -Throw
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort $true} | should -Throw
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort $null} | should -Throw
|
||||
It "targetPort Parameter should have a default value of 9081" {
|
||||
Get-Command $global:function | Should -HaveParameter targetPort -DefaultValue 9081
|
||||
}
|
||||
|
||||
It "Will fail if the specified port is outside of the range 1024 - 65535" {
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 1023} | Should -Throw
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 65536} | Should -Throw
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 0} | Should -Throw
|
||||
{Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort -1} | Should -Throw
|
||||
It "targetPort Parameter should have a Min value of 1024" {
|
||||
(Get-Command $global:function).Parameters['targetPort'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 1024
|
||||
}
|
||||
|
||||
it "Supports 'SupportsShouldProcess'" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter WhatIf
|
||||
Get-Command $file.BaseName | Should -HaveParameter Confirm
|
||||
$file | Should -FileContentMatch 'SupportsShouldProcess'
|
||||
$file | Should -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
It "targetPort Parameter should have a Max value of 65535" {
|
||||
(Get-Command $global:function).Parameters['targetPort'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 65535
|
||||
}
|
||||
|
||||
It "Supports 'SupportsShouldProcess'" {
|
||||
Get-Command $global:function | Should -HaveParameter WhatIf
|
||||
Get-Command $global:function | Should -HaveParameter Confirm
|
||||
$script:ScriptBlock | Should -Match 'SupportsShouldProcess'
|
||||
$script:ScriptBlock | Should -Match '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
}
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Function Unit Tests" {
|
||||
|
||||
Mock -ModuleName ZertoApiWrapper Invoke-ZertoRestRequest {
|
||||
return "9a49f42e-2bbd-4bf8-b571-77908a2e5e98.928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
Context "Add-ZertoPeerSite::Functional Unit Tests" {
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest {
|
||||
return (Get-Content "$global:here\Mocks\TaskId.txt")
|
||||
}
|
||||
|
||||
it "Returns a string value" {
|
||||
It "Returns a string value when no Token Passed" {
|
||||
$results = Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort '9081'
|
||||
$results | should -Not -BeNullOrEmpty
|
||||
$results | should -BeOfType "String"
|
||||
$results | Should -BeExactly "9a49f42e-2bbd-4bf8-b571-77908a2e5e98.928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
$results | Should -Not -BeNullOrEmpty
|
||||
$results | Should -BeOfType "String"
|
||||
$results | Should -BeExactly "7e79035e-fb8c-47fe-815c-12ddd41708e6.3e4cdd0d-1064-4022-921f-6265ad6d335a"
|
||||
}
|
||||
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest
|
||||
It "Returns a string value when a Token is passed" {
|
||||
$results = Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort '9081' -token "NotARealTokenString"
|
||||
$results | Should -Not -BeNullOrEmpty
|
||||
$results | Should -BeOfType "String"
|
||||
$results | Should -BeExactly "7e79035e-fb8c-47fe-815c-12ddd41708e6.3e4cdd0d-1064-4022-921f-6265ad6d335a"
|
||||
}
|
||||
|
||||
It "Does not return a taskId if '-whatif' is used" {
|
||||
$results = Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort '9081' -WhatIf
|
||||
$results | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -Exactly 2
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#Requires -Modules Pester
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -Leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
BeforeAll {
|
||||
$script:ScriptBlock = (Get-Command $global:function).ScriptBlock
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
It "$global:function should have exactly 16 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 16
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgSettingsIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'Vm'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'VpgName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "Supports 'SupportsShouldProcess'" {
|
||||
Get-Command $global:function | Should -HaveParameter WhatIf
|
||||
Get-Command $global:function | Should -HaveParameter Confirm
|
||||
$script:ScriptBlock | Should -Match 'SupportsShouldProcess'
|
||||
$script:ScriptBlock | Should -Match '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Add-ZertoPeerSite::Functional Unit Tests" {
|
||||
}
|
||||
}
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
@@ -1,66 +1,63 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
BeforeAll {
|
||||
$script:ScriptBlock = (Get-Command $global:function).ScriptBlock
|
||||
}
|
||||
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest {
|
||||
return "3b687246-ac63-40da-9a59-b99863769eb0.928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
return (Get-Content "$global:here\Mocks\TaskId.txt")
|
||||
}
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName get-zertovpg {
|
||||
return @{vpgIdentifier = "dddf2fa8-79e2-4e4f-a83b-f66676afea64"}
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName get-zertovpg -ParameterFilter { $VpgName -eq "MyVpg" } {
|
||||
return (Get-Content "$global:here\Mocks\VPGInfo.json" -Raw | ConvertFrom-Json)
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
it "Has a parameter for the VpgName that is Mandatory" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory -Type String
|
||||
Context "$($global:function)::Parameter Unit Tests" {
|
||||
It "Has a parameter for the VpgName that is Mandatory" {
|
||||
Get-Command $global:function | Should -HaveParameter vpgName -Mandatory -Type 'String[]'
|
||||
}
|
||||
|
||||
it "Has a parameter for the CheckpointName that is Mandatory" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter CheckpointName -Mandatory -Type String
|
||||
It "Has a parameter for the CheckpointName that is Mandatory" {
|
||||
Get-Command $global:function | Should -HaveParameter CheckpointName -Mandatory -Type String
|
||||
}
|
||||
|
||||
it "Throws and error when an empty or null checkpointName is specified" {
|
||||
{Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName ""} | Should -Throw
|
||||
{Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName $null} | Should -Throw
|
||||
It "Throws and error when an empty or null checkpointName is specified" {
|
||||
{ Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName "" } | Should -Throw
|
||||
{ Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName $null } | Should -Throw
|
||||
}
|
||||
|
||||
it "Throws an error when an empty or null vpgName is specified" {
|
||||
{Checkpoint-ZertoVpg -vpgName "" -checkpointName "MyCheckPoint"} | Should -Throw
|
||||
{Checkpoint-ZertoVpg -vpgName $null -checkpointName "MyCheckPoint"} | Should -Throw
|
||||
It "Throws an error when an empty or null vpgName is specified" {
|
||||
{ Checkpoint-ZertoVpg -vpgName "" -checkpointName "MyCheckPoint" } | Should -Throw
|
||||
{ Checkpoint-ZertoVpg -vpgName $null -checkpointName "MyCheckPoint" } | Should -Throw
|
||||
}
|
||||
|
||||
it "Does not support 'SupportsShouldProcess'" {
|
||||
Get-Command $file.BaseName | Should -Not -HaveParameter WhatIf
|
||||
Get-Command $file.BaseName | Should -Not -HaveParameter Confirm
|
||||
$file | Should -Not -FileContentMatch 'SupportsShouldProcess'
|
||||
$file | Should -Not -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
It "Does not support 'SupportsShouldProcess'" {
|
||||
Get-Command $global:function | Should -Not -HaveParameter WhatIf
|
||||
Get-Command $global:function | Should -Not -HaveParameter Confirm
|
||||
$script:ScriptBlock | Should -not -match 'SupportsShouldProcess'
|
||||
$script:ScriptBlock | Should -not -match '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
}
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Function Unit Tests" {
|
||||
Context "$($global:function)::Function Unit Tests" {
|
||||
|
||||
it "should return a not null or empty string" {
|
||||
It "should return a not null or empty string" {
|
||||
$results = Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName "My Checkpoint Name"
|
||||
$results | should -not -BeNullOrEmpty
|
||||
$results | should -BeOfType "String"
|
||||
$results | should -BeExactly "3b687246-ac63-40da-9a59-b99863769eb0.928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
$results | Should -not -BeNullOrEmpty
|
||||
$results | Should -BeOfType "String"
|
||||
$results | Should -BeExactly "7e79035e-fb8c-47fe-815c-12ddd41708e6.3e4cdd0d-1064-4022-921f-6265ad6d335a"
|
||||
}
|
||||
It "does not return anything when a invalid VPG is defined" {
|
||||
$results = Checkpoint-ZertoVpg -vpgName "DoesNotExist" -checkpointName "My Checkpoint Name"
|
||||
$results | Should -Be "Cannot find VPG named DoesNotExist. Please check the name and try again."
|
||||
}
|
||||
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpg
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -Exactly 2
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpg -Exactly 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name function -Scope Global
|
||||
Remove-Variable -Name here -Scope Global
|
||||
|
||||
@@ -1,19 +1,72 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
BeforeAll {
|
||||
$script:ScriptBlock = (Get-Command $global:function).ScriptBlock
|
||||
}
|
||||
}
|
||||
|
||||
Context "$($global:function)::Parameter Unit Tests" {
|
||||
It "Has a parameter for the Required Credentials that is Mandatory" {
|
||||
Get-Command $global:function | Should -HaveParameter credential -Mandatory -Type PSCredential
|
||||
}
|
||||
}
|
||||
|
||||
Context "$($global:function)::Function Unit Tests" {
|
||||
|
||||
InModuleScope -ModuleName ZertoApiWrapper {
|
||||
Mock -CommandName Invoke-ZARestRequest {
|
||||
return (Get-Content "$global:here\Mocks\ZAToken.json"-Raw | ConvertFrom-Json)
|
||||
}
|
||||
|
||||
$password = 'NotARealPassword' | ConvertTo-SecureString -AsPlainText -Force
|
||||
$cred = New-Object pscredential('NotARealUser', $password)
|
||||
|
||||
$results = Connect-ZertoAnalytics -credential $cred
|
||||
|
||||
It "Creates a Script Level Hashtable Variable for the ZertoAnalytics Headers" {
|
||||
$script:zaHeaders | Should -BeOfType Hashtable
|
||||
}
|
||||
|
||||
It "the ZertoAnalytics Headers variable contains 2 items" {
|
||||
$script:zaHeaders.keys | Should -HaveCount 2
|
||||
}
|
||||
|
||||
It "the ZertoAnalytics Headers variable has an 'Accept' key" {
|
||||
$script:zaHeaders.keys | Should -Contain 'Accept'
|
||||
}
|
||||
|
||||
It "thh ZertoAnalytics headers variable 'Accept' key should be JSON" {
|
||||
$script:zaHeaders['Accept'] | Should -match 'application/json'
|
||||
}
|
||||
|
||||
It "the ZertoAnalytics Headers variable has an 'Authorization' key" {
|
||||
$script:zaHeaders.keys | Should -Contain 'Authorization'
|
||||
}
|
||||
|
||||
It "the ZertoAnalytics Headers variable 'Authorization' key should start with 'Bearer'" {
|
||||
$script:zaHeaders['Authorization'] | Should -Match '^Bearer '
|
||||
}
|
||||
|
||||
It "Creates a Script Level Variable for the LastActionTime" {
|
||||
$script:zaLastActionTime | Should -BeOfType Long
|
||||
}
|
||||
|
||||
It "LastActionTime Variable should be in the past" {
|
||||
$script:zaLastActionTime | Should -BeLessThan (Get-Date).Ticks
|
||||
}
|
||||
|
||||
It "Returns Header Information" {
|
||||
$results | Should -not -BeNullOrEmpty
|
||||
$results['Authorization'] | Should -MatchExactly 'Bearer N074r34l70k3n'
|
||||
$results['Accept'] | Should -Match 'application/json'
|
||||
}
|
||||
}
|
||||
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZARestRequest -Exactly 1
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name function -Scope Global
|
||||
Remove-Variable -Name here -Scope Global
|
||||
|
||||
@@ -1,203 +1,142 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$userName = "zerto\build"
|
||||
$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force
|
||||
$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password)
|
||||
$Server = "192.168.1.100"
|
||||
$zertoPort = "7669"
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -Leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag Unit {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
BeforeAll {
|
||||
$script:ScriptBlock = (Get-Command $global:function).ScriptBlock
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
Context "$($global:function)::Parameter Unit Tests" {
|
||||
|
||||
it "server vairable has a mandatory String parameter" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter zertoserver -Mandatory -Type String
|
||||
It "server vairable has a mandatory String parameter" {
|
||||
Get-Command $global:function | Should -HaveParameter zertoserver -Mandatory -Type String
|
||||
}
|
||||
|
||||
it "server variable does not accecpt an empty or null input" {
|
||||
{Connect-ZertoServer -zertoServer $null -credential $credential} | Should -Throw
|
||||
{Connect-ZertoServer -zertoServer "" -credential $credential} | Should -Throw
|
||||
It "server variable does not accecpt an empty or null input" {
|
||||
{ Connect-ZertoServer -zertoServer $null -credential $credential } | Should -Throw
|
||||
{ Connect-ZertoServer -zertoServer "" -credential $credential } | Should -Throw
|
||||
}
|
||||
|
||||
it "port variable has a non-mandatory String parameter" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter zertoPort -Not -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter zertoPort -Type String
|
||||
Get-Command $file.BaseName | Should -HaveParameter zertoPort -DefaultValue "9669"
|
||||
It "port variable has a non-mandatory String parameter" {
|
||||
Get-Command $global:function | Should -HaveParameter zertoPort -Not -Mandatory
|
||||
Get-Command $global:function | Should -HaveParameter zertoPort -Type String
|
||||
Get-Command $global:function | Should -HaveParameter zertoPort -DefaultValue "9669"
|
||||
}
|
||||
|
||||
it "port variable does not accecpt an empty or null input" {
|
||||
{Connect-ZertoServer -zertoServer "192.168.1.100" -zertoPort "" -credential $credential} | Should -Throw
|
||||
{Connect-ZertoServer -zertoServer "192.168.1.100" -zertoPort $null -credential $credential} | Should -Throw
|
||||
It "port variable does not accecpt an empty or null input" {
|
||||
{ Connect-ZertoServer -zertoServer "192.168.1.100" -zertoPort "" -credential $credential } | Should -Throw
|
||||
{ Connect-ZertoServer -zertoServer "192.168.1.100" -zertoPort $null -credential $credential } | Should -Throw
|
||||
}
|
||||
|
||||
it "port variable should fall between 1024 and 65535" {
|
||||
{Connect-ZertoServer -zertoServer $Server -zertoPort 1023 -credential $credential} | Should -Throw
|
||||
{Connect-ZertoServer -zertoServer $Server -zertoPort 65536 -credential $credential} | Should -Throw
|
||||
{Connect-ZertoServer -zertoServer $Server -zertoPort 0 -credential $credential} | Should -Throw
|
||||
{Connect-ZertoServer -zertoServer $Server -zertoPort -1 -credential $credential} | Should -Throw
|
||||
It "port variable should fall between 1024 and 65535" {
|
||||
{ Connect-ZertoServer -zertoServer $Server -zertoPort 1023 -credential $credential } | Should -Throw
|
||||
{ Connect-ZertoServer -zertoServer $Server -zertoPort 65536 -credential $credential } | Should -Throw
|
||||
{ Connect-ZertoServer -zertoServer $Server -zertoPort 0 -credential $credential } | Should -Throw
|
||||
{ Connect-ZertoServer -zertoServer $Server -zertoPort -1 -credential $credential } | Should -Throw
|
||||
}
|
||||
|
||||
it "has a mandatory PSCredential parameter for the credential vairable" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter credential -Mandatory -Type PSCredential
|
||||
It "has a mandatory PSCredential parameter for the credential vairable" {
|
||||
Get-Command $global:function | Should -HaveParameter credential -Mandatory -Type PSCredential
|
||||
}
|
||||
|
||||
it "should require a PSCredentialObject for the credentials" {
|
||||
{Connect-ZertoServer -zertoServer -credential "MyUsername"} | Should -Throw
|
||||
{Connect-ZertoServer -zertoServer -credential 1234} | Should -Throw
|
||||
{Connect-ZertoServer -zertoServer -credential $(@{Username = "zerto\build"; Password = 'SecureString'})} | Should -Throw
|
||||
It "should require a PSCredentialObject for the credentials" {
|
||||
{ Connect-ZertoServer -zertoServer -credential "MyUsername" } | Should -Throw
|
||||
{ Connect-ZertoServer -zertoServer -credential 1234 } | Should -Throw
|
||||
{ Connect-ZertoServer -zertoServer -credential $(@{Username = "zerto\build"; Password = 'SecureString' }) } | Should -Throw
|
||||
}
|
||||
|
||||
It "has a switch parameter to return the headers" {
|
||||
Get-Command $global:function | Should -HaveParameter returnHeaders
|
||||
Get-Command $global:function | Should -HaveParameter returnHeaders -Type Switch
|
||||
}
|
||||
|
||||
It "has a switch parameter to auto reauthorize the session" {
|
||||
Get-Command $global:function | Should -HaveParameter autoReconnect
|
||||
Get-Command $global:function | Should -HaveParameter autoReconnect -Type Switch
|
||||
}
|
||||
}
|
||||
|
||||
InModuleScope ZertoApiWrapper {
|
||||
Context "$($file.BaseName)::InModuleScope Function Unit Tests" {
|
||||
InModuleScope -ModuleName ZertoApiWrapper {
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest {
|
||||
# Attempted to Mock this per the Mock Below and it blew up. Auth Headers Returns a Dictionary
|
||||
# and does not index the same way when imported from a JSON file. Need addtional investigation.
|
||||
$xZertoSession = @("e34da0b0-4bc2-4cda-b316-0384e35bdca5")
|
||||
$Headers = @{'x-zerto-session' = $xZertoSession }
|
||||
$results = @{'Headers' = $Headers }
|
||||
return $results
|
||||
}
|
||||
|
||||
$server = '192.168.1.100'
|
||||
$userName = "zerto\build"
|
||||
$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force
|
||||
$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password)
|
||||
Context "$($global:function)::InModuleScope Function Unit Tests" {
|
||||
|
||||
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest {
|
||||
$xZertoSession = @("7ecf544d-e7ed-4108-86f3-fb355c51cdfa")
|
||||
$Headers = @{'x-zerto-session' = $xZertoSession}
|
||||
$results = @{'Headers' = $Headers}
|
||||
return $results
|
||||
BeforeAll {
|
||||
$server = '192.168.1.100'
|
||||
$password = ConvertTo-SecureString -String "NotARealPassword" -AsPlainText -Force
|
||||
$credential = New-Object pscredential('NotARealUser', $password)
|
||||
$now = $(Get-Date).ticks
|
||||
Connect-ZertoServer -zertoServer $server -credential $credential
|
||||
}
|
||||
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoLocalSite {
|
||||
$results = @{
|
||||
BandwidthThrottlingInMBs = -1
|
||||
ContactEmail = "vSphere-Site01@zerto.com"
|
||||
ContactName = "vSphere-Site01@zerto.com"
|
||||
ContactPhone = "066-6666666"
|
||||
IpAddress = "192.168.200.1"
|
||||
IsReplicationToSelfEnabled = $True
|
||||
Link = @{
|
||||
href = "https://192.168.24.1:7669/v1/localsite"
|
||||
identifier = "928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
rel = $null
|
||||
type = "LocalSiteApi"
|
||||
}
|
||||
Location = "vSphere-Site01"
|
||||
SiteName = "vSphere-Site01 at Zerto"
|
||||
SiteType = "VCenter"
|
||||
UtcOffsetInMinutes = -240
|
||||
Version = "7.0.0"
|
||||
SiteIdentifier = "928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
}
|
||||
return $results
|
||||
}
|
||||
|
||||
$now = $(Get-Date).ticks
|
||||
Connect-ZertoServer -zertoServer $server -credential $credential
|
||||
|
||||
it "Module Scope zvmServer variable tests" {
|
||||
It "Module Scope zvmServer variable tests" {
|
||||
$script:zvmServer | Should -Not -BeNullOrEmpty
|
||||
$script:zvmServer | Should -Be $server
|
||||
}
|
||||
|
||||
it "Module Scope zvmPort variable tests" {
|
||||
It "Module Scope zvmPort variable tests" {
|
||||
$script:zvmPort | Should -Not -BeNullOrEmpty
|
||||
$script:zvmPort | Should -Be '9669'
|
||||
}
|
||||
|
||||
it "Module Scope zvmLastAction variable tests" {
|
||||
It "Module Scope zvmLastAction variable tests" {
|
||||
$script:zvmLastAction | Should -Not -BeNullOrEmpty
|
||||
$script:zvmLastAction | Should -BeGreaterOrEqual $now
|
||||
}
|
||||
|
||||
it "Module Scope zvmHeaders variable tests" {
|
||||
It "Module Scope zvmHeaders variable tests" {
|
||||
$script:zvmHeaders | Should -Not -BeNullOrEmpty
|
||||
$script:zvmHeaders | Should -BeOfType Hashtable
|
||||
$script:zvmHeaders.keys.count | Should -BeExactly 2
|
||||
$script:zvmHeaders | Should -BeOfType PSCustomObject
|
||||
$script:zvmHeaders.keys.count | Should -BeExactly 3
|
||||
$script:zvmHeaders.ContainsKey('x-zerto-session') | Should -BeTrue
|
||||
$script:zvmHeaders.ContainsKey('Accept') | Should -BeTrue
|
||||
$script:zvmHeaders['x-zerto-session'] | Should -BeOfType String
|
||||
$script:zvmHeaders['Accept'] | Should -BeOfType String
|
||||
}
|
||||
|
||||
it "Module Scope zvmLocalInfo variable tests" {
|
||||
$script:zvmLocalInfo | Should -Not -BeNullOrEmpty
|
||||
$script:zvmLocalInfo | Should -BeOfType Hashtable
|
||||
$script:zvmLocalInfo['SiteIdentifier'] | Should -BeOfType String
|
||||
$script:zvmLocalInfo.ContainsKey('SiteIdentifier') | Should -BeTrue
|
||||
$script:zvmLocalInfo['SiteIdentifier'] | Should -BeOfType String
|
||||
}
|
||||
|
||||
$headers = Connect-ZertoServer -zertoServer $Server -credential $credential -returnHeaders
|
||||
it "returns a Hashtable with 2 keys" {
|
||||
It "returns a Hashtable with 2 keys" {
|
||||
$headers | Should -BeOfType Hashtable
|
||||
$headers.keys.count | should be 2
|
||||
$headers.keys.count | Should -Be 3
|
||||
}
|
||||
|
||||
it "return value has a key called 'x-zerto-session'" {
|
||||
$headers.ContainsKey('x-zerto-session') | should be $true
|
||||
It "return value has a key called 'x-zerto-session'" {
|
||||
$headers.ContainsKey('x-zerto-session') | Should -Be $true
|
||||
}
|
||||
|
||||
it "return key 'x-zerto-session' value should be a string" {
|
||||
$headers['x-zerto-session'] | should -BeOfType "String"
|
||||
$headers['x-zerto-session'] | Should -BeExactly "7ecf544d-e7ed-4108-86f3-fb355c51cdfa"
|
||||
It "return key 'x-zerto-session' value should be a string" {
|
||||
$headers['x-zerto-session'] | Should -BeOfType "String"
|
||||
$headers['x-zerto-session'] | Should -BeExactly "e34da0b0-4bc2-4cda-b316-0384e35bdca5"
|
||||
}
|
||||
|
||||
it "return value has a key called 'accept'" {
|
||||
$headers.ContainsKey('accept') | should be $true
|
||||
It "return value has a key called 'accept'" {
|
||||
$headers.ContainsKey('accept') | Should -Be $true
|
||||
}
|
||||
|
||||
it "return key 'accept' value should be 'application/json'" {
|
||||
$headers['accept'] | should be 'application/json'
|
||||
It "return key 'accept' value should be 'application/json'" {
|
||||
$headers['accept'] | Should -Be 'application/json'
|
||||
}
|
||||
|
||||
it "should not require a port to be specified" {
|
||||
It "should not require a port to be specified" {
|
||||
Connect-ZertoServer -zertoServer $Server -credential $credential
|
||||
}
|
||||
|
||||
it "returns null when -ReturnHeaders is not used" {
|
||||
It "returns null when -ReturnHeaders is not used" {
|
||||
Connect-ZertoServer -zertoServer $Server -credential $credential | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoLocalSite
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -Exactly 4
|
||||
}
|
||||
}
|
||||
}
|
||||
<#
|
||||
Describe "Connect-ZertoServer" -Tag Integration {
|
||||
it "file should exist" {
|
||||
"$filePath\$fileName" | should exist
|
||||
}
|
||||
it "has a function called Connect-ZertoServer" {
|
||||
get-command Connect-ZertoServer | should be $true
|
||||
}
|
||||
$headers = Connect-ZertoServer -zertoServer $Server -zertoPort $zertoPort -credential $credential -returnHeaders
|
||||
it "returns a Hashtable with 2 keys" {
|
||||
$headers.keys.count | should be 2
|
||||
}
|
||||
it "return value has a key called 'x-zerto-session'" {
|
||||
$headers.ContainsKey('x-zerto-session') | should be $true
|
||||
}
|
||||
it "return key 'x-zerto-session' value should be a string" {
|
||||
$headers['x-zerto-session'].gettype().name | should be "String"
|
||||
}
|
||||
it "return value has a key called 'accept'" {
|
||||
$headers.ContainsKey('accept') | should be $true
|
||||
}
|
||||
it "return key 'accept' value should be 'application/json'" {
|
||||
$headers['accept'] | should be 'application/json'
|
||||
}
|
||||
Disconnect-ZertoServer
|
||||
}
|
||||
#>
|
||||
|
||||
Remove-Variable -Name function -Scope Global
|
||||
Remove-Variable -Name here -Scope Global
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
#Requires -Modules Pester
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
BeforeAll {
|
||||
$script:ScriptBlock = (Get-Command $global:function).ScriptBlock
|
||||
}
|
||||
|
||||
Context "$($global:function)::Parameter Unit Tests" {
|
||||
|
||||
It "$global:function should have exactly 16 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 16
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'SourceVpgName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'NewVpgName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'VMs'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
$null {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.TypeId.Count | Should -Be 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "Supports 'SupportsShouldProcess'" {
|
||||
Get-Command $global:function | Should -HaveParameter WhatIf
|
||||
Get-Command $global:function | Should -HaveParameter Confirm
|
||||
$script:ScriptBlock | Should -match 'SupportsShouldProcess'
|
||||
$script:ScriptBlock | Should -match '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
}
|
||||
}
|
||||
|
||||
Context "$($global:function)::Function Unit Tests" {
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpg -ParameterFilter {
|
||||
$vpgName -eq "MyVpg"
|
||||
} {
|
||||
return (Get-Content "$global:here\Mocks\GetVpg.json" -Raw | ConvertFrom-Json)
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpg -ParameterFilter {
|
||||
$vpgName -eq "NotAVpg"
|
||||
} {
|
||||
return $null
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoUnprotectedVm {
|
||||
return (Get-Content "$global:here\Mocks\UnprotectedVms.json" -Raw | ConvertFrom-Json)
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoProtectedVm {
|
||||
return (Get-Content "$global:here\Mocks\ProtectedVms.json" -Raw | ConvertFrom-Json)
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq "vpgSettings/copyVpgSettings"
|
||||
} {
|
||||
return (Get-Content "$global:here\Mocks\VpgId.txt")
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq "vpgSettings/9607f923-00a7-477b-8b04-26a386214455/vms"
|
||||
} {
|
||||
return $null
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq "vpgSettings/9607f923-00a7-477b-8b04-26a386214455"
|
||||
} {
|
||||
return (Get-Content "$global:here\Mocks\CopyVpgSettings.json" -Raw | ConvertFrom-Json)
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Save-ZertoVpgSetting {
|
||||
return (Get-Content "$global:here\Mocks\TaskId.txt")
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Get-Map -ParameterFilter {
|
||||
$null -ne $InputObject[0].VpgName
|
||||
} {
|
||||
@{
|
||||
"WindowsBox" = "d809de8e-deb7-45cc-b620-08030a1143e1.vm-90"
|
||||
"CentOS-Test" = "d809de8e-deb7-45cc-b620-08030a1143e1.vm-88"
|
||||
"Application01" = "d809de8e-deb7-45cc-b620-08030a1143e1.vm-35"
|
||||
"sql01-test" = "d809de8e-deb7-45cc-b620-08030a1143e1.vm-73"
|
||||
"jenkins" = "d809de8e-deb7-45cc-b620-08030a1143e1.vm-75"
|
||||
}
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Get-Map -ParameterFilter {
|
||||
$null -eq $InputObject[0].VpgName
|
||||
} {
|
||||
@{
|
||||
"Win2019Template" = "d809de8e-deb7-45cc-b620-08030a1143e1.vm-79"
|
||||
"Ubuntu01" = "d809de8e-deb7-45cc-b620-08030a1143e1.vm-34"
|
||||
"WinTemplate" = "d809de8e-deb7-45cc-b620-08030a1143e1.vm-25"
|
||||
"sql01-prod" = "d809de8e-deb7-45cc-b620-08030a1143e1.vm-87"
|
||||
"nczvm.nc.lab" = "d809de8e-deb7-45cc-b620-08030a1143e1.vm-30"
|
||||
}
|
||||
} -Verifiable
|
||||
|
||||
It "Should throw an error when no VPG is found" {
|
||||
{ Copy-ZertoVpg -SourceVpgName "NotAVpg" -NewVpgName "NewVpg" -VMs 'sql01-prod', 'Ubuntu01' } | Should Throw "Unable to find a VPG with the name:"
|
||||
}
|
||||
|
||||
It "Returns a TaskIdentifier when called correctly" {
|
||||
Copy-ZertoVpg -SourceVpgName "MyVpg" -NewVpgName "NewVpg" -VMs 'sql01-prod', 'Ubuntu01' | Should -Be "7e79035e-fb8c-47fe-815c-12ddd41708e6.3e4cdd0d-1064-4022-921f-6265ad6d335a"
|
||||
}
|
||||
|
||||
It "Should warn when VM is not found" {
|
||||
$results = Copy-ZertoVpg -SourceVpgName "MyVpg" -NewVpgName "NewVpg" -VMs 'sql01-prod', 'Ubuntu01', 'DoesNotExist' 3>&1
|
||||
$results[0].ToString() | Should -Match 'Unable to find VM with Name DoesNotExist. Skipping.'
|
||||
|
||||
}
|
||||
|
||||
Assert-VerifiableMock
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name function -Scope Global
|
||||
Remove-Variable -Name here -Scope Global
|
||||
@@ -1,37 +1,40 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest {
|
||||
$null
|
||||
}
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Remove-Variable {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
}
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
it "Does not take any parameters" {
|
||||
(get-command disconnect-zertoserver).parameters.count | Should -BeExactly 11
|
||||
Context "$($global:function)::Parameter Unit Tests" {
|
||||
It "Does not take any parameters" {
|
||||
(Get-Command disconnect-zertoserver).parameters.count | Should -BeExactly 11
|
||||
}
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Function Unit Tests" {
|
||||
it "Does not return anything" {
|
||||
Disconnect-ZertoServer | Should -BeNullOrEmpty
|
||||
Context "$($global:function)::Function Unit Tests" {
|
||||
InModuleScope -ModuleName ZertoApiWrapper {
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest {
|
||||
# Attempted to Mock this per the Mock Below and it blew up. Auth Headers Returns a Dictionary
|
||||
# and does not index the same way when imported from a JSON file. Need addtional investigation.
|
||||
$xZertoSession = @("e34da0b0-4bc2-4cda-b316-0384e35bdca5")
|
||||
$Headers = @{'x-zerto-session' = $xZertoSession }
|
||||
$results = @{'Headers' = $Headers }
|
||||
return $results
|
||||
}
|
||||
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoLocalSite {
|
||||
return (Get-Content -Path "$global:here\Mocks\LocalSiteInfo.json" -Raw | ConvertFrom-Json)
|
||||
}
|
||||
|
||||
BeforeAll {
|
||||
Connect-ZertoServer
|
||||
}
|
||||
|
||||
It "Does not return anything" {
|
||||
Disconnect-ZertoServer | Should -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name function -Scope Global
|
||||
Remove-Variable -Name here -Scope Global
|
||||
|
||||
@@ -1,187 +1,103 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path) -Replace "Tests", "ZertoApiWrapper"
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Mock -ModuleName ZertoApiWrapper Invoke-ZertoRestRequest {
|
||||
return "8dcfdc8e-e5d2-4ba4-9885-f9eb57d92b14.928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
Get-Content $global:here\Mocks\TaskId.txt
|
||||
}
|
||||
|
||||
Mock -ModuleName ZertoApiWrapper Get-ZertoVra {
|
||||
$vraInformation = @{
|
||||
DatastoreClusterIdentifier = $null
|
||||
DatastoreClusterName = $null
|
||||
DatastoreIdentifier = "840f99fb-4689-2f8b-ea10-2a47a5bb00cc.Prod_Datastore"
|
||||
DatastoreName = "Prod_Datastore"
|
||||
HostIdentifier = "840f99fb-4689-2f8b-ea10-2a47a5bb00cc.znest82esxus-1"
|
||||
HostVersion = 6.5
|
||||
IpAddress = 192.168.1.100
|
||||
Link = @{
|
||||
href = "https://192.168.1.200:7669/v1/vras/2609816293328110468"
|
||||
identifier = "269816293328110468"
|
||||
rel = $null
|
||||
type = "VraApi"
|
||||
}
|
||||
MemoryInGB = 3
|
||||
NetworkIdentifier = "840f99fb-4689-2f8b-ea10-2a47a5bb00cc.network-1"
|
||||
NetworkName = "Test Network"
|
||||
Progress = 0
|
||||
ProtectedCounters = @{
|
||||
Vms = 0
|
||||
Volumes = 0
|
||||
Vpgs = 0
|
||||
}
|
||||
RecoveryCounters = @{
|
||||
Vms = 0
|
||||
Volumes = 0
|
||||
Vpgs = 0
|
||||
}
|
||||
SelfProtectedVpgs = 0
|
||||
Status = 0
|
||||
VraAlerts = @{
|
||||
VraAlertStatus = 0
|
||||
}
|
||||
VraGroup = "default_group"
|
||||
VraIdentifier = 269816293328110468
|
||||
VraIdentifierStr = "269816293328110468"
|
||||
VraName = "VRA-znest82esxus-1"
|
||||
VraNetworkDataApi = @{
|
||||
DefaultGateway = "192.168.1.1"
|
||||
SubnetMask = "255.255.255.0"
|
||||
VraIpAddress = "192.168.1.100"
|
||||
VraIpConfigurationTypeApi = "Dhcp"
|
||||
}
|
||||
VraVersion = 7.0
|
||||
}
|
||||
return $vraInformation
|
||||
Mock -ModuleName ZertoApiWrapper Get-ZertoVra -ParameterFilter { $vraIdentifier -in @("MyVraIdentifier", "PasswordVraIdentifier") } {
|
||||
Get-Content $global:here\Mocks\GetSingleVra.json -Raw | ConvertFrom-Json
|
||||
}
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
Mock -ModuleName ZertoApiWrapper Get-ZertoVra -ParameterFilter { $vraIdentifier -eq "DoesNotExist" } {
|
||||
$null
|
||||
}
|
||||
|
||||
Context "$($File.BaseName)::Parameter Unit Tests" {
|
||||
Mock -ModuleName ZertoApiWrapper Get-ZertoVra -ParameterFilter { $vraIdentifier -eq "DhcpVraIdentifier" } {
|
||||
Get-Content $global:here\Mocks\GetDhcpVra.json -Raw | ConvertFrom-Json
|
||||
}
|
||||
|
||||
It "has a mandatory String variable for the vraIdentifier" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vraIdentifier -Mandatory -Type String
|
||||
{Edit-ZertoVra}
|
||||
Context "$($global:function)::Parameter Unit Tests" {
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vraIdentifier'; Type = 'String'; Mandatory = $true }
|
||||
@{ParameterName = 'groupName'; Type = 'String'; Mandatory = $false }
|
||||
@{ParameterName = 'vraIpAddress'; Type = 'String'; Mandatory = $false }
|
||||
@{ParameterName = 'defaultGateway'; Type = 'String'; Mandatory = $false }
|
||||
@{ParameterName = 'subnetMask'; Type = 'String'; Mandatory = $false }
|
||||
@{ParameterName = 'HostRootPassword'; Type = 'securestring'; Mandatory = $false }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "has a non-mandatory String variable for the Bandwidth Group" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter groupName -Not -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter groupName -Type String
|
||||
$StringTestCases = @(
|
||||
@{ ParameterName = 'vraIdentifier' }
|
||||
@{ ParameterName = 'groupName' }
|
||||
)
|
||||
|
||||
It "<ParameterName> validates against null or empty values" -TestCases $StringTestCases {
|
||||
param($ParameterName)
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
it "has a non-mandatory String variable for the staticIp Address" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Not -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Type String
|
||||
$IpAddrTestCases = @(
|
||||
@{ParameterName = 'vraIpAddress' }
|
||||
@{ParameterName = 'defaultGateway' }
|
||||
@{ParameterName = 'subnetMask' }
|
||||
)
|
||||
|
||||
It "<ParameterName> validates string for a valid IP Address" -TestCases $IpAddrTestCases {
|
||||
param($ParameterName)
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateScript] }.Count | Should -Be 1
|
||||
$attrs.Where{ $_ -is [ValidateScript] }.ScriptBlock | Should -Match '\$_ \-match \[IPAddress\]\$_'
|
||||
}
|
||||
|
||||
it "has a non-mandatory String variable for the default gateway" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Not -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Type String
|
||||
}
|
||||
|
||||
it "has a non-mandatory String variable for the subnetmask" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter subnetMask -Not -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter subnetMask -Type String
|
||||
}
|
||||
|
||||
it "supports WhatIf" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter WhatIf -Not -Mandatory
|
||||
}
|
||||
|
||||
$cases = `
|
||||
@{vraIpAddress = "192.168.1.256"}, `
|
||||
@{vraIpAddress = "192.168.1"}, `
|
||||
@{vraIpAddress = "String"}, `
|
||||
@{vraIpAddress = 192.168.1}, `
|
||||
@{vraIpAddress = 192.168.1.246}, `
|
||||
@{vraIpAddress = 32}, `
|
||||
@{vraIpAddress = ""}, `
|
||||
@{vraIpAddress = $null}
|
||||
It "IpAddress field require valid IP addresses as a String" -TestCases $cases {
|
||||
param ( $vraIpAddress )
|
||||
{Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -vraIpaddress $vraIpAddress} | Should -Throw
|
||||
}
|
||||
|
||||
$cases = `
|
||||
@{subnetMask = "192.168.1.256"}, `
|
||||
@{subnetMask = "192.168.1"}, `
|
||||
@{subnetMask = "String"}, `
|
||||
@{subnetMask = 192.168.1}, `
|
||||
@{subnetMask = 192.168.1.246}, `
|
||||
@{subnetMask = 32}, `
|
||||
@{subnetMask = ""}, `
|
||||
@{subnetMask = $null}
|
||||
It "subnetMask field require valid IP addresses as a String" -TestCases $cases {
|
||||
param ( $vraIpAddress )
|
||||
{Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -subnetMask $subnetMask} | Should -Throw
|
||||
}
|
||||
|
||||
$cases = `
|
||||
@{defaultGateway = "192.168.1.256"}, `
|
||||
@{defaultGateway = "192.168.1"}, `
|
||||
@{defaultGateway = "String"}, `
|
||||
@{defaultGateway = 192.168.1}, `
|
||||
@{defaultGateway = 192.168.1.246}, `
|
||||
@{defaultGateway = 32}, `
|
||||
@{defaultGateway = ""}, `
|
||||
@{defaultGateway = $null}
|
||||
It "defaultGateway field require valid IP addresses as a String" -TestCases $cases {
|
||||
param ( $vraIpAddress )
|
||||
{Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -defaultGateway $defaultGateway} | Should -Throw
|
||||
}
|
||||
|
||||
$cases = `
|
||||
@{vraIdentifier = ""; paramName = "vraIdentifier"; paramValue = ""}, `
|
||||
@{vraIdentifier = $null; paramName = "vraIdentifier"; paramValue = ""}, `
|
||||
@{vraIdentifier = "MyVraIdentifier"; paramName = "groupName"; paramValue = ""}, `
|
||||
@{vraIdentifier = "MyVraIdentifier"; paramName = "groupName"; paramValue = $null}, `
|
||||
@{vraIdentifier = "MyVraIdentifier"; paramName = "vraIpAddress"; paramValue = ""}, `
|
||||
@{vraIdentifier = "MyVraIdentifier"; paramName = "vraIpAddress"; paramValue = $null}, `
|
||||
@{vraIdentifier = "MyVraIdentifier"; paramName = "subnetMask"; paramValue = ""}, `
|
||||
@{vraIdentifier = "MyVraIdentifier"; paramName = "subnetMask"; paramValue = $null}, `
|
||||
@{vraIdentifier = "MyVraIdentifier"; paramName = "defaultGateway"; paramValue = ""}, `
|
||||
@{vraIdentifier = "MyVraIdentifier"; paramName = "defaultGateway"; paramValue = $null}
|
||||
|
||||
It "<paramName> does not take empty or null" -TestCases $cases {
|
||||
param($vraIdentifier, $paramValue, $paramName )
|
||||
if ([String]::IsNullOrEmpty($vraIdentifier)) {
|
||||
{Edit-ZertoVra -vraIdentifier $vraIdentifier} | Should -Throw
|
||||
} else {
|
||||
{Edit-ZertoVra -vraIdentifier $vraIdentifier -$paramName $paramValue} | should -Throw
|
||||
}
|
||||
It "Supports 'SupportsShouldProcess'" {
|
||||
Get-Command $global:function | Should -HaveParameter WhatIf
|
||||
Get-Command $global:function | Should -HaveParameter Confirm
|
||||
(Get-Command $global:function).ScriptBlock | Should -Match 'SupportsShouldProcess'
|
||||
(Get-Command $global:function).ScriptBlock | Should -Match '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
}
|
||||
}
|
||||
|
||||
Context "$($File.BaseName)::Function Unit Tests" {
|
||||
Context "$($global:function)::Function Unit Tests" {
|
||||
|
||||
It "Returns a string" {
|
||||
It "Returns a task id string" {
|
||||
$results = Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -groupName "MyGroup"
|
||||
$results | should not benullorempty
|
||||
$results | should -BeOfType "String"
|
||||
$results | Should -BeExactly "8dcfdc8e-e5d2-4ba4-9885-f9eb57d92b14.928a122b-1763-4664-ad37-cc00bb883f2f"
|
||||
$results | Should not benullorempty
|
||||
$results | Should -BeOfType "String"
|
||||
$results | Should -BeExactly "7e79035e-fb8c-47fe-815c-12ddd41708e6.3e4cdd0d-1064-4022-921f-6265ad6d335a"
|
||||
}
|
||||
|
||||
it "Supports 'SupportsShouldProcess'" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter WhatIf
|
||||
Get-Command $file.BaseName | Should -HaveParameter Confirm
|
||||
$file | Should -FileContentMatch 'SupportsShouldProcess'
|
||||
$file | Should -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
It "Throws an error when the VPG does not exist" {
|
||||
{ Edit-ZertoVra -vraIdentifier "DoesNotExist" -groupName "MyNewGroup" } | Should Throw "VRA with Identifier:"
|
||||
}
|
||||
|
||||
It "Runs when passed static IP information" {
|
||||
Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -vraIpAddress "192.168.1.250" -defaultGateway "192.168.1.254" -subnetMask "255.255.255.0"
|
||||
}
|
||||
|
||||
It "Processes a VRA with a DHCP address" {
|
||||
Edit-ZertoVra -vraIdentifier "DhcpVraIdentifier" -groupName "MyNewGroup" | Should -BeExactly "7e79035e-fb8c-47fe-815c-12ddd41708e6.3e4cdd0d-1064-4022-921f-6265ad6d335a"
|
||||
}
|
||||
|
||||
It "Runs with root password provided" {
|
||||
$SecurePassword = 'NotARealPassword' | ConvertTo-SecureString -AsPlainText -Force
|
||||
Edit-ZertoVra -vraIdentifier "PasswordVraIdentifier" -HostRootPassword $SecurePassword | Should -BeExactly "7e79035e-fb8c-47fe-815c-12ddd41708e6.3e4cdd0d-1064-4022-921f-6265ad6d335a"
|
||||
}
|
||||
|
||||
}
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVra
|
||||
}
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -Exactly 4
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVra -Exactly 5
|
||||
}
|
||||
|
||||
Remove-Variable -Name function -Scope Global
|
||||
Remove-Variable -Name here -Scope Global
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#Requires -Modules Pester
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'OutputFile'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'vpgName'; Type = 'String[]'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> has <Validation> validation set" -TestCases $ParameterTestCases {
|
||||
param($ParameterName)
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Function Unit Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name function -Scope Global
|
||||
Remove-Variable -Name here -Scope Global
|
||||
@@ -1,53 +1,39 @@
|
||||
#Requires -Modules Pester
|
||||
#Region - Test Setup
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
#EndRegion
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
it "has a mantatory string parameter for the output path" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter outputPath -Type String -Mandatory
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'OutputPath'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'vpgName'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'allVpgs'; Type = 'Switch'; Mandatory = $true; Validation = $null }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type, with correct validation" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
it "has a non-mandatory string array parameter for vpgName(s) to export" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Type String[] -Mandatory
|
||||
}
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
it "has a non-mandatory switch parameter to export all vpgs" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter allVpgs -Type Switch -Mandatory
|
||||
}
|
||||
|
||||
it "No defined vpgName or AllVpg switch should throw an error" {
|
||||
{Export-ZertoVpg -outputPath "."} | Should -Throw
|
||||
}
|
||||
|
||||
it "Output path does not take null or empty string" {
|
||||
{Export-ZertoVpg -outputPath "" -allVpgs} | Should -Throw
|
||||
{Export-ZertoVpg -outputPath $null -allVpgs} | Should -Throw
|
||||
}
|
||||
|
||||
it "Vpg Name parameter does not take null or empty string" {
|
||||
{Export-ZertoVpg -outputPath "." -vpgName = ""} | Should -Throw
|
||||
{Export-ZertoVpg -outputPath "." -vpgName = $null} | Should -Throw
|
||||
$null {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.TypeId.Count | Should -Be 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Function Unit Tests" {
|
||||
Context "$($global:function)::Function Unit Tests" {
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpg {
|
||||
$returnObj = @{
|
||||
VpgName = "HRIS"
|
||||
@@ -60,6 +46,10 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
return "1024d377-afb8-4880-82f0-96eeff413ffd"
|
||||
}
|
||||
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Remove-ZertoVpgSettingsIdentifier {
|
||||
return $null
|
||||
}
|
||||
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpgSetting {
|
||||
$returnObj = @{
|
||||
Backup = $null
|
||||
@@ -213,11 +203,11 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
|
||||
$outputPath = "TestDrive:"
|
||||
|
||||
it "Output path should exist" {
|
||||
It "Output path should exist" {
|
||||
$outputPath | Should -Exist
|
||||
}
|
||||
|
||||
it "Exported JSON file should exist after function called" {
|
||||
It "Exported JSON file should exist after function called" {
|
||||
$vpgName = "HRIS"
|
||||
Export-ZertoVpg -outputPath $outputPath -vpgName $vpgName
|
||||
$outputFile = "{0}\{1}.json" -f $outputPath, $vpgName
|
||||
@@ -225,11 +215,11 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
$outputFile | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
|
||||
it "Only one file should be present in the TestDrive" {
|
||||
It "Only one file should be present in the TestDrive" {
|
||||
(Get-ChildItem $outputPath).Count | Should -BeExactly 1
|
||||
}
|
||||
|
||||
it "Should be valid JSON" {
|
||||
It "Should be valid JSON" {
|
||||
$vpgName = "HRIS"
|
||||
Export-ZertoVpg -outputPath $outputPath -vpgName $vpgName
|
||||
$outputFile = "{0}\{1}.json" -f $outputPath, $vpgName
|
||||
@@ -247,3 +237,6 @@ Describe $file.BaseName -Tag 'Unit' {
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpgSetting
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name function -Scope Global
|
||||
Remove-Variable -Name here -Scope Global
|
||||
|
||||
@@ -1,19 +1,58 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'limitTo'; Type = 'int'; Mandatory = $false; Validation = 'Range' }
|
||||
@{ParameterName = 'alertIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "LimitTo Parameter should have a Min value of 1" {
|
||||
(Get-Command $global:function).Parameters['limitTo'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 1
|
||||
}
|
||||
|
||||
It "LimitTo Parameter should have a Max value of 1000000" {
|
||||
(Get-Command $global:function).Parameters['limitTo'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 1000000
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,44 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'datastoreIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'clusterIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'siteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,77 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
It "$global:function should have exactly 16 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 16
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'limitTo'; Type = 'int'; Mandatory = $false; Validation = 'Range' }
|
||||
@{ParameterName = 'category'; Type = 'String'; Mandatory = $false; Validation = 'Set' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Set' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "LimitTo Parameter should have a Min value of 1" {
|
||||
(Get-Command $global:function).Parameters['limitTo'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 1
|
||||
}
|
||||
|
||||
It "LimitTo Parameter should have a Max value of 1000000" {
|
||||
(Get-Command $global:function).Parameters['limitTo'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 1000000
|
||||
}
|
||||
|
||||
It "Category parameter should only have 2 options" {
|
||||
(Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues.Count | Should -Be 2
|
||||
}
|
||||
|
||||
It "Category parameter should take 'events'" {
|
||||
(Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'events'
|
||||
}
|
||||
|
||||
It "Category parameter should take 'alertsHistory'" {
|
||||
(Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'alertsHistory'
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,59 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
It "$global:function should have exactly 15 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 15
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Min value of 60" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 60
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Max value of 2678400" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 2678400
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,58 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 15 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 15
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Min value of 60" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 60
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Max value of 2678400" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 2678400
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,44 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,44 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,58 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 15 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 15
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Min value of 60" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 60
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Max value of 2678400" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 2678400
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,58 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 15 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 15
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Min value of 60" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 60
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Max value of 2678400" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 2678400
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,58 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 15 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 15
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Min value of 60" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 60
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Max value of 2678400" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 2678400
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,58 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 15 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 15
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Min value of 60" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 60
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Max value of 2678400" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 2678400
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,58 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 15 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 15
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Min value of 60" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 60
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Max value of 2678400" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 2678400
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,44 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,44 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,44 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 11 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 11
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 12 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 12
|
||||
}
|
||||
|
||||
It "$global:function has a non-mandatory string parameter for the zOrgIdentifier" {
|
||||
Get-Command $global:function | Should -HaveParameter zOrgIdentifier -Type String
|
||||
Get-Command $global:function | Should -HaveParameter zOrgIdentifier -not -Mandatory
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,60 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 17 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 17
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'protectedSiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Min value of 60" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 60
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Max value of 2678400" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 2678400
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,60 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 17 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 17
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'protectedSiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Min value of 60" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 60
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Max value of 2678400" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 2678400
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,51 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 16 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 16
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'protectedSiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,51 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 16 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 16
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'protectedSiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'recoverySiteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,58 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 15 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 15
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Min value of 60" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 60
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Max value of 2678400" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 2678400
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,58 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 15 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 15
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Min value of 60" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 60
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Max value of 2678400" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 2678400
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,49 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,49 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#Requires -Modules Pester
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 17 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 17
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'siteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'vmIdentifier'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'recoveryType'; Type = 'String'; Mandatory = $true; Validation = 'Set' }
|
||||
@{ParameterName = 'desiredJournalHistory'; Type = 'Int'; Mandatory = $false; Validation = 'Range' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Set' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
@@ -0,0 +1,57 @@
|
||||
#Requires -Modules Pester
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 17 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 17
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'siteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'vmIdentifier'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'recoveryType'; Type = 'String'; Mandatory = $true; Validation = 'Set' }
|
||||
@{ParameterName = 'interval'; Type = 'Int'; Mandatory = $false; Validation = 'Range' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Set' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
@@ -0,0 +1,42 @@
|
||||
#Requires -Modules Pester
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 12 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 12
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'siteIdentifier'; Type = 'String[]'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
@@ -0,0 +1,57 @@
|
||||
#Requires -Modules Pester
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 17 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 17
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'siteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'vmIdentifier'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'recoveryType'; Type = 'String'; Mandatory = $true; Validation = 'Set' }
|
||||
@{ParameterName = 'desiredJournalHistory'; Type = 'Int'; Mandatory = $false; Validation = 'Range' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Set' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
@@ -0,0 +1,56 @@
|
||||
#Requires -Modules Pester
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 16
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'siteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'vmIdentifier'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'recoveryType'; Type = 'String'; Mandatory = $true; Validation = 'Set' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Set' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
@@ -0,0 +1,56 @@
|
||||
#Requires -Modules Pester
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 16 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 16
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'siteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'vmIdentifier'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'recoveryType'; Type = 'String'; Mandatory = $true; Validation = 'Set' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Set' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
@@ -0,0 +1,41 @@
|
||||
#Requires -Modules Pester
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'AllVms'; Type = 'Switch'; Mandatory = $false; Validation = $Null }
|
||||
@{ParameterName = 'vmIdentifier'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'Volumes'; Type = 'Switch'; Mandatory = $false; Validation = $Null }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
@@ -0,0 +1,39 @@
|
||||
#Requires -Modules Pester
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 12 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 12
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vmIdentifier'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
@@ -1,19 +1,44 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,58 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 15 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 15
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'Interval'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Min value of 60" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 60
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Max value of 2678400" {
|
||||
(Get-Command $global:function).Parameters['Interval'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 2678400
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,44 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,44 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,44 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,44 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,28 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 12 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 12
|
||||
}
|
||||
|
||||
It "zOrgIdentifier Parameter should be present and of 'String' Type" {
|
||||
Get-Command $global:function | Should -HaveParameter zOrgIdentifier -Type String -Mandatory:$false
|
||||
}
|
||||
|
||||
It "zOrgIdentifier has the NotNullOrEmpty Validator" {
|
||||
(Get-Command $global:function).Parameters['zOrgIdentifier'].Attributes.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,44 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,42 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 12 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 12
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,57 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'limitTo'; Type = 'Int'; Mandatory = $false; Validation = 'Range' }
|
||||
@{ParameterName = 'taskIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Min value of 1" {
|
||||
(Get-Command $global:function).Parameters['limitTo'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 1
|
||||
}
|
||||
|
||||
It "Interval Parameter should have a Max value of 1000000" {
|
||||
(Get-Command $global:function).Parameters['limitTo'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 1000000
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,45 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 15 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 15
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'siteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'clusterIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'datastoreIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,43 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 13 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 13
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 11 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 11
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,84 +1,51 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'alertId'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'entities'; Type = 'Switch'; Mandatory = $false; Validation = $null }
|
||||
@{ParameterName = 'helpIdentifiers'; Type = 'Switch'; Mandatory = $false; Validation = $null }
|
||||
@{ParameterName = 'levels'; Type = 'Switch'; Mandatory = $false; Validation = $null }
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'siteIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'level'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'helpIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'isDismissed'; Type = 'bool'; Mandatory = $false; Validation = $null }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
$null {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.TypeId.Count | Should -Be 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
it "Has a mandatory string parameter for the Alert identifier" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter alertId
|
||||
Get-Command $file.BaseName | Should -HaveParameter alertId -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter alertId -Type String[]
|
||||
}
|
||||
|
||||
it "Has a non-mandatory switch parameter for the entities" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter entities
|
||||
Get-Command $file.BaseName | Should -HaveParameter entities -Type switch
|
||||
}
|
||||
|
||||
it "Has a non-mandatory switch parameter for the helpIdentifiers" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter helpIdentifiers
|
||||
Get-Command $file.BaseName | Should -HaveParameter helpIdentifiers -Type switch
|
||||
}
|
||||
|
||||
it "Has a non-mandatory switch parameter for the levels" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter levels
|
||||
Get-Command $file.BaseName | Should -HaveParameter levels -Type switch
|
||||
}
|
||||
|
||||
it "Has a non-mandatory string parameter for the startDate" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter startDate
|
||||
Get-Command $file.BaseName | Should -HaveParameter startDate -Type string
|
||||
}
|
||||
|
||||
it "Has a non-mandatory string parameter for the endDate" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter endDate
|
||||
Get-Command $file.BaseName | Should -HaveParameter endDate -Type string
|
||||
}
|
||||
|
||||
it "Has a non-mandatory string parameter for the vpgIdentifier" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgIdentifier
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgIdentifier -Type string
|
||||
}
|
||||
|
||||
it "Has a non-mandatory string parameter for the siteIdentifier" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter siteIdentifier
|
||||
Get-Command $file.BaseName | Should -HaveParameter siteIdentifier -Type string
|
||||
}
|
||||
|
||||
it "Has a non-mandatory string parameter for the zorgIdentifier" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter zorgIdentifier
|
||||
Get-Command $file.BaseName | Should -HaveParameter zorgIdentifier -Type string
|
||||
}
|
||||
|
||||
it "Has a non-mandatory string parameter for the level" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter level
|
||||
Get-Command $file.BaseName | Should -HaveParameter level -Type string
|
||||
}
|
||||
|
||||
it "Has a non-mandatory string parameter for the helpIdentifier" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter helpIdentifier
|
||||
Get-Command $file.BaseName | Should -HaveParameter helpIdentifier -Type string
|
||||
}
|
||||
|
||||
it "Has a non-mandatory bool parameter for the isDismissed" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter isDismissed
|
||||
Get-Command $file.BaseName | Should -HaveParameter isDismissed -Type bool
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,24 +1,25 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
It "has a non-mandatory string parameter for the datacenterIdentifier" {
|
||||
Get-Command $global:function | Should -HaveParameter datastoreIdentifier
|
||||
Get-Command $global:function | Should -HaveParameter datastoreIdentifier -Type String[]
|
||||
}
|
||||
|
||||
It "datastoreIdentifier parameter does not take null or empty values" {
|
||||
(Get-Command $global:function).Parameters['datastoreIdentifier'].Attributes.Where{ $_ -is [ValidateNotNullOrEmpty] }.count | Should -Be 1
|
||||
}
|
||||
}
|
||||
|
||||
It "has a non-mandatory string parameter for the datacenterIdentifier" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter datastoreIdentifier
|
||||
Get-Command $file.BaseName | Should -HaveParameter datastoreIdentifier -Type String[]
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,120 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -Leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 28 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 28
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'startDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'endDate'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'vpg'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'eventType'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'siteName'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'siteIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'zOrgIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'entityType'; Type = 'String'; Mandatory = $false; Validation = 'Set' }
|
||||
@{ParameterName = 'userName'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'category'; Type = 'String'; Mandatory = $false; Validation = 'Set' }
|
||||
@{ParameterName = 'eventCategory'; Type = 'String'; Mandatory = $false; Validation = 'Set' }
|
||||
@{ParameterName = 'alertIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'eventId'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'categories'; Type = 'Switch'; Mandatory = $true; Validation = $null }
|
||||
@{ParameterName = 'entities'; Type = 'Switch'; Mandatory = $true; Validation = $null }
|
||||
@{ParameterName = 'types'; Type = 'Switch'; Mandatory = $true; Validation = $null }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Set' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
$null {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.TypeId.Count | Should -Be 2
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "entityType parameter only accecpts 4 different values" {
|
||||
(Get-Command $global:function).Parameters['entityType'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues.Count | Should -Be 4
|
||||
}
|
||||
|
||||
It "entityType parameter accecpts 'VPG' as a Value" {
|
||||
(Get-Command $global:function).Parameters['entityType'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'VPG'
|
||||
}
|
||||
|
||||
It "entityType parameter accecpts 'VRA' as a Value" {
|
||||
(Get-Command $global:function).Parameters['entityType'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'VRA'
|
||||
}
|
||||
|
||||
It "entityType parameter accecpts 'Unknown' as a Value" {
|
||||
(Get-Command $global:function).Parameters['entityType'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'Unknown'
|
||||
}
|
||||
|
||||
It "entityType parameter accecpts 'Site' as a Value" {
|
||||
(Get-Command $global:function).Parameters['entityType'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'Site'
|
||||
}
|
||||
|
||||
It "category parameter only accecpts 3 different values" {
|
||||
(Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues.Count | Should -Be 3
|
||||
}
|
||||
|
||||
It "category parameter accecpts 'All' as a Value" {
|
||||
(Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'All'
|
||||
}
|
||||
|
||||
It "category parameter accecpts 'events' as a Value" {
|
||||
(Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'events'
|
||||
}
|
||||
|
||||
It "category parameter accecpts 'alerts' as a Value" {
|
||||
(Get-Command $global:function).Parameters['category'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'alerts'
|
||||
}
|
||||
|
||||
It "eventCategory parameter only accecpts 3 different values" {
|
||||
(Get-Command $global:function).Parameters['eventCategory'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues.Count | Should -Be 3
|
||||
}
|
||||
|
||||
It "eventCategory parameter accecpts 'All' as a Value" {
|
||||
(Get-Command $global:function).Parameters['eventCategory'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'All'
|
||||
}
|
||||
|
||||
It "eventCategory parameter accecpts 'events' as a Value" {
|
||||
(Get-Command $global:function).Parameters['eventCategory'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'events'
|
||||
}
|
||||
|
||||
It "eventCategory parameter accecpts 'alerts' as a Value" {
|
||||
(Get-Command $global:function).Parameters['eventCategory'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'alerts'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 11 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 11
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,27 +1,24 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 12 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 12
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
|
||||
it "Has a non-mandatory switch parameter for the pairing Statuses" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter pairingstatuses
|
||||
Get-Command $file.BaseName | Should -HaveParameter pairingstatuses -Type switch
|
||||
It "Has a non-mandatory switch parameter for the pairing Statuses" {
|
||||
Get-Command $global:function | Should -HaveParameter pairingstatuses
|
||||
Get-Command $global:function | Should -HaveParameter pairingstatuses -Type switch
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,53 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 18 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 18
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'pairingStatuses'; Type = 'Switch'; Mandatory = $true; Validation = $null }
|
||||
@{ParameterName = 'siteIdentifier'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'peerName'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'paringStatus'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'location'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'hostName'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'port'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
$null {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.TypeId.Count | Should -Be 2
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,261 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
BeforeAll {
|
||||
$script:ScriptBlock = (Get-Command $global:function).ScriptBlock
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 23 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 23
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'siteIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'hostIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'folders'; Type = 'Switch'; Mandatory = $true; Validation = $Null }
|
||||
@{ParameterName = 'hostClusters'; Type = 'Switch'; Mandatory = $true; Validation = $Null }
|
||||
@{ParameterName = 'hosts'; Type = 'Switch'; Mandatory = $true; Validation = $Null }
|
||||
@{ParameterName = 'networks'; Type = 'Switch'; Mandatory = $true; Validation = $Null }
|
||||
@{ParameterName = 'resourcePools'; Type = 'Switch'; Mandatory = $true; Validation = $Null }
|
||||
@{ParameterName = 'vms'; Type = 'Switch'; Mandatory = $true; Validation = $Null }
|
||||
@{ParameterName = 'repositories'; Type = 'Switch'; Mandatory = $true; Validation = $Null }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting of <Validation>" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Validation)
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
Switch ($Validation) {
|
||||
|
||||
'NotNullOrEmpty' {
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
$Null {
|
||||
$Type -match 'Switch' | Should -BeTrue -Because "Only Switch Parameters should not have validation"
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -BeFalse -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
It "$($global:function) does not have 'SupportsShouldProcess'" {
|
||||
Get-Command $global:function | Should -not -HaveParameter WhatIf
|
||||
Get-Command $global:function | Should -not -HaveParameter Confirm
|
||||
$script:ScriptBlock | Should -not -match 'SupportsShouldProcess'
|
||||
$script:ScriptBlock | Should -not -match '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites'
|
||||
} {
|
||||
return (Get-Content "$global:here\Mocks\VirtualSite-NoParams.json" -Raw) | ConvertFrom-Json
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/devices'
|
||||
} {
|
||||
return (Get-Content "$global:here\Mocks\VirtualSite-devices.json" -Raw) | ConvertFrom-Json
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/devices?hostIdentifier=4567'
|
||||
} {
|
||||
return (Get-Content "$global:here\Mocks\VirtualSite-devices-hostid.json" -Raw) | ConvertFrom-Json
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/hosts'
|
||||
} {
|
||||
return (Get-Content "$global:here\Mocks\VirtualSite-hosts.json" -Raw) | ConvertFrom-Json
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/hosts/4567'
|
||||
} {
|
||||
return (Get-Content "$global:here\Mocks\VirtualSite-hosts-hostid.json" -Raw) | ConvertFrom-Json
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234'
|
||||
} {
|
||||
return (Get-Content "$global:here\Mocks\VirtualSite-SiteId.json" -Raw) | ConvertFrom-Json
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/datastores'
|
||||
} {
|
||||
return (Get-Content "$global:here\Mocks\VirtualSite-datastores.json" -Raw) | ConvertFrom-Json
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/datastoreclusters'
|
||||
} {
|
||||
return (Get-Content "$global:here\Mocks\VirtualSite-datastoreClusters.json" -Raw) | ConvertFrom-Json
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/networks'
|
||||
} {
|
||||
return (Get-Content "$global:here\Mocks\VirtualSite-Networks.json" -Raw) | ConvertFrom-Json
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/folders'
|
||||
} {
|
||||
return (Get-Content "$global:here\Mocks\VirtualSite-Folders.json" -Raw) | ConvertFrom-Json
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/hostclusters'
|
||||
} {
|
||||
return (Get-Content "$global:here\Mocks\VirtualSite-hostClusters.json" -Raw) | ConvertFrom-Json
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/resourcepools'
|
||||
} {
|
||||
return (Get-Content "$global:here\Mocks\VirtualSite-ResourcePools.json" -Raw) | ConvertFrom-Json
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/vms'
|
||||
} {
|
||||
return (Get-Content "$global:here\Mocks\VirtualSite-VMs.json" -Raw) | ConvertFrom-Json
|
||||
} -Verifiable
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/repositories'
|
||||
} {
|
||||
return (Get-Content "$global:here\Mocks\VirtualSite-repositories.json" -Raw) | ConvertFrom-Json
|
||||
} -Verifiable
|
||||
|
||||
It "Should return all known sites when called without parameters" {
|
||||
$results = Get-ZertoVirtualizationSite
|
||||
$results.Count | Should -BeExactly 2
|
||||
}
|
||||
|
||||
It "Should return a single site when a siteIdentifier is provided" {
|
||||
$results = Get-ZertoVirtualizationSite -siteIdentifier '1234'
|
||||
$results.VirtualizationSiteName | Should -BeExactly 'cavc.nc.lab'
|
||||
$results.siteIdentifier | Should -BeExactly '8e1c9f53-4973-4a4a-b2dd-1ebb293614d8'
|
||||
}
|
||||
|
||||
It "Should return a list of devices with the '-devices' switch" {
|
||||
$results = Get-ZertoVirtualizationSite -siteIdentifier '1234' -devices
|
||||
$results.Count | Should -BeExactly 5
|
||||
}
|
||||
|
||||
It "Should return a list of devices with the '-devices' switch and hostIdentifier provided" {
|
||||
$results = Get-ZertoVirtualizationSite -siteIdentifier '1234' -devices -hostIdentifier '4567'
|
||||
$results.Count | Should -BeExactly 5
|
||||
}
|
||||
|
||||
It "Should return a list of hosts with the '-hosts' switch" {
|
||||
$results = Get-ZertoVirtualizationSite -siteIdentifier '1234' -hosts
|
||||
$results.Count | Should -BeExactly 3
|
||||
}
|
||||
|
||||
It "Should return a single host with the '-hosts' switch and hostIdentifier provided" {
|
||||
$results = Get-ZertoVirtualizationSite -siteIdentifier '1234' -hosts -hostIdentifier '4567'
|
||||
$results.VirtualizationHostName | Should -BeExactly "caesx3.nc.lab"
|
||||
$results.hostIdentifier | Should -BeExactly "09db6c5b-b956-430f-9589-b58876ca377a.host-18"
|
||||
}
|
||||
|
||||
It "Should return a list of datastores with the '-datastores' switch" {
|
||||
$results = Get-ZertoVirtualizationSite -siteIdentifier '1234' -datastores
|
||||
$results.Count | Should -BeExactly 8
|
||||
}
|
||||
|
||||
It "Should return a list of datastores with the '-datastoreClusters' switch" {
|
||||
$results = Get-ZertoVirtualizationSite -siteIdentifier '1234' -datastoreClusters
|
||||
$results.DatastoreClusterIdentifier | Should -BeExactly "09db6c5b-b956-430f-9589-b58876ca377a.group-p44"
|
||||
$results.DatastoreClusterName | Should -BeExactly "CA_DS_Cluster"
|
||||
}
|
||||
|
||||
It "Should return a list of Networks with the '-networks' switch" {
|
||||
$results = Get-ZertoVirtualizationSite -siteIdentifier '1234' -networks
|
||||
$results.NetworkIdentifier | Should -BeExactly "09db6c5b-b956-430f-9589-b58876ca377a.network-20"
|
||||
$results.VirtualizationNetworkName | Should -BeExactly "VM Network"
|
||||
}
|
||||
|
||||
It "Should return a list of folders with the '-folders' switch" {
|
||||
$results = Get-ZertoVirtualizationSite -siteIdentifier '1234' -folders
|
||||
$results.Count | Should -BeExactly 3
|
||||
}
|
||||
|
||||
It "Should return a list of Host Clusters with the '-hostClusters' switch" {
|
||||
$results = Get-ZertoVirtualizationSite -siteIdentifier '1234' -hostClusters
|
||||
$results.ClusterIdentifier | Should -BeExactly "09db6c5b-b956-430f-9589-b58876ca377a.domain-c7"
|
||||
$results.VirtualizationClusterName | Should -BeExactly "CA Cluster"
|
||||
}
|
||||
|
||||
It "Should return a list of Resource Pools with the '-resourcePools' switch" {
|
||||
$results = Get-ZertoVirtualizationSite -siteIdentifier '1234' -resourcePools
|
||||
$results.ResourcePoolIdentifier | Should -BeExactly "09db6c5b-b956-430f-9589-b58876ca377a.resgroup-8"
|
||||
$results.ResourcePoolName | Should -BeExactly "Resources"
|
||||
}
|
||||
|
||||
It "Should return a list of VMs with the '-VMs' switch" {
|
||||
$results = Get-ZertoVirtualizationSite -siteIdentifier '1234' -vms
|
||||
$results.Count | Should -BeExactly 4
|
||||
}
|
||||
|
||||
It "Should return a list of LTR Repositories with the '-repositories' switch" {
|
||||
$results = Get-ZertoVirtualizationSite -siteIdentifier '1234' -repositories
|
||||
$results.ConnectionType | Should -BeExactly "ServerMessageBlock"
|
||||
$results.RepositoryIdentifier | Should -BeExactly "120355ce-fcd0-4820-a971-787d0470793b"
|
||||
$results.RepositoryName | Should -BeExactly "Synology"
|
||||
$results.StorageType | Should -BeExactly "NetworkShare"
|
||||
$results.Path | Should -not -be $null
|
||||
}
|
||||
|
||||
Assert-VerifiableMock
|
||||
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites'
|
||||
} -Exactly 1
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234'
|
||||
} -Exactly 1
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/devices'
|
||||
} -Exactly 1
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/devices?hostIdentifier=4567'
|
||||
} -Exactly 1
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/hosts'
|
||||
} -Exactly 1
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/hosts/4567'
|
||||
} -Exactly 1
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/datastores'
|
||||
} -Exactly 1
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/datastoreclusters'
|
||||
} -Exactly 1
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/networks'
|
||||
} -Exactly 1
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/folders'
|
||||
} -Exactly 1
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/hostclusters'
|
||||
} -Exactly 1
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/resourcepools'
|
||||
} -Exactly 1
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/vms'
|
||||
} -Exactly 1
|
||||
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -ParameterFilter {
|
||||
$uri -eq 'virtualizationsites/1234/repositories'
|
||||
} -Exactly 1
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#Requires -Modules Pester
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 11 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
It "Has a mandatory string array parameter for the settings file to import" {
|
||||
Get-Command $global:function | Should -HaveParameter InputFile
|
||||
Get-Command $global:function | Should -HaveParameter InputFile -Mandatory
|
||||
Get-Command $global:function | Should -HaveParameter InputFile -Type String
|
||||
}
|
||||
|
||||
It "Will not accecpt a Null or Empty string for the settings file" {
|
||||
$attrs = (Get-Command $global:function).Parameters['InputFile'].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
@@ -1,39 +1,30 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 12 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 12
|
||||
}
|
||||
|
||||
It "Has a mandatory string array parameter for the settings file to import" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter settingsFile
|
||||
Get-Command $file.BaseName | Should -HaveParameter settingsFile -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter settingsFile -Type String[]
|
||||
Get-Command $global:function | Should -HaveParameter settingsFile
|
||||
Get-Command $global:function | Should -HaveParameter settingsFile -Mandatory
|
||||
Get-Command $global:function | Should -HaveParameter settingsFile -Type String[]
|
||||
}
|
||||
|
||||
It "Will not accecpt a Null or Empty string for the settings file" {
|
||||
{Import-ZertoVpg -settingsFile $null} | Should -Throw
|
||||
{Import-ZertoVpg -settingsFile ""} | Should -Throw
|
||||
{Import-ZertoVpg -settingsFile @()} | Should -Throw
|
||||
$attrs = (Get-Command $global:function).Parameters['settingsFile'].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Function Unit Tests" {
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,108 +1,57 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 24 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 24
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'hostName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'datastoreName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'networkName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'Dhcp'; Type = 'Switch'; Mandatory = $true; Validation = $null }
|
||||
@{ParameterName = 'vraIpAddress'; Type = 'String'; Mandatory = $true; Validation = 'IpAddr' }
|
||||
@{ParameterName = 'subnetMask'; Type = 'String'; Mandatory = $true; Validation = 'IpAddr' }
|
||||
@{ParameterName = 'defaultGateway'; Type = 'String'; Mandatory = $true; Validation = 'IpAddr' }
|
||||
@{ParameterName = 'UseRootCredential'; Type = 'Switch'; Mandatory = $true; Validation = $null }
|
||||
@{ParameterName = 'HostRootPassword'; Type = 'SecureString'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'IpAddr' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateScript] }.Count | Should -Be 1
|
||||
$attrs.Where{ $_ -is [ValidateScript] }.ScriptBlock | Should -Match '\$_ \-match \[IPAddress\]\$_'
|
||||
}
|
||||
|
||||
$null {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.TypeId.Count | Should -Be 3
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
It "Has a mandatory string host name parameter" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter hostName
|
||||
Get-Command $file.BaseName | Should -HaveParameter hostName -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter hostName -Type String
|
||||
}
|
||||
|
||||
It "Will not accecpt a Null or Empty string for the host name" {
|
||||
{Install-ZertoVra -hostName $null -datastoreName "DS01" -networkName "MyNetwork" -Dhcp } | Should -Throw "The argument is null or empty"
|
||||
{Install-ZertoVra -hostName "" -datastoreName "DS01" -networkName "MyNetwork" -Dhcp } | Should -Throw "The argument is null or empty"
|
||||
}
|
||||
|
||||
It "Has a mandatory string datastore parameter" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter datastoreName
|
||||
Get-Command $file.BaseName | Should -HaveParameter datastoreName -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter datastoreName -Type String
|
||||
}
|
||||
|
||||
It "Will not accecpt a Null or Empty string for the datastore" {
|
||||
{Install-ZertoVra -hostName "MyfirstHost" -datastoreName $null -networkName "MyNetwork" -Dhcp } | Should -Throw "The argument is null or empty"
|
||||
{Install-ZertoVra -hostName "MyfirstHost" -datastoreName "" -networkName "MyNetwork" -Dhcp } | Should -Throw "The argument is null or empty"
|
||||
}
|
||||
|
||||
It "Has a mandatory string network parameter" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter networkName
|
||||
Get-Command $file.BaseName | Should -HaveParameter networkName -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter networkName -Type String
|
||||
}
|
||||
|
||||
It "Will not accecpt a Null or Empty string for the datastore" {
|
||||
{Install-ZertoVra -hostName "MyfirstHost" -datastoreName "DS01" -networkName $null -Dhcp } | Should -Throw "The argument is null or empty"
|
||||
{Install-ZertoVra -hostName "MyfirstHost" -datastoreName "DS01" -networkName "" -Dhcp } | Should -Throw "The argument is null or empty"
|
||||
}
|
||||
|
||||
it "Has a switch parameter for setting DHCP" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter Dhcp
|
||||
Get-Command $file.BaseName | Should -HaveParameter Dhcp -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter Dhcp -Type 'Switch'
|
||||
|
||||
}
|
||||
|
||||
it "Has a mandatory string parameter for the static IP address" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vraIpAddress
|
||||
Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Type String
|
||||
}
|
||||
|
||||
it "Has a mandatory string parameter for the subnet mask" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter subnetMask
|
||||
Get-Command $file.BaseName | Should -HaveParameter subnetMask -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter subnetMask -Type String
|
||||
}
|
||||
|
||||
it "Has a mandatory string parameter for the default gateway" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter defaultGateway
|
||||
Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Type String
|
||||
}
|
||||
|
||||
$cases = `
|
||||
@{invalidIpAddress = "192.168.1.256"}, `
|
||||
@{invalidIpAddress = "192.168.1"}, `
|
||||
@{invalidIpAddress = "String"}, `
|
||||
@{invalidIpAddress = 192.168.1.246}, `
|
||||
@{invalidIpAddress = 32}, `
|
||||
@{invalidIpAddress = ""}, `
|
||||
@{invalidIpAddress = $null}
|
||||
It "IpAddress field require valid IP addresses as a String: <invalidIpAddress>" -TestCases $cases {
|
||||
param ( $invalidIpAddress )
|
||||
{Install-ZertoVra -hostName "MyFirstHost" -datastoreName "DS01" -networkName "MyNetwork" -vraIpAddress $invalidIpAddress -subnetMask "255.255.255.0" -defaultGateway "192.168.1.254"} | Should -Throw
|
||||
}
|
||||
|
||||
It "Default Gateway field require valid IP addresses as a String: <invalidIpAddress>" -TestCases $cases {
|
||||
param ( $invalidIpAddress )
|
||||
{Install-ZertoVra -hostName "MyFirstHost" -datastoreName "DS01" -networkName "MyNetwork" -vraIpAddress '192.168.1.100' -subnetMask "255.255.255.0" -defaultGateway $invalidIpAddress} | Should -Throw
|
||||
}
|
||||
|
||||
It "Subnet Mask field require valid IP addresses as a String: <invalidIpAddress>" -TestCases $cases {
|
||||
param ( $invalidIpAddress )
|
||||
{Install-ZertoVra -hostName "MyFirstHost" -datastoreName "DS01" -networkName "MyNetwork" -vraIpAddress '192.168.1.100' -subnetMask $invalidIpAddress -defaultGateway "192.168.1.254"} | Should -Throw
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Function Unit Tests" {
|
||||
#TODO
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
#Requires -Modules Pester
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
InModuleScope -ModuleName ZertoApiWrapper {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
$testCases = @(
|
||||
@{ParameterName = 'uri'; Type = 'String'; Mandatory = $true; TestName = 'URI' }
|
||||
@{ParameterName = 'method'; Type = 'String'; Mandatory = $false; TestName = 'Method' }
|
||||
@{ParameterName = 'body'; Type = 'String'; Mandatory = $false; TestName = 'Body' }
|
||||
)
|
||||
|
||||
It "Parameter present and Type test for: <TestName> " -TestCases $testCases {
|
||||
param($parameterName, $type, $Mandatory)
|
||||
Get-Command $global:function | Should -HaveParameter $parameterName -Type $type
|
||||
if ($Mandatory) {
|
||||
Get-Command $global:function | Should -HaveParameter $parameterName -Mandatory
|
||||
} else {
|
||||
Get-Command $global:function | Should -HaveParameter $parameterName -Not -Mandatory
|
||||
}
|
||||
}
|
||||
|
||||
It "Method parameter default is 'GET'" {
|
||||
Get-Command $global:function | Should -HaveParameter Method -DefaultValue "GET"
|
||||
}
|
||||
|
||||
$NotNullOrEmptyTests = @(
|
||||
@{ParameterName = 'uri'; TestName = 'Uri' }
|
||||
@{ParameterName = 'body'; TestName = 'Body' }
|
||||
)
|
||||
|
||||
It "<TestName> parameter does not accecpt a null or empty value" -TestCases $NotNullOrEmptyTests {
|
||||
param($parameterName)
|
||||
$parameterInfo = ( Get-Command Invoke-ZARestRequest ).Parameters[$parameterName]
|
||||
$parameterInfo.Attributes.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
It "method parametert only accecpts 'GET' 'DELETE' 'PUT' 'POST' values" {
|
||||
$parameterInfo = ( Get-Command Invoke-ZARestRequest ).Parameters['method']
|
||||
$parameterInfo.Attributes.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1
|
||||
$validateSet = $parameterInfo.Attributes.Where{ $_ -is [ValidateSet] }
|
||||
$validateSet.ValidValues -contains 'GET' | Should -BeTrue
|
||||
$validateSet.ValidValues -contains 'PUT' | Should -BeTrue
|
||||
$validateSet.ValidValues -contains 'POST' | Should -BeTrue
|
||||
$validateSet.ValidValues -contains 'DELETE' | Should -BeTrue
|
||||
$validateSet.ValidValues.Count | Should -Be 4
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Function Unit Tests" {
|
||||
|
||||
Mock -ModuleName ZertoApiWrapper -CommandName Invoke-RestMethod {
|
||||
"Ran Command"
|
||||
}
|
||||
|
||||
BeforeEach {
|
||||
Set-Variable -Name zaHeaders -Scope Script -Value (@{ "Accept" = "application/json" })
|
||||
Set-Variable -Name zaLastActionTime -Scope Script -Value $(Get-Date).Ticks
|
||||
}
|
||||
|
||||
It "runs when called" {
|
||||
Invoke-ZARestRequest -uri "myuri" | Should -Be "Ran Command"
|
||||
}
|
||||
|
||||
It "throws when the last action was over 60 minutes ago" {
|
||||
$script:zaLastActionTime = (Get-Date).AddMinutes(-61).Ticks
|
||||
{ Invoke-ZARestRequest -uri "myuri" } | Should Throw "Authorization Token has Expired."
|
||||
}
|
||||
|
||||
It "throws when the zaHeaders variable does not exits" {
|
||||
Remove-Variable -Name zaHeaders -Scope Script
|
||||
{ Invoke-ZARestRequest -uri "myuri" } | Should Throw "Zerto Analytics Connection does not Exist."
|
||||
}
|
||||
|
||||
It "throws when the zaLastActionTime variable does not exist" {
|
||||
Remove-Variable -Name zaLastActionTime -Scope Script
|
||||
{ Invoke-ZARestRequest -uri "myuri" } | Should Throw "Zerto Analytics Connection does not Exist."
|
||||
}
|
||||
|
||||
Assert-MockCalled -CommandName Invoke-RestMethod -ModuleName ZertoApiWrapper -Exactly 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name function -Scope Global
|
||||
Remove-Variable -Name here -Scope Global
|
||||
@@ -0,0 +1,54 @@
|
||||
#Requires -Modules Pester
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 16 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 16
|
||||
}
|
||||
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'hostName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty'; ParameterSet = @('hostName') }
|
||||
@{ParameterName = 'vraName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' ; ParameterSet = @('vraName') }
|
||||
@{ParameterName = 'vraIdentifier'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' ; ParameterSet = @('vraIdentifier') }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
$null {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.TypeId.Count | Should -Be 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter is part of the correct ParameterSet(s)" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $ParameterSet)
|
||||
$commandParameterSets = (Get-Command $global:function).Parameters[$ParameterName].ParameterSets
|
||||
foreach ($Set in $ParameterSet) {
|
||||
$commandParameterSets.ContainsKey($Set) | Should -BeTrue
|
||||
}
|
||||
$commandParameterSets.Count | Should -Be $ParameterSet.Count
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
@@ -1,77 +1,101 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
it "has a mandatory string parameter for the vpgName" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Type string
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 20 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 20
|
||||
}
|
||||
|
||||
it "has a non-mandatory string parameter for the checkpoint" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter checkpointIdentifier
|
||||
Get-Command $file.BaseName | Should -HaveParameter checkpointIdentifier -Type string
|
||||
Get-Command $file.BaseName | Should -HaveParameter checkpointIdentifier -Not -Mandatory
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'checkpointIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'commitPolicy'; Type = 'String'; Mandatory = $false; Validation = 'Set' }
|
||||
@{ParameterName = 'shutdownPolicy'; Type = 'Int'; Mandatory = $false; Validation = 'Set' }
|
||||
@{ParameterName = 'timeToWaitBeforeShutdownInSec'; Type = 'Int'; Mandatory = $false; Validation = 'Range' }
|
||||
@{ParameterName = 'reverseProtection'; Type = 'bool'; Mandatory = $false; Validation = $null }
|
||||
@{ParameterName = 'vmName'; Type = 'String[]'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'whatIf'; Type = 'Switch'; Mandatory = $false; Validation = 'ShouldProcess' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
it "has a non-mandatory string parameter for the commit policy" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter commitPolicy
|
||||
Get-Command $file.BaseName | Should -HaveParameter commitPolicy -Type string
|
||||
Get-Command $file.BaseName | Should -HaveParameter commitPolicy -Not -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter commitPolicy -DefaultValue "Rollback"
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Set' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'ShouldProcess' {
|
||||
$scriptBlock = (Get-Command $global:function).ScriptBlock
|
||||
$scriptBlock | Should -match 'SupportsShouldProcess'
|
||||
$scriptBlock | Should -match '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
}
|
||||
|
||||
$null {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.TypeId.Count | Should -Be 2
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
it "has a non-mandatory int parameter for the shutdown policy" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter shutdownPolicy
|
||||
Get-Command $file.BaseName | Should -HaveParameter shutdownPolicy -Type int
|
||||
Get-Command $file.BaseName | Should -HaveParameter shutdownPolicy -Not -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter shutdownPolicy -DefaultValue 0
|
||||
It "Commit Policy Default Value is 'RollBack'" {
|
||||
Get-Command $global:function | Should -HaveParameter commitPolicy -DefaultValue "Rollback"
|
||||
}
|
||||
|
||||
it "has a non-mandatory int parameter for the time to wait before force shutdown" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter timeToWaitBeforeShutdownInSec
|
||||
Get-Command $file.BaseName | Should -HaveParameter timeToWaitBeforeShutdownInSec -Type int
|
||||
Get-Command $file.BaseName | Should -HaveParameter timeToWaitBeforeShutdownInSec -Not -Mandatory
|
||||
Get-Command $file.BaseName | Should -HaveParameter timeToWaitBeforeShutdownInSec -DefaultValue 3600
|
||||
It "Commit Policy Only Accecpts 'RollBack', 'Commit', or 'None'" {
|
||||
(Get-Command $global:function).Parameters['commitPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -HaveCount 3
|
||||
(Get-Command $global:function).Parameters['commitPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'RollBack'
|
||||
(Get-Command $global:function).Parameters['commitPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'Commit'
|
||||
(Get-Command $global:function).Parameters['commitPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'None'
|
||||
}
|
||||
|
||||
it "has a non-mandatory bool parameter for the reverse protection policy" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter reverseProtection
|
||||
Get-Command $file.BaseName | Should -HaveParameter reverseProtection -Type bool
|
||||
Get-Command $file.BaseName | Should -HaveParameter reverseProtection -Not -Mandatory
|
||||
It "Shutdown Policy Default Value is '0'" {
|
||||
Get-Command $global:function | Should -HaveParameter shutdownPolicy -DefaultValue 0
|
||||
}
|
||||
|
||||
it "has a non-mandatory array string parameter for the named VMs to be failed over" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vmName
|
||||
Get-Command $file.BaseName | Should -HaveParameter vmName -Type string[]
|
||||
Get-Command $file.BaseName | Should -HaveParameter vmName -Not -Mandatory
|
||||
It "Shutdown Policy Only Accecpts 'RollBack', 'Commit', or 'None'" {
|
||||
(Get-Command $global:function).Parameters['shutdownPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -HaveCount 3
|
||||
(Get-Command $global:function).Parameters['shutdownPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 0
|
||||
(Get-Command $global:function).Parameters['shutdownPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 1
|
||||
(Get-Command $global:function).Parameters['shutdownPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 2
|
||||
}
|
||||
|
||||
it "Supports 'SupportsShouldProcess'" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter WhatIf
|
||||
Get-Command $file.BaseName | Should -HaveParameter Confirm
|
||||
$file | Should -FileContentMatch 'SupportsShouldProcess'
|
||||
$file | Should -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
It "Time to wait before shutdown in sec should have a default value of 3600" {
|
||||
Get-Command $global:function | Should -HaveParameter timeToWaitBeforeShutdownInSec -DefaultValue 3600
|
||||
}
|
||||
|
||||
It "Time to wait before shutdown in sec should have a minimum value of 300 and max value of 86400" {
|
||||
(Get-Command $global:function).Parameters['timeToWaitBeforeShutdownInSec'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 300
|
||||
(Get-Command $global:function).Parameters['timeToWaitBeforeShutdownInSec'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 86400
|
||||
}
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Function Unit Tests" {
|
||||
#TODO
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,44 +1,56 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
|
||||
it "Supports 'ShouldProcess'" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter WhatIf
|
||||
Get-Command $file.BaseName | Should -HaveParameter Confirm
|
||||
$file | Should -FileContentMatch 'SupportsShouldProcess'
|
||||
$file | Should -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
It "$global:function should have exactly 15 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 15
|
||||
}
|
||||
|
||||
it "has a mandatory string parameter for the vpgName" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Type string[]
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgName'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'reverseProtection'; Type = 'switch'; Mandatory = $false; Validation = $null }
|
||||
@{ParameterName = 'whatIf'; Type = 'Switch'; Mandatory = $false; Validation = 'ShouldProcess' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
it "has a switch parameter for reverse protection" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter reverseProtection
|
||||
Get-Command $file.BaseName | Should -HaveParameter reverseProtection -Type switch
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'ShouldProcess' {
|
||||
$scriptBlock = (Get-Command $global:function).ScriptBlock
|
||||
$scriptBlock | Should -match 'SupportsShouldProcess'
|
||||
$scriptBlock | Should -match '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
}
|
||||
|
||||
$null {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.TypeId.Count | Should -Be 2
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Function Unit Tests" {
|
||||
#TODO
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,28 +1,25 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 12 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 12
|
||||
}
|
||||
|
||||
it "has a mandatory string parameter for the vpgName" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Type string[]
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory
|
||||
It "has a mandatory string parameter for the vpgName" {
|
||||
Get-Command $global:function | Should -HaveParameter vpgName
|
||||
Get-Command $global:function | Should -HaveParameter vpgName -Type string[]
|
||||
Get-Command $global:function | Should -HaveParameter vpgName -Mandatory
|
||||
}
|
||||
}
|
||||
}
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,28 +1,26 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 12 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 12
|
||||
}
|
||||
|
||||
it "has a mandatory string parameter for the vpgName" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Type string[]
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory
|
||||
It "has a mandatory string parameter for the vpgName" {
|
||||
Get-Command $global:function | Should -HaveParameter vpgName
|
||||
Get-Command $global:function | Should -HaveParameter vpgName -Type string[]
|
||||
Get-Command $global:function | Should -HaveParameter vpgName -Mandatory
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,74 +1,83 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
|
||||
it "has a mandatory string parameter for the vpgName" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Type string[]
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 21 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 21
|
||||
}
|
||||
|
||||
it "has a non-mandatory string parameter for commitPolicy" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter commitPolicy
|
||||
Get-Command $file.BaseName | Should -HaveParameter commitPolicy -Type string
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgIdentifier'; Type = 'Guid[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'vpgName'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'commitPolicy'; Type = 'String'; Mandatory = $false; Validation = 'Set' }
|
||||
@{ParameterName = 'commitPolicyTimeout'; Type = 'Int'; Mandatory = $false; Validation = 'Range' }
|
||||
@{ParameterName = 'forceShutdown'; Type = 'Switch'; Mandatory = $false; Validation = $null }
|
||||
@{ParameterName = 'disableReverseProtection'; Type = 'Switch'; Mandatory = $false; Validation = $null }
|
||||
@{ParameterName = 'keepSourceVms'; Type = 'Switch'; Mandatory = $false; Validation = $null }
|
||||
@{ParameterName = 'ContinueOnPreScriptFailure'; Type = 'Switch'; Mandatory = $false; Validation = $null }
|
||||
@{ParameterName = 'whatIf'; Type = 'Switch'; Mandatory = $false; Validation = 'ShouldProcess' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
it "CommitPolicy only accecpts 'Rollback', 'Commit', or 'None'" {
|
||||
{ Invoke-ZertoMove -vpgName "MyVpg" -commitPolicy "Rollbackk" } | Should -Throw
|
||||
{ Invoke-ZertoMove -vpgName "MyVpg" -commitPolicy "" } | Should -Throw
|
||||
{ Invoke-ZertoMove -vpgName "MyVpg" -commitPolicy $null } | Should -Throw
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Set' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateSet] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'Range' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'ShouldProcess' {
|
||||
$scriptBlock = (Get-Command $global:function).ScriptBlock
|
||||
$scriptBlock | Should -match 'SupportsShouldProcess'
|
||||
$scriptBlock | Should -match '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
}
|
||||
|
||||
$null {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.TypeId.Count | Should -Be 2
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
it "has a non-mandatory int parameter for commitPolicyTimeout" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter commitPolicyTimeout
|
||||
Get-Command $file.BaseName | Should -HaveParameter commitPolicyTimeout -Type Int
|
||||
It "Commit Policy Only Accecpts 'RollBack', 'Commit', or 'None'" {
|
||||
(Get-Command $global:function).Parameters['commitPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -HaveCount 3
|
||||
(Get-Command $global:function).Parameters['commitPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'RollBack'
|
||||
(Get-Command $global:function).Parameters['commitPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'Commit'
|
||||
(Get-Command $global:function).Parameters['commitPolicy'].Attributes.Where{ $_ -is [ValidateSet] }.ValidValues | Should -Contain 'None'
|
||||
}
|
||||
|
||||
it "Commit Policy Timeout will only accecpt an int value between 5 minutes and 24 Hours" {
|
||||
{ Invoke-ZertoMove -vpgName "MyVpg" -commitPolicyTimeout 150 } | Should -Throw
|
||||
{ Invoke-ZertoMove -vpgName "MyVpg" -commitPolicyTimeout 15000000 } | Should -Throw
|
||||
{ Invoke-ZertoMove -vpgName "MyVpg" -commitPolicyTimeout -1350 } | Should -Throw
|
||||
{ Invoke-ZertoMove -vpgName "MyVpg" -commitPolicyTimeout $null } | Should -Throw
|
||||
{ Invoke-ZertoMove -vpgName "MyVpg" -commitPolicyTimeout "" } | Should -Throw
|
||||
}
|
||||
|
||||
it "has a non-mandatory switch parameter for forceShutdown" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter forceShutdown
|
||||
Get-Command $file.BaseName | Should -HaveParameter forceShutdown -Type Switch
|
||||
}
|
||||
|
||||
it "has a mandatory switch parameter for disableReverseProtection" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter disableReverseProtection
|
||||
Get-Command $file.BaseName | Should -HaveParameter disableReverseProtection -Type Switch
|
||||
Get-Command $file.BaseName | Should -HaveParameter disableReverseProtection -Mandatory
|
||||
}
|
||||
|
||||
it "has a non-mandatory switch parameter for keepSourceVms" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter keepSourceVms
|
||||
Get-Command $file.BaseName | Should -HaveParameter keepSourceVms -Type Switch
|
||||
Get-Command $file.BaseName | Should -HaveParameter keepSourceVms -Mandatory
|
||||
}
|
||||
|
||||
it "has a non-mandatory switch parameter for ContinueOnPreScriptFailure" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter ContinueOnPreScriptFailure
|
||||
Get-Command $file.BaseName | Should -HaveParameter ContinueOnPreScriptFailure -Type Switch
|
||||
It "Commit Policy Timeout should have a minimum value of 300 and max value of 86400" {
|
||||
(Get-Command $global:function).Parameters['commitPolicyTimeout'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should -Be 300
|
||||
(Get-Command $global:function).Parameters['commitPolicyTimeout'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should -Be 86400
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,28 +1,56 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 16 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 16
|
||||
}
|
||||
|
||||
it "has a mandatory string parameter for the vpgName" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Type string[]
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory
|
||||
$ParameterTestCases = @(
|
||||
@{ParameterName = 'vpgName'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' }
|
||||
@{ParameterName = 'reverseProtection'; Type = 'switch'; Mandatory = $false; Validation = $null }
|
||||
@{ParameterName = 'whatIf'; Type = 'Switch'; Mandatory = $false; Validation = 'ShouldProcess' }
|
||||
)
|
||||
|
||||
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Type, $Mandatory, $Validation)
|
||||
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
|
||||
}
|
||||
|
||||
It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
|
||||
param($ParameterName, $Validation)
|
||||
Switch ($Validation) {
|
||||
'NotNullOrEmpty' {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
|
||||
}
|
||||
|
||||
'ShouldProcess' {
|
||||
$scriptBlock = (Get-Command $global:function).ScriptBlock
|
||||
$scriptBlock | Should -match 'SupportsShouldProcess'
|
||||
$scriptBlock | Should -match '\$PSCmdlet\.ShouldProcess\(.+\)'
|
||||
}
|
||||
|
||||
$null {
|
||||
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
|
||||
$attrs.TypeId.Count | Should -Be 2
|
||||
}
|
||||
|
||||
default {
|
||||
$true | Should -Be $false -Because "No Validation Selected. Review test cases"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
@@ -1,28 +1,25 @@
|
||||
#Requires -Modules Pester
|
||||
$moduleFileName = "ZertoApiWrapper.psd1"
|
||||
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper")
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
$file = Get-ChildItem "$here\$sut"
|
||||
$modulePath = $here -replace "Public", ""
|
||||
$moduleFile = Get-ChildItem "$modulePath\$moduleFileName"
|
||||
Get-Module -Name ZertoApiWrapper | Remove-Module -Force
|
||||
Import-Module $moduleFile -Force
|
||||
$global:here = (Split-Path -Parent $PSCommandPath)
|
||||
$global:function = ((Split-Path -leaf $PSCommandPath).Split('.'))[0]
|
||||
|
||||
Describe $file.BaseName -Tag 'Unit' {
|
||||
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
|
||||
It "is valid Powershell (Has no script errors)" {
|
||||
$contents = Get-Content -Path $file -ErrorAction Stop
|
||||
$errors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
|
||||
$errors | Should -HaveCount 0
|
||||
}
|
||||
Context "$global:function::Parameter Unit Tests" {
|
||||
|
||||
Context "$($file.BaseName)::Parameter Unit Tests" {
|
||||
It "$global:function should have exactly 14 parameters defined" {
|
||||
(Get-Command $global:function).Parameters.Count | Should -Be 14
|
||||
}
|
||||
|
||||
it "has a mandatory string parameter for the vpgName" {
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Type string[]
|
||||
Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory
|
||||
It "has a mandatory string parameter for the vpgName" {
|
||||
Get-Command $global:function | Should -HaveParameter vpgName
|
||||
Get-Command $global:function | Should -HaveParameter vpgName -Type string[]
|
||||
Get-Command $global:function | Should -HaveParameter vpgName -Mandatory
|
||||
}
|
||||
}
|
||||
}
|
||||
Context "$global:function::Parameter Functional Tests" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Variable -Name here -Scope Global
|
||||
Remove-Variable -Name function -Scope Global
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user