diff --git a/.gitattributes b/.gitattributes index 69dc8aae..daee888f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,20 +2,23 @@ CHANGELOG.md merge=union # Set default behaviour, in case users don't have core.autocrlf set. -* text=auto eol=crlf +* text=auto -# Explicitly declare text files we want to always be normalized and converted -# to native line endings on checkout. -*.md text -*.gitattributes text -*.ps1 text -*.psm1 text -*.psd1 text -*.psc1 text -*.ps1xml text -*.clixml text -*.xml text -*.txt text +# Explicitly declare text files we want to always be normalized. +*.md text eol=crlf +*.gitattributes text eol=crlf +*.gitignore text eol=crlf +*.ps1 text eol=crlf +*.psm1 text eol=crlf +*.psd1 text eol=crlf +*.psc1 text eol=crlf +*.ps1xml text eol=crlf +*.clixml text eol=crlf +*.cs text eol=crlf +*.xml text eol=crlf +*.yml text eol=crlf +*.txt text eol=crlf +*.json text eol=crlf # Denote all files that are truly binary and should not be mergeable. *.dll binary diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index d3340f73..00000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,32 +0,0 @@ - - -### Expected Behavior - - - -### Current Behavior - - - -### Possible Solution - - - -### Steps to Reproduce (for bugs) - -1. -2. -3. -4. - -### Context - - - -### Your Environment - - -> ```powershell -> Get-Module JiraPS -ListAvailable | select version -> $PSVersionTable -> ``` diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 55303de3..af558991 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,22 +1,30 @@ + + ### Description + ### Motivation and Context + ### Types of changes + + - [ ] 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: +### Checklist + + - [ ] My code follows the code style of this project. - [ ] I have added Pester Tests that describe what my changes should do. - [ ] I have updated the documentation accordingly. diff --git a/.gitignore b/.gitignore index 226dc35f..379130b3 100644 --- a/.gitignore +++ b/.gitignore @@ -6,15 +6,16 @@ config.xml # except for git files !.gitattributes !.gitignore +!.editorconfig +!.spelling !.github/ !.vscode/ !.travis.yml # Ignore Release directory generated by local builds Release/ -Tools/*.exe JiraPS/en-US/ -TestResult.xml +Test*.xml ####### # Excerpts from https://www.gitignore.io @@ -32,6 +33,3 @@ ehthumbs.db # Folder config file Desktop.ini - -#Vim Junk -.swp diff --git a/.spelling b/.spelling index d85578c7..9e271276 100644 --- a/.spelling +++ b/.spelling @@ -1,205 +1,48 @@ -AppVeyor +// AtlassianPS Atlassian Atlassian's -atlassianps.org -atlassianps.slack.com -behavior -behaviors -booleans -CAPTCHA -cmd -cmdlet -cmdlets -color -colors -config -config.xml -datacenter -env -exe -github -hashtable -hashtables -hotfix -img -IssueLink Jira -JIRA -jira-screen-createissue -JIRA's -JiraPS -jql -json -MSI -multiselect -OAuth -PackageManagement -param -png -PoshCode -powershell -PowerShell -powershell.exe -PowerShellGet -projectCategory -ps1 -PSGallery -PSJira -PSModulePath -ReadTheDocs -vscode -WindowsPowerShell -worklog -# Commands -Add-JiraGroupMember -Add-JiraIssueComment -Add-JiraIssueLink -Add-JiraIssueWatcher -Add-JiraIssueWorklog -ConvertFrom-Json2 -ConvertTo-JiraComment -ConvertTo-JiraComponent -ConvertTo-JiraCreateMetaField -ConvertTo-JiraEditMetaField -ConvertTo-JiraField -ConvertTo-JiraFilter -ConvertTo-JiraGroup -ConvertTo-JiraIssue -ConvertTo-JiraIssueLink -ConvertTo-JiraIssueLinkType -ConvertTo-JiraIssueType -ConvertTo-JiraLink -ConvertTo-JiraPriority -ConvertTo-JiraProject -ConvertTo-JiraSession -ConvertTo-JiraStatus -ConvertTo-JiraTransition -ConvertTo-JiraUser -ConvertTo-JiraWorklogItem -Format-Jira -Get-JiraComponent -Get-JiraConfigServer -Get-JiraField -Get-JiraFilter -Get-JiraGroup -Get-JiraGroupMember -Get-JiraIssue -Get-JiraIssueComment -Get-JiraIssueCreateMetadata -Get-JiraIssueEditMetadata -Get-JiraIssueLink -Get-JiraIssueLinkType -Get-JiraIssueType -Get-JiraIssueWatcher -Get-JiraPriority -Get-JiraProject -Get-JiraRemoteLink -Get-JiraSession -Get-JiraUser -Invoke-JiraIssueTransition -Invoke-JiraMethod -New-JiraGroup -New-JiraIssue -New-JiraSession -New-JiraUser -Remove-JiraGroup -Remove-JiraGroupMember -Remove-JiraIssueLink -Remove-JiraIssueWatcher -Remove-JiraRemoteLink -Remove-JiraSession -Remove-JiraUser -Resolve-JiraError -Set-JiraConfigServer -Set-JiraIssue -Set-JiraIssueLabel -Set-JiraUser - -# Data Types -Int -JiraPS.Comment -JiraPS.Component -JiraPS.CreateMetaField -JiraPS.Field -JiraPS.Filter -JiraPS.Group -JiraPS.Issue -JiraPS.IssueLink -JiraPS.IssueLinkType -JiraPS.IssueType -JiraPS.IssueType -JiraPS.Link -JiraPS.Priority -JiraPS.Project -JiraPS.Session -JiraPS.Transition -JiraPS.User -JiraPS.Watchers -PSCredential -PSCustomObject -System.Management.Automation.PSObject -System.Object -System.String - -# Parameters -AllowedValues -ComponentId -ConfigFile -ContentType -DateStarted -DisplayName -EmailAddress -FixVersion -GroupName -IncludeDebug -IncludeInactive -InputObject -IssueType -LinkType -MaxJsonLength -MaxResults -PageSize -PassThru -SecureString -StartIndex -TimeSpent -VisibleRole -WhatIf -WriteError +// Module specific +worklog +timespan +multipart +captcha -# Methods -ToString -# ParameterSets -ByFilter -ByFilterID -ByGroupName -ByHashtable -ById -ByInputObject -ByIssueKey -ByJQL -ByNamedParameters -ByProject -ByUserName -ClearLabels -ModifyLabels -ReplaceLabels -ReturnError -WebResponse +// Powershell +pwsh +cmdlet +cmdlets +recurse +hashtable +posh +Passthru +EXTERNALHELP -# User Names -alexsuslin -axxelG +// Person/Username +lipkau +bunke brianbunke +thomykay +juneb +alexsuslin +axxel +beaudryj +clijsters colhal dejulia489 ebekker jkknorr kittholland -LiamLeane -lipkau +liam +leane lukhase padgers -ThePSAdmin +JohnAdders +hmmwhatsthisdo + +// misc +markdownlint +veyor +pandoc diff --git a/.vscode/extensions.json b/.vscode/extensions.json index f4b2d754..c54ae4a6 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -3,6 +3,7 @@ // for the documentation about the extensions.json format "recommendations": [ "ms-vscode.PowerShell", - "DavidAnson.vscode-markdownlint" + "DavidAnson.vscode-markdownlint", + "streetsidesoftware.code-spell-checker" ] } diff --git a/.vscode/launch.json b/.vscode/launch.json index 08bc1516..95377687 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,53 +1,34 @@ { "version": "0.2.0", - "configurations": [ - { + "configurations": [{ "type": "PowerShell", "request": "launch", - "name": "PowerShell Launch Current File", - "script": "${file}", + "name": "PowerShell Pester Tests", + "script": ".\\.env.ps1", + "script": "Invoke-Pester", "args": [], - "cwd": "${file}" + "cwd": "${workspaceRoot}" }, { "type": "PowerShell", "request": "launch", - "name": "PowerShell Launch Current File in Temporary Console", + "name": "PowerShell Launch (current file)", "script": "${file}", "args": [], - "cwd": "${file}", - "createTemporaryIntegratedConsole": true - }, - { - "type": "PowerShell", - "request": "launch", - "name": "PowerShell Launch Current File w/Args Prompt", - "script": "${file}", - "args": [ - "${command:SpecifyScriptArgs}" - ], "cwd": "${file}" }, { "type": "PowerShell", - "request": "launch", - "name": "PowerShell Interactive Session", - "cwd": "${workspaceRoot}" + "request": "attach", + "name": "PowerShell Attach to Host Process", + "processId": "${command.PickPSHostProcess}", + "runspaceId": 1 }, { "type": "PowerShell", "request": "launch", - "name": "PowerShell Pester Tests", - "script": "Invoke-Pester", - "args": [], + "name": "PowerShell Interactive Session", "cwd": "${workspaceRoot}" - }, - { - "type": "PowerShell", - "request": "attach", - "name": "PowerShell Attach to Host Process", - "processId": "${command:PickPSHostProcess}", - "runspaceId": 1 } ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 3558e98e..5c174b11 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -28,6 +28,14 @@ "MD025": false, "MD028": false }, + "cSpell.dictionaryDefinitions": [{ + "name": "customDictionary", + "path": "./.spelling" + }], + "cSpell.dictionaries": [ + "customDictionary" + ], + "cSpell.language": "en" // Recomendations for "USER SETTINGS": // "editor.formatOnType": true, diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c494f58..7c4d3b07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,10 @@ # Change Log -## 2.8 - 2018-06-28 +## [2.8] - 2018-06-28 More detailed description about the changes can be found on [Our Website](https://atlassianps.org/article/announcement/JiraPS-v2.8.html). -### IMPROVEMENTS +### Changed - Added support for paginated response from API server by means of `-Paging` (#291, [@lipkau[]]) - Added full set of functions to manage Filter Permissions (#289, [@lipkau[]]) @@ -16,26 +16,26 @@ More detailed description about the changes can be found on [Our Website](https: - Added `Remove-JiraIssue` (#265, [@hmmwhatsthisdo[]]) - Improved Build script (to deploy changes to the homepage) (#259, [@lipkau[]]) -### BUG FIXES +### Fixed -- Reverted `Add-JiraIssueAttachament` as JiraPS v2.7 broke it (#287, [@lipkau[]]) +- Reverted `Add-JiraIssueAttachment` as JiraPS v2.7 broke it (#287, [@lipkau[]]) - Fixed resolving of Remote Link (#286, [@lipkau[]]) - Improved error handling for ErrorDetails and non-JSON/HTML responses (#277, [@hmmwhatsthisdo[]]) - Fully support Powershell v3 (#273, [@lipkau[]]) - Fixed parameter used in documentation but not in code (#263, [@lipkau[]]) -## 2.7 - 2018-05-13 +## [2.7] - 2018-05-13 More detailed description about the changes can be found on [Our Website](https://atlassianps.org/article/announcement/JiraPS-v2.7.html). -### IMPROVEMENTS +### Changed - Writing and throwing of errors show better context (#199, [@lipkau][]) - Improved validation of parameters in `Add-JiraGroupMember` (#250, [@WindowsAdmin92][]) - Improved casting to `-Fields` by defining it's type as `[PSCustomObject]` (#255, [@lipkau][]) - Several improvements to the CI pipeline (#252, #257, [@lipkau][]) -### BUG FIXES +### Fixed - Build script was not publishing to the PSGallery (#252, [@lipkau][]) - Build script was publishing a new tag to repository even in case the build failed (#252, [@lipkau][]) @@ -43,23 +43,23 @@ More detailed description about the changes can be found on [Our Website](https: - Fixed CI icon in README (#245, [@lipkau][]) - Allow `Get-JiraUser` to return more than 1 result (#246, [@lipkau][]) -## 2.6 - 2018-05-02 +## [2.6] - 2018-05-02 More detailed description about the changes can be found on [Our Website](https://atlassianps.org/article/announcement/JiraPS-v2.6.html). -### FEATURES +### Added -- Added `-Passthru` parameter to `Invoke-JiraIssueTransition` (#239, [@lipkau][]) -- Added `Get-JiraUser` functionality to find the current user (#231, [@lipkau][]) -- Added full support for PowerShell Core (v6) and Linux/MacOS support (#230, [@lipkau][]) -- Added JiraPS documentation on the homepage (#230, [@lipkau][]) +- `-Passthru` parameter to `Invoke-JiraIssueTransition` (#239, [@lipkau][]) +- `Get-JiraUser` functionality to find the current user (#231, [@lipkau][]) +- full support for PowerShell Core (v6) and Linux/MacOS support (#230, [@lipkau][]) +- JiraPS documentation on the homepage (#230, [@lipkau][]) -### IMPROVEMENTS +### Changed - Exposed `Invoke-JiraMethod` as a public function (#233, [@lipkau][]) - Migrated to External Help (instead of Comment-Based Help) (#230, [@lipkau][]) -### BUG FIXES +### Fixed - Index Into Null Object (#209, [@lipkau][]) - Fix empty header (#206, [@lipkau][]) @@ -68,11 +68,11 @@ More detailed description about the changes can be found on [Our Website](https: - Fix removing labels with `Set-JiraIssueLabel -Remove` (#244, [lipkau][]) - Fix adding of multiple labels at once with `Set-JiraIssueLabel -Add` (#244, [lipkau][]) -## 2.5 - 2018-03-23 +## [2.5] - 2018-03-23 More detailed description about the changes can be found on [Our Website](https://atlassianps.org/article/announcement/JiraPS-v2.5.html). -### IMPROVEMENTS +### Changed - Harmonized code style (#162, [@lipkau][]) - Harmonized verbose messages (#162, [@lipkau][]) @@ -89,43 +89,43 @@ More detailed description about the changes can be found on [Our Website](https: - Fixed _date_ and _timespan_ representation in _Body_ of `Add-JiraIssueWorklog` (#214, [@lipkau][]) - Improved output of `Get-JiraProject` (#216, [@lipkau][]) -## 2.4 (Nov 01, 2017) +## [2.4] (Nov 01, 2017) -### FEATURES +### Added - `Add-JiraIssueAttachment`: Add an attachment to an issue (#137, [@beaudryj][]) - `Get-JiraIssueAttachment`: Get attachments from issues (#137, [@beaudryj][]) - `Remove-JiraIssueAttachment`: Remove attachments from issues (#137, [@beaudryj][]) -### IMPROVEMENTS +### Changed - `JiraPS.Issue` now has a property for Attachments `JiraPS.Attachment` (#137, [@beaudryj][]) -## 2.3 (Okt 07, 2017) +## [2.3] (Okt 07, 2017) -### FEATURES +### Added - `Get-JiraServerInformation`: Fetches the information about the server (#187, [@lipkau][]) -### IMPROVEMENTS +### Changed - Added `-AddComment` to `Set-JiraIssue`. Allowing the user to write a comment for the changes to the issue (#167, [@Clijsters][]) - Changed the default visibility of comments (#172, [@lipkau][]) - Added more properties to `JiraPS.User` objects (#152, [@lipkau][]) -## 2.2.0 (Aug 05, 2017) +## [2.2].0 (Aug 05, 2017) -### FEATURES +### Added -- `New-JiraVerion`: Create a new Version in a project (#158, [@Dejulia489][]) -- `Get-JiraVerion`: Get Versions of a project (#158, [@Dejulia489][]) -- `Set-JiraVerion`: Changes a Version of a project (#158, [@Dejulia489][]) -- `Remove-JiraVerion`: Removes a Version of a project (#158, [@Dejulia489][]) +- `New-JiraVersion`: Create a new Version in a project (#158, [@Dejulia489][]) +- `Get-JiraVersion`: Get Versions of a project (#158, [@Dejulia489][]) +- `Set-JiraVersion`: Changes a Version of a project (#158, [@Dejulia489][]) +- `Remove-JiraVersion`: Removes a Version of a project (#158, [@Dejulia489][]) - New custom object for Versions (#158, [@Dejulia489][]) -## 2.1.0 (Jul 25, 2017) +## [2.1].0 (Jul 25, 2017) -### FEATURES +### Added - `Get-JiraIssueEditMetadata`: Returns metadata required to create an issue in JIRA (#65, [@lipkau][]) - `Get-JiraRemoteLink`: Returns a remote link from a JIRA issue (#80, [@lipkau][]) @@ -135,7 +135,7 @@ More detailed description about the changes can be found on [Our Website](https: - Added support for getting and managing Issue Watchers (`Add-JiraIssueWatcher`, `Get-JiraIssueWatcher`, `Remove-JiraIssueWatcher`) (#73, [@ebekker][]) - Added IssueLink functionality (`Add-JiraIssueLink`, `Get-JiraIssueLink`, `Get-JiraIssueLinkType`, `Remove-JiraIssueLink`) (#131, [@lipkau][]) -### IMPROVEMENTS +### Changed - `New-JiraIssue`: _Description_ and _Priority_ are no longer mandatory (#53, [@brianbunke][]) - Added property `Components` to `PSjira.Project` (#68, [@axxelG][]) @@ -147,14 +147,14 @@ More detailed description about the changes can be found on [Our Website](https: - Switched to _Basic Authentication_ when generating the session (#116, [@lipkau][]) - Added more tests for the CI (#142, [@lipkau][]) -### BUG FIXES +### Fixed - `Invoke-JiraMethod`: Error when Invoke-WebRequest returns '204 No content' (#42, [@colhal][]) - `Invoke-JiraIssueTransition`: Error when Invoke-WebRequest returns '204 No content' (#43, [@colhal][]) - `Set-JiraIssueLabel`: Forced label property to be an array (#88, [@kittholland][]) - `Invoke-JiraMethod`: Send ContentType as Parameter instead of in the Header (#121, [@lukhase][]) -## 2.0.0 (Jun 24, 2017) +## [2.0].0 (Jun 24, 2017) ### Changes to the code module @@ -162,14 +162,14 @@ More detailed description about the changes can be found on [Our Website](https: - Rename of the module to `JiraPS` **breaking change** - Rename of module's custom objects to `JiraPS.*` **breaking change** -## 1.2.5 (Aug 08, 2016) +## [1.2].5 (Aug 08, 2016) -### IMPROVEMENTS +### Changed - New-JiraIssue: Priority and Description are no longer mandatory (#24, @lipkau) - New-JiraIssue: Added -Parent parameter for sub-tasks (#29, @ebekker) -### BUG FIXES +### Fixed - ConvertTo-JiraProject: updated for Atlassian's minor wording change of projectCategory (#31, @alexsuslin) - Invoke-JiraMethod: now uses the -ContentType parameter instead of manually passing the Content-Type header (#19) @@ -177,86 +177,86 @@ More detailed description about the changes can be found on [Our Website](https: - Set-JiraIssue: fixed issue with JSON depth for custom parameters (#17, @ThePSAdmin) - Various: Fixed issues with ConvertFrom-Json max length with a custom ConvertFrom-Json function (#23, @LiamLeane) -## 1.2.4 (Dec 10, 2015) +## [1.2].4 (Dec 10, 2015) -### IMPROVEMENTS +### Changed - Get-JiraGroupMember: now returns all members by default, with support for -MaxResults and -StartIndex parameters (#14) - Get-JiraIssue: significantly increased performance (#12) -### BUG FIXES +### Fixed - Get-JiraIssue: fixed issue where Get-JiraIssue would only return one result when using -Filter parameter in some cases (#15) - Invoke-JiraIssueTransition: fixed -Credential parameter (#13) -## 1.2.3 (Dec 02, 2015) +## [1.2].3 (Dec 02, 2015) -### FEATURES +### Added - Get-JiraIssue: added paging support with the -StartIndex and -PageSize parameters. This allows programmatically looping through all issues that match a given search. (#9) -### IMPROVEMENTS +### Changed - Get-JiraIssue: default behavior has been changed to return all issues via paging when using -Query or -Filter parameters -### BUG FIXES +### Fixed - Invoke-JiraMethod: Fixed issue where non-standard characters were not being parsed correctly from JSON (#7) -## 1.2.2 (Nov 16, 2015) +## [1.2].2 (Nov 16, 2015) -### FEATURES +### Added - Set-JiraIssueLabel: add and remove specific issue labels, or overwrite or clear all labels on an issue (#5) -### IMPROVEMENTS +### Changed - New-JiraIssue: now has a -Label parameter - Set-JiraIssue: now has a -Label parameter (this replaces all labels on an issue; use Set-JiraIssueLabel for more fine-grained control) - Invoke-JiraMethod: handles special UTF-8 characters correctly (#4) -### BUG FIXES +### Fixed - Get-JiraIssueCreateMetadata: now correctly returns the ID of fields as well (#6) -## 1.2.1 (Oct 26, 2015) +## [1.2].1 (Oct 26, 2015) -### IMPROVEMENTS +### Changed - Get-JiraIssueCreateMetadata: changed output type from a generic PSCustomObject to new type PSJira.CreateMetaField - Get-JiraIssueCreateMetadata: now returns additional properties for field metadata, such as AllowedValues -## 1.2.0 (Oct 16, 2015) +## [1.2].0 (Oct 16, 2015) -### FEATURES +### Added - Get-JiraFilter: get a reference to a JIRA filter, including its JQL and owner -### IMPROVEMENTS +### Changed - Get-JiraIssue: now supports a -Filter parameter to obtain all issues matching a given filter object or ID -## 1.1.1 (Oct 08, 2015) +## [1.1].1 (Oct 08, 2015) -### IMPROVEMENTS +### Changed - Set-JiraIssue now supports modifying arbitrary fields through the Fields parameter -## 1.1.0 (Sep 17, 2015) +## [1.1].0 (Sep 17, 2015) -### FEATURES +### Added - User management: create and delete users and groups, and modify group memberships -### IMPROVEMENTS +### Changed -- Cleaner error handling in all REST requests; JIRA's error messages should now be passed as PowerShell errors +- Cleaner error handling in all REST requests; Jira's error messages should now be passed as PowerShell errors -### BUG FIXES +### Fixed - PSJira.User: ToString() now works as expected -## 1.0.0 (Aug 5, 2015) +## [1.0].0 (Aug 5, 2015) - Initial release @@ -267,11 +267,11 @@ which is in turn inspired by the [Vagrant](https://github.com/mitchellh/vagrant/ ## Next Release -### FEATURES +### Added -### IMPROVEMENTS +### Changed -### BUG FIXES +### Fixed [@alexsuslin]: https://github.com/alexsuslin diff --git a/JiraPS.build.ps1 b/JiraPS.build.ps1 index 32e9a038..85e2c311 100644 --- a/JiraPS.build.ps1 +++ b/JiraPS.build.ps1 @@ -1,9 +1,13 @@ +#requires -Modules InvokeBuild + [CmdletBinding()] [System.Diagnostics.CodeAnalysis.SuppressMessage('PSAvoidUsingWriteHost', '')] [System.Diagnostics.CodeAnalysis.SuppressMessage('PSAvoidUsingEmptyCatchBlock', '')] param( [String[]]$Tag, - [String[]]$ExcludeTag + [String[]]$ExcludeTag = @("Integration"), + [String]$PSGalleryAPIKey, + [String]$GithubAccessToken ) $WarningPreference = "Continue" @@ -24,12 +28,17 @@ catch { } Set-StrictMode -Version Latest -Import-Module "$PSScriptRoot/Tools/build.psm1" -Force -ErrorAction Stop +Import-Module "$PSScriptRoot/Tools/BuildTools.psm1" -Force -ErrorAction Stop + if ($BuildTask -notin @("SetUp", "InstallDependencies")) { Import-Module BuildHelpers -Force -ErrorAction Stop + Invoke-Init } #region SetUp +# Synopsis: Proxy task +task Init { Invoke-Init } + # Synopsis: Create an initial environment for developing on the module task SetUp InstallDependencies, Build @@ -40,7 +49,7 @@ task InstallDependencies { $parameterPSDepend = @{ Path = "$PSScriptRoot/Tools/build.requirements.psd1" Install = $true - Import = $true + Import = $false Force = $true ErrorAction = "Stop" } @@ -48,28 +57,26 @@ task InstallDependencies { Import-Module BuildHelpers -Force } -# Synopsis: Ensure the build environment is all ready to go -task Init { - Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -ErrorAction SilentlyContinue - # BuildHelpers does not write the project name in the correct caps - if ($env:APPVEYOR_PROJECT_NAME) { - $env:BHProjectName = $env:APPVEYOR_PROJECT_NAME - } - - Add-ToModulePath -Path $env:BHBuildOutput -}, GetNextVersion - # Synopsis: Get the next version for the build task GetNextVersion { - $currentVersion = [Version](Get-Metadata -Path $env:BHPSModuleManifest) - if ($env:BHBuildNumber) { - $newRevision = $env:BHBuildNumber + $manifestVersion = [Version](Get-Metadata -Path $env:BHPSModuleManifest) + try { + $env:CurrentOnlineVersion = [Version](Find-Module -Name $env:BHProjectName).Version + $nextOnlineVersion = Get-NextNugetPackageVersion -Name $env:BHProjectName + + if ( ($manifestVersion.Major -gt $nextOnlineVersion.Major) -or + ($manifestVersion.Minor -gt $nextOnlineVersion.Minor) + # -or ($manifestVersion.Build -gt $nextOnlineVersion.Build) + ) { + $env:NextBuildVersion = [Version]::New($manifestVersion.Major, $manifestVersion.Minor, 0) + } + else { + $env:NextBuildVersion = $nextOnlineVersion + } } - else { - $newRevision = 0 + catch { + $env:NextBuildVersion = $manifestVersion } - $env:NextBuildVersion = [Version]::New($currentVersion.Major, $currentVersion.Minor, $newRevision) - $env:CurrentBuildVersion = $currentVersion } #endregion Setup @@ -94,7 +101,7 @@ switch ($true) { #endregion HarmonizeVariables #region DebugInformation -task ShowInfo Init, { +task ShowInfo Init, GetNextVersion, { Write-Build Gray Write-Build Gray ('Running in: {0}' -f $env:BHBuildSystem) Write-Build Gray '-------------------------------------------------------' @@ -102,14 +109,13 @@ task ShowInfo Init, { Write-Build Gray ('Project name: {0}' -f $env:BHProjectName) Write-Build Gray ('Project root: {0}' -f $env:BHProjectPath) Write-Build Gray ('Build Path: {0}' -f $env:BHBuildOutput) - Write-Build Gray ('Current Version: {0}' -f $env:CurrentBuildVersion) + Write-Build Gray ('Current (online) Version: {0}' -f $env:CurrentOnlineVersion) Write-Build Gray '-------------------------------------------------------' Write-Build Gray Write-Build Gray ('Branch: {0}' -f $env:BHBranchName) Write-Build Gray ('Commit: {0}' -f $env:BHCommitMessage) Write-Build Gray ('Build #: {0}' -f $env:BHBuildNumber) Write-Build Gray ('Next Version: {0}' -f $env:NextBuildVersion) - Write-Build Gray ('Will deploy new version? {0}' -f (Test-ShouldDeploy)) Write-Build Gray '-------------------------------------------------------' Write-Build Gray Write-Build Gray ('PowerShell version: {0}' -f $PSVersionTable.PSVersion.ToString()) @@ -121,10 +127,10 @@ task ShowInfo Init, { #region BuildRelease # Synopsis: Build a shippable release -task Build GenerateRelease, UpdateManifest, Package +task Build Init, GenerateExternalHelp, CopyModuleFiles, UpdateManifest, CompileModule, PrepareTests # Synopsis: Generate ./Release structure -task GenerateRelease Init, GenerateExternalHelp, { +task CopyModuleFiles { # Setup if (-not (Test-Path "$env:BHBuildOutput/$env:BHProjectName")) { $null = New-Item -Path "$env:BHBuildOutput/$env:BHProjectName" -ItemType Directory @@ -134,23 +140,59 @@ task GenerateRelease Init, GenerateExternalHelp, { Copy-Item -Path "$env:BHModulePath/*" -Destination "$env:BHBuildOutput/$env:BHProjectName" -Recurse -Force # Copy additional files Copy-Item -Path @( - "$BuildRoot/CHANGELOG.md" - "$BuildRoot/LICENSE" - "$BuildRoot/README.md" + "$env:BHProjectPath/CHANGELOG.md" + "$env:BHProjectPath/LICENSE" + "$env:BHProjectPath/README.md" ) -Destination "$env:BHBuildOutput/$env:BHProjectName" -Force - # Copy Tests +} + +# Synopsis: Prepare tests for ./Release +task PrepareTests Init, { $null = New-Item -Path "$env:BHBuildOutput/Tests" -ItemType Directory -ErrorAction SilentlyContinue - Copy-Item -Path "$BuildRoot/Tests/*.ps1" -Destination "$env:BHBuildOutput/Tests" -Recurse -Force - # Include Analyzer Settings - Copy-Item -Path "$BuildRoot/PSScriptAnalyzerSettings.psd1" -Destination "$env:BHBuildOutput/PSScriptAnalyzerSettings.psd1" -Force - # Remove all execptions from PSScriptAnalyzer - BuildHelpers\Update-Metadata -Path "$env:BHBuildOutput/PSScriptAnalyzerSettings.psd1" -PropertyName ExcludeRules -Value '' + Copy-Item -Path "$env:BHProjectPath/Tests" -Destination $env:BHBuildOutput -Recurse -Force + Copy-Item -Path "$env:BHProjectPath/PSScriptAnalyzerSettings.psd1" -Destination $env:BHBuildOutput -Force +} + +# Synopsis: Compile all functions into the .psm1 file +task CompileModule Init, { + $regionsToKeep = @('Dependencies', 'Configuration') + + $targetFile = "$env:BHBuildOutput/$env:BHProjectName/$env:BHProjectName.psm1" + $content = Get-Content -Encoding UTF8 -LiteralPath $targetFile + $capture = $false + $compiled = "" + + foreach ($line in $content) { + if ($line -match "^#region ($($regionsToKeep -join "|"))$") { + $capture = $true + } + if (($capture -eq $true) -and ($line -match "^#endregion")) { + $capture = $false + } + + if ($capture) { + $compiled += "$line`r`n" + } + } + + $PublicFunctions = @( Get-ChildItem -Path "$env:BHBuildOutput/$env:BHProjectName/Public/*.ps1" -ErrorAction SilentlyContinue ) + $PrivateFunctions = @( Get-ChildItem -Path "$env:BHBuildOutput/$env:BHProjectName/Private/*.ps1" -ErrorAction SilentlyContinue ) + + foreach ($function in @($PublicFunctions + $PrivateFunctions)) { + $compiled += (Get-Content -Path $function.FullName -Raw) + $compiled += "`r`n" + } + + Set-Content -LiteralPath $targetFile -Value $compiled -Encoding UTF8 -Force + Remove-Utf8Bom -Path $targetFile + + "Private", "Public" | Foreach-Object { Remove-Item -Path "$env:BHBuildOutput/$env:BHProjectName/$_" -Recurse -Force } } # Synopsis: Use PlatyPS to generate External-Help -task GenerateExternalHelp -If (Get-ChildItem "$BuildRoot/docs/en-US/commands" -ErrorAction SilentlyContinue) Init, { +task GenerateExternalHelp Init, { Import-Module platyPS -Force - foreach ($locale in (Get-ChildItem "$BuildRoot/docs" -Attribute Directory)) { + foreach ($locale in (Get-ChildItem "$env:BHProjectPath/docs" -Attribute Directory)) { New-ExternalHelp -Path "$($locale.FullName)" -OutputPath "$env:BHModulePath/$($locale.Basename)" -Force New-ExternalHelp -Path "$($locale.FullName)/commands" -OutputPath "$env:BHModulePath/$($locale.Basename)" -Force } @@ -163,9 +205,6 @@ task UpdateManifest GetNextVersion, { Import-Module $env:BHPSModuleManifest -Force $ModuleAlias = @(Get-Alias | Where-Object {$_.ModuleName -eq "$env:BHProjectName"}) - Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue - Import-Module $env:BHProjectName -Force - BuildHelpers\Update-Metadata -Path "$env:BHBuildOutput/$env:BHProjectName/$env:BHProjectName.psd1" -PropertyName ModuleVersion -Value $env:NextBuildVersion # BuildHelpers\Update-Metadata -Path "$env:BHBuildOutput/$env:BHProjectName/$env:BHProjectName.psd1" -PropertyName FileList -Value (Get-ChildItem "$env:BHBuildOutput/$env:BHProjectName" -Recurse).Name BuildHelpers\Set-ModuleFunctions -Name "$env:BHBuildOutput/$env:BHProjectName/$env:BHProjectName.psd1" -FunctionsToExport ([string[]](Get-ChildItem "$env:BHBuildOutput/$env:BHProjectName/Public/*.ps1").BaseName) @@ -176,7 +215,9 @@ task UpdateManifest GetNextVersion, { } # Synopsis: Create a ZIP file with this build -task Package GenerateRelease, { +task Package Init, { + Assert-True { Test-Path "$env:BHBuildOutput\$env:BHProjectName" } "Missing files to package" + Remove-Item "$env:BHBuildOutput\$env:BHProjectName.zip" -ErrorAction SilentlyContinue $null = Compress-Archive -Path "$env:BHBuildOutput\$env:BHProjectName" -DestinationPath "$env:BHBuildOutput\$env:BHProjectName.zip" } @@ -184,63 +225,57 @@ task Package GenerateRelease, { #region Test task Test Init, { - assert { Test-Path $env:BHBuildOutput -PathType Container } + Assert-True { Test-Path $env:BHBuildOutput -PathType Container } "Release path must exist" Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue - $params = @{ + <# $params = @{ Path = "$env:BHBuildOutput/$env:BHProjectName" Include = '*.ps1', '*.psm1' Recurse = $True - # Exclude = $CodeCoverageExclude + Exclude = $CodeCoverageExclude } - $codeCoverageFiles = Get-ChildItem @params + $codeCoverageFiles = Get-ChildItem @params #> try { $parameter = @{ Script = "$env:BHBuildOutput/Tests/*" Tag = $Tag ExcludeTag = $ExcludeTag + Show = "Fails" PassThru = $true - OutputFile = "$BuildRoot/TestResult.xml" + OutputFile = "$env:BHProjectPath/Test-$OS-$($PSVersionTable.PSVersion.ToString()).xml" OutputFormat = "NUnitXml" - CodeCoverage = $codeCoverageFiles + # CodeCoverage = $codeCoverageFiles } - $parameter["Show"] = "Fails" $testResults = Invoke-Pester @parameter - If ('AppVeyor' -eq $env:BHBuildSystem) { - BuildHelpers\Add-TestResultToAppveyor -TestFile $parameter["OutputFile"] - } - - assert ($testResults.FailedCount -eq 0) "$($testResults.FailedCount) Pester test(s) failed." + Assert-True ($testResults.FailedCount -eq 0) "$($testResults.FailedCount) Pester test(s) failed." } catch { throw $_ } - - Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -ErrorAction SilentlyContinue - # BuildHelpers does not write the project name in the correct caps - if ($env:APPVEYOR_PROJECT_NAME) { - $env:BHProjectName = $env:APPVEYOR_PROJECT_NAME - } -}, RemoveTestResults, RemoveConfig +}, { Init } #endregion #region Publish # Synopsis: Publish a new release on github and the PSGallery -task Deploy -If { Test-ShouldDeploy } Init, PublishToGallery, TagReplository, UpdateHomepage +task Deploy Init, PublishToGallery, TagReplository, UpdateHomepage -# Synipsis: Publish the $release to the PSGallery +# Synpsis: Publish the $release to the PSGallery task PublishToGallery { - assert ($env:PSGalleryAPIKey) "No key for the PSGallery" + Assert-True (-not [String]::IsNullOrEmpty($PSGalleryAPIKey)) "No key for the PSGallery" + Assert-True {Get-Module $env:BHProjectName -ListAvailable} "Module $env:BHProjectName is not available" - Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module $env:BHProjectName -ErrorAction Ignore - Publish-Module -Name $env:BHProjectName -NuGetApiKey $env:PSGalleryAPIKey + Publish-Module -Name $env:BHProjectName -NuGetApiKey $PSGalleryAPIKey } -task TagReplository GetNextVersion, { +# Synopsis: push a tag with the version to the git repository +task TagReplository GetNextVersion, Package, { + Assert-True (-not [String]::IsNullOrEmpty($GithubAccessToken)) "No key for the PSGallery" + $releaseText = "Release version $env:NextBuildVersion" # Push a tag to the repository @@ -254,17 +289,28 @@ task TagReplository GetNextVersion, { cmd /c "git push origin v$env:NextBuildVersion 2>&1" # Publish a release on github for the tag above - $releaseResponse = Publish-GithubRelease -ReleaseText $releaseText -NextBuildVersion $env:NextBuildVersion + $releaseResponse = Publish-GithubRelease -GITHUB_ACCESS_TOKEN $GithubAccessToken -ReleaseText $releaseText -NextBuildVersion $env:NextBuildVersion # Upload the package of the version to the release $packageFile = Get-Item "$env:BHBuildOutput\$env:BHProjectName.zip" -ErrorAction Stop $uploadURI = $releaseResponse.upload_url -replace "\{\?name,label\}", "?name=$($packageFile.Name)" - $null = Publish-GithubReleaseArtifact -Uri $uploadURI -Path $packageFile + $null = Publish-GithubReleaseArtifact -GITHUB_ACCESS_TOKEN $GithubAccessToken -Uri $uploadURI -Path $packageFile } # Synopsis: Update the version of this module that the homepage uses task UpdateHomepage { try { + Add-Content (Join-Path $Home ".git-credentials") "https://$GithubAccessToken:x-oauth-basic@github.com`n" + + Write-Build Gray "git config --global credential.helper `"store --file ~/.git-credentials`"" + git config --global credential.helper "store --file ~/.git-credentials" + + Write-Build Gray "git config --global user.email `"support@atlassianps.org`"" + git config --global user.email "support@atlassianps.org" + + Write-Build Gray "git config --global user.name `"AtlassianPS automation`"" + git config --global user.name "AtlassianPS automation" + Write-Build Gray "git close .../AtlassianPS.github.io --recursive" $null = cmd /c "git clone https://github.com/AtlassianPS/AtlassianPS.github.io --recursive 2>&1" @@ -295,24 +341,20 @@ task UpdateHomepage { #region Cleaning tasks # Synopsis: Clean the working dir -task Clean Init, RemoveGeneratedFiles, RemoveTestResults, RemoveConfig +task Clean Init, RemoveGeneratedFiles, RemoveTestResults # Synopsis: Remove generated and temp files. task RemoveGeneratedFiles { + Remove-Item "$env:BHModulePath/en-US/*" -Force -ErrorAction SilentlyContinue Remove-Item $env:BHBuildOutput -Force -Recurse -ErrorAction SilentlyContinue } # Synopsis: Remove Pester results task RemoveTestResults { - Remove-Item "TestResult.xml" -Force -ErrorAction SilentlyContinue -} - -# Synopsis: Remove Jira config file -task RemoveConfig { - Remove-Item "$env:BHBuildOutput\config.xml" -Force -ErrorAction SilentlyContinue + Remove-Item "Test-*.xml" -Force -ErrorAction SilentlyContinue } #endregion -task . ShowInfo, Clean, Build, Test, Deploy +task . ShowInfo, Clean, Build, Test Remove-Item -Path Env:\BH* diff --git a/PSScriptAnalyzerSettings.psd1 b/PSScriptAnalyzerSettings.psd1 index 2ca8ff36..3ac3b77d 100644 --- a/PSScriptAnalyzerSettings.psd1 +++ b/PSScriptAnalyzerSettings.psd1 @@ -1,7 +1,5 @@ @{ Severity = @('Error', 'Warning') # IncludeRules = @() - ExcludeRules = @( - 'PSUseToExportFieldsInManifest' - ) + # ExcludeRules = @() } diff --git a/README.md b/README.md index 933820ac..89652d3f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,10 @@ permalink: /module/JiraPS/ --- # [JiraPS](https://atlassianps.org/module/JiraPS) -[![GitHub release](https://img.shields.io/github/release/AtlassianPS/JiraPS.svg)](https://github.com/AtlassianPS/JiraPS/releases/latest) [![Build status](https://img.shields.io/appveyor/ci/AtlassianPS/JiraPS/master.svg)](https://ci.appveyor.com/project/AtlassianPS/jiraps/branch/master) [![PowerShell Gallery](https://img.shields.io/powershellgallery/dt/JiraPS.svg)](https://www.powershellgallery.com/packages/JiraPS) ![License](https://img.shields.io/badge/license-MIT-blue.svg) +[![GitHub release](https://img.shields.io/github/release/AtlassianPS/JiraPS.svg?style=for-the-badge)](https://github.com/AtlassianPS/JiraPS/releases/latest) +[![Build Status](https://img.shields.io/vso/build/AtlassianPS/JiraPS/11/master.svg?style=for-the-badge)](https://dev.azure.com/AtlassianPS/JiraPS/_build/latest?definitionId=11) +[![PowerShell Gallery](https://img.shields.io/powershellgallery/dt/JiraPS.svg?style=for-the-badge)](https://www.powershellgallery.com/packages/JiraPS) +![License](https://img.shields.io/badge/license-MIT-blue.svg?style=for-the-badge) JiraPS is a Windows PowerShell module to interact with Atlassian [JIRA] via a REST API, while maintaining a consistent PowerShell look and feel. @@ -56,7 +59,18 @@ We appreciate [everyone](https://atlassianps.org/#people) who invests their time Check out our guidelines on [Contributing] to our modules and documentation. -## Acknowledgments +## Tested on + +|Configuration|Status| +|-------------|------| +|Windows Powershell v3|| +|Windows Powershell v4|| +|Windows Powershell v5.1|[![Build Status](https://img.shields.io/vso/build/AtlassianPS/JiraPS/11/master.svg?style=for-the-badge)](https://dev.azure.com/AtlassianPS/JiraPS/_build/latest?definitionId=11)| +|Powershell Core (latest) on Windows|[![Build Status](https://img.shields.io/vso/build/AtlassianPS/JiraPS/11/master.svg?style=for-the-badge)](https://dev.azure.com/AtlassianPS/JiraPS/_build/latest?definitionId=11)| +|Powershell Core (latest) on Ubuntu|[![Build Status](https://img.shields.io/vso/build/AtlassianPS/JiraPS/11/master.svg?style=for-the-badge)](https://dev.azure.com/AtlassianPS/JiraPS/_build/latest?definitionId=11)| +|Powershell Core (latest) on MacOS|[![Build Status](https://img.shields.io/vso/build/AtlassianPS/JiraPS/11/master.svg?style=for-the-badge)](https://dev.azure.com/AtlassianPS/JiraPS/_build/latest?definitionId=11)| + +## Acknowledgements * Thanks to [replicaJunction] for getting this module on it's feet * Thanks to everyone ([Our Contributors](https://atlassianps.org/#people)) that helped with this module diff --git a/Tests/Build.Tests.ps1 b/Tests/Build.Tests.ps1 new file mode 100644 index 00000000..b00c8ba6 --- /dev/null +++ b/Tests/Build.Tests.ps1 @@ -0,0 +1,66 @@ +#requires -modules BuildHelpers +#requires -modules Configuration +#requires -modules Pester + +Describe "Validation of build environment" -Tag Unit { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + # Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + $changelogFile = if ($script:isBuild) { + "$env:BHBuildOutput/$env:BHProjectName/CHANGELOG.md" + } + else { + "$env:BHProjectPath/CHANGELOG.md" + } + + Context "CHANGELOG" { + + foreach ($line in (Get-Content $changelogFile)) { + if ($line -match "(?:##|\)\s*\[(?(\d+\.?){1,2})\]") { + $changelogVersion = $matches.Version + break + } + } + + It "has a changelog file" { + $changelogFile | Should -Exist + } + + It "has a valid version in the changelog" { + $changelogVersion | Should -Not -BeNullOrEmpty + [Version]($changelogVersion) | Should -BeOfType [Version] + } + + It "has a version changelog that matches the manifest version" { + Configuration\Get-Metadata -Path $env:BHManifestToTest -PropertyName ModuleVersion | Should -BeLike "$changelogVersion*" + } + } +} diff --git a/Tests/ConvertTo-JiraComponent.Tests.ps1 b/Tests/ConvertTo-JiraComponent.Tests.ps1 deleted file mode 100644 index a3266075..00000000 --- a/Tests/ConvertTo-JiraComponent.Tests.ps1 +++ /dev/null @@ -1,35 +0,0 @@ -Describe "ConvertTo-JiraComponent" { - - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop - - InModuleScope JiraPS { - - . "$PSScriptRoot/Shared.ps1" - - $jiraServer = 'http://jiraserver.example.com' - - $sampleJson = @" -{ - "self": "$jiraServer/rest/api/2/component/11000", - "id": "11000", - "name": "test component" -} -"@ - $sampleObject = ConvertFrom-Json -InputObject $sampleJson - - $r = ConvertTo-JiraComponent -InputObject $sampleObject - - It "Creates a PSObject out of JSON input" { - $r | Should Not BeNullOrEmpty - } - - It "Sets the type name to JiraPS.Project" { - # (Get-Member -InputObject $r).TypeName | Should Be 'JiraPS.Component' - checkType $r "JiraPS.Component" - } - - defProp $r 'Id' '11000' - defProp $r 'Name' 'test component' - defProp $r 'RestUrl' "$jiraServer/rest/api/2/component/11000" - } -} diff --git a/Tests/ConvertTo-JiraField.Tests.ps1 b/Tests/ConvertTo-JiraField.Tests.ps1 deleted file mode 100644 index 1871210d..00000000 --- a/Tests/ConvertTo-JiraField.Tests.ps1 +++ /dev/null @@ -1,23 +0,0 @@ -Describe "ConvertTo-JiraField" { - - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop - - InModuleScope JiraPS { - - . "$PSScriptRoot/Shared.ps1" - - $sampleJson = '{"id":"issuetype","name":"Issue Type","custom":false,"orderable":true,"navigable":true,"searchable":true,"clauseNames":["issuetype","type"],"schema":{"type":"issuetype","system":"issuetype"}}' - $sampleObject = ConvertFrom-Json -InputObject $sampleJson - - $r = ConvertTo-JiraField $sampleObject - It "Creates a PSObject out of JSON input" { - $r | Should Not BeNullOrEmpty - } - - checkPsType $r 'JiraPS.Field' - - defProp $r 'Id' 'issuetype' - defProp $r 'Name' 'Issue Type' - defProp $r 'Custom' $false - } -} diff --git a/Tests/ConvertTo-JiraGroup.Tests.ps1 b/Tests/ConvertTo-JiraGroup.Tests.ps1 deleted file mode 100644 index c576d5f6..00000000 --- a/Tests/ConvertTo-JiraGroup.Tests.ps1 +++ /dev/null @@ -1,40 +0,0 @@ -Describe "ConvertTo-JiraGroup" { - - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop - - InModuleScope JiraPS { - - . "$PSScriptRoot/Shared.ps1" - - $jiraServer = 'http://jiraserver.example.com' - $groupName = 'powershell-testgroup' - - $sampleJson = @" -{ - "self": "$jiraServer/rest/api/2/group?groupname=$groupName", - "name": "$groupName", - "users": { - "size": 1, - "items": [], - "max-results": 50, - "start-index": 0, - "end-index": 0 - }, - "expand": "users" -} -"@ - $sampleObject = ConvertFrom-Json -InputObject $sampleJson - - $r = ConvertTo-JiraGroup -InputObject $sampleObject - - It "Creates a PSObject out of JSON input" { - $r | Should Not BeNullOrEmpty - } - - checkPsType $r 'JiraPS.Group' - - defProp $r 'Name' $groupName - defProp $r 'RestUrl' "$jiraServer/rest/api/2/group?groupname=$groupName" - defProp $r 'Size' 1 - } -} diff --git a/Tests/ConvertTo-JiraIssueLink.Tests.ps1 b/Tests/ConvertTo-JiraIssueLink.Tests.ps1 deleted file mode 100644 index 32afb31b..00000000 --- a/Tests/ConvertTo-JiraIssueLink.Tests.ps1 +++ /dev/null @@ -1,53 +0,0 @@ -Describe "ConvertTo-JiraIssueLink" { - - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop - - InModuleScope JiraPS { - - . "$PSScriptRoot/Shared.ps1" - - $jiraServer = 'http://jiraserver.example.com' - - $issueLinkId = 41313 - $issueKeyInward = "TEST-01" - $issueKeyOutward = "TEST-10" - $linkTypeName = "Composition" - - $sampleJson = @" -{ - "id": "$issueLinkId", - "type": { - "id": "10500", - "name": "$linkTypeName", - "inward": "is part of", - "outward": "composes" - }, - "inwardIssue": { - "key": "$issueKeyInward" - }, - "outwardIssue": { - "key": "$issueKeyOutward" - } -} -"@ - - $sampleObject = ConvertFrom-Json -InputObject $sampleJson - - $r = ConvertTo-JiraIssueLink -InputObject $sampleObject - It "Creates a PSObject out of JSON input" { - $r | Should Not BeNullOrEmpty - } - - checkPsType $r 'JiraPS.IssueLink' - - defProp $r 'Id' $issueLinkId - defProp $r 'Type' "Composition" - defProp $r 'InwardIssue' "[$issueKeyInward] " - defProp $r 'OutwardIssue' "[$issueKeyOutward] " - - It "Handles pipeline input" { - $r = $sampleObject | ConvertTo-JiraIssueLink - @($r).Count | Should Be 1 - } - } -} diff --git a/Tests/ConvertTo-JiraIssueType.Tests.ps1 b/Tests/ConvertTo-JiraIssueType.Tests.ps1 deleted file mode 100644 index 613e0ca0..00000000 --- a/Tests/ConvertTo-JiraIssueType.Tests.ps1 +++ /dev/null @@ -1,41 +0,0 @@ -Describe "ConvertTo-JiraIssueType" { - - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop - - InModuleScope JiraPS { - - . "$PSScriptRoot/Shared.ps1" - - $jiraServer = 'http://jiraserver.example.com' - - $issueTypeId = 2 - $issueTypeName = 'Test Issue Type' - $issueTypeDescription = 'A test issue used for...well, testing' - - $sampleJson = @" -{ - "self": "$jiraServer/rest/api/latest/issuetype/2", - "id": "$issueTypeId", - "description": "$issueTypeDescription", - "iconUrl": "$jiraServer/images/icons/issuetypes/newfeature.png", - "name": "$issueTypeName", - "subtask": false -} -"@ - $sampleObject = ConvertFrom-Json -InputObject $sampleJson - - $r = ConvertTo-JiraIssueType $sampleObject - It "Creates a PSObject out of JSON input" { - $r | Should Not BeNullOrEmpty - } - - checkPsType $r 'JiraPS.IssueType' - - defProp $r 'Id' $issueTypeId - defProp $r 'Name' $issueTypeName - defProp $r 'Description' $issueTypeDescription - defProp $r 'RestUrl' "$jiraServer/rest/api/latest/issuetype/$issueTypeId" - defProp $r 'IconUrl' "$jiraServer/images/icons/issuetypes/newfeature.png" - defProp $r 'Subtask' $false - } -} diff --git a/Tests/ConvertTo-JiraPriority.Tests.ps1 b/Tests/ConvertTo-JiraPriority.Tests.ps1 deleted file mode 100644 index 25539bba..00000000 --- a/Tests/ConvertTo-JiraPriority.Tests.ps1 +++ /dev/null @@ -1,40 +0,0 @@ -Describe "ConvertTo-JiraPriority" { - - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop - - InModuleScope JiraPS { - - . "$PSScriptRoot/Shared.ps1" - - $jiraServer = 'http://jiraserver.example.com' - - $priorityId = 1 - $priorityName = 'Critical' - $priorityDescription = 'Cannot contine normal operations' - - $sampleJson = @" -{ - "self": "$jiraServer/rest/api/2/priority/1", - "statusColor": "#cc0000", - "description": "$priorityDescription", - "name": "$priorityName", - "id": "$priorityId" - } -"@ - $sampleObject = ConvertFrom-Json -InputObject $sampleJson - - $r = ConvertTo-JiraPriority -InputObject $sampleObject - - It "Creates a PSObject out of JSON input" { - $r | Should Not BeNullOrEmpty - } - - checkPsType $r 'JiraPS.Priority' - - defProp $r 'Id' $priorityId - defProp $r 'Name' $priorityName - defProp $r 'RestUrl' "$jiraServer/rest/api/2/priority/$priorityId" - defProp $r 'Description' $priorityDescription - defProp $r 'StatusColor' '#cc0000' - } -} diff --git a/Tests/ConvertTo-JiraProjectRole.Tests.ps1 b/Tests/ConvertTo-JiraProjectRole.Tests.ps1 deleted file mode 100644 index acee0c95..00000000 --- a/Tests/ConvertTo-JiraProjectRole.Tests.ps1 +++ /dev/null @@ -1,49 +0,0 @@ -Describe "ConvertTo-JiraProjectRole" { - - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop - - InModuleScope JiraPS { - - . "$PSScriptRoot/Shared.ps1" - - $sampleJson = @" -[ - { - "self": "http://www.example.com/jira/rest/api/2/project/MKY/role/10360", - "name": "Developers", - "id": 10360, - "description": "A project role that represents developers in a project", - "actors": [ - { - "id": 10240, - "displayName": "jira-developers", - "type": "atlassian-group-role-actor", - "name": "jira-developers" - }, - { - "id": 10241, - "displayName": "Fred F. User", - "type": "atlassian-user-role-actor", - "name": "fred" - } - ] - } -] -"@ - - $sampleObject = ConvertFrom-Json -InputObject $sampleJson - $r = ConvertTo-JiraProjectRole -InputObject $sampleObject - - It "Creates a PSObject out of JSON input" { - $r | Should -Not -BeNullOrEmpty - } - - checkPsType $r 'JiraPS.ProjectRole' - - defProp $r 'Id' 10360 - defProp $r 'Name' "Developers" - defProp $r 'Description' "A project role that represents developers in a project" - hasProp $r 'Actors' - defProp $r 'RestUrl' "http://www.example.com/jira/rest/api/2/project/MKY/role/10360" - } -} diff --git a/Tests/ConvertTo-JiraServerInfo.Tests.ps1 b/Tests/ConvertTo-JiraServerInfo.Tests.ps1 deleted file mode 100644 index aaa0f1c5..00000000 --- a/Tests/ConvertTo-JiraServerInfo.Tests.ps1 +++ /dev/null @@ -1,44 +0,0 @@ -Describe "ConvertTo-JiraServerInfo" { - - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop - - InModuleScope JiraPS { - - . "$PSScriptRoot/Shared.ps1" - - $jiraServer = 'http://jiraserver.example.com' - - $sampleJson = @" -{ - "baseUrl":"$jiraServer", - "version":"1000.1323.0", - "versionNumbers":[1000,1323,0], - "deploymentType":"Cloud", - "buildNumber":100062, - "buildDate":"2017-09-26T00:00:00.000+0200", - "serverTime":"2017-09-27T09:59:25.520+0200", - "scmInfo":"f3c60100df073e3576f9741fb7a3dc759b416fde", - "serverTitle":"JIRA" -} -"@ - - $sampleObject = ConvertFrom-Json -InputObject $sampleJson - $r = ConvertTo-JiraServerInfo -InputObject $sampleObject - - It "Creates a PSObject out of JSON input" { - $r | Should Not BeNullOrEmpty - } - - checkPsType $r 'JiraPS.ServerInfo' - - - defProp $r 'BaseURL' $jiraServer - defProp $r 'Version' ([Version]"1000.1323.0") - defProp $r 'DeploymentType' "Cloud" - defProp $r 'BuildNumber' 100062 - defProp $r 'BuildDate' (Get-Date '2017-09-26T00:00:00.000+0200') - defProp $r 'ServerTime' (Get-Date '2017-09-27T09:59:25.520+0200') - defProp $r 'ScmInfo' "f3c60100df073e3576f9741fb7a3dc759b416fde" - defProp $r 'ServerTitle' "JIRA" - } -} diff --git a/Tests/ConvertTo-JiraSession.Tests.ps1 b/Tests/ConvertTo-JiraSession.Tests.ps1 deleted file mode 100644 index 10c15429..00000000 --- a/Tests/ConvertTo-JiraSession.Tests.ps1 +++ /dev/null @@ -1,21 +0,0 @@ -Describe "ConvertTo-JiraSession" { - - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop - - InModuleScope JiraPS { - - . "$PSScriptRoot/Shared.ps1" - - $sampleUsername = 'powershell-test' - $sampleSession = @{} - - $r = ConvertTo-JiraSession -Session $sampleSession -Username $sampleUsername - - It "Creates a PSObject out of Web request data" { - $r | Should Not BeNullOrEmpty - } - - checkPsType $r 'JiraPS.Session' - defProp $r 'Username' $sampleUsername - } -} diff --git a/Tests/ConvertTo-JiraStatus.Tests.ps1 b/Tests/ConvertTo-JiraStatus.Tests.ps1 deleted file mode 100644 index adaf0ffd..00000000 --- a/Tests/ConvertTo-JiraStatus.Tests.ps1 +++ /dev/null @@ -1,47 +0,0 @@ -Describe "ConvertTo-JiraStatus" { - - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop - - InModuleScope JiraPS { - - . "$PSScriptRoot/Shared.ps1" - - $jiraServer = 'http://jiraserver.example.com' - - $statusName = 'In Progress' - $statusId = 3 - $statusDesc = 'This issue is being actively worked on at the moment by the assignee.' - - $sampleJson = @" -{ - "self": "$jiraServer/rest/api/2/status/$statusId", - "description": "$statusDesc", - "iconUrl": "$jiraServer/images/icons/statuses/inprogress.png", - "name": "$statusName", - "id": "$statusId", - "statusCategory": { - "self": "$jiraServer/rest/api/2/statuscategory/4", - "id": 4, - "key": "indeterminate", - "colorName": "yellow", - "name": "In Progress" - } -} -"@ - $sampleObject = ConvertFrom-Json -InputObject $sampleJson - - $r = ConvertTo-JiraStatus -InputObject $sampleObject - - It "Creates a PSObject out of JSON input" { - $r | Should Not BeNullOrEmpty - } - - checkPsType $r 'JiraPS.Status' - - defProp $r 'Id' $statusId - defProp $r 'Name' $statusName - defProp $r 'Description' $statusDesc - defProp $r 'IconUrl' "$jiraServer/images/icons/statuses/inprogress.png" - defProp $r 'RestUrl' "$jiraServer/rest/api/2/status/$statusId" - } -} diff --git a/Tests/Examples.Tests.ps1 b/Tests/Examples.Tests.ps1 new file mode 100644 index 00000000..530f26cd --- /dev/null +++ b/Tests/Examples.Tests.ps1 @@ -0,0 +1,45 @@ +#requires -modules BuildHelpers +#requires -modules Pester + +Describe "Validation of example codes in the documentation" -Tag Documentation, NotImplemented { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + # Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + Assert-True $script:isBuild "Examples can only be tested in the build environment. Please run `Invoke-Build -Task Build`." + + $functions = Get-Command -Module $env:BHProjectName | Get-Help + foreach ($function in $functions) { + Context "Examples of $($function.Name)" { + + + } + } +} diff --git a/Tests/Add-JiraFilterPermission.Tests.ps1 b/Tests/Functions/Add-JiraFilterPermission.Unit.Tests.ps1 similarity index 89% rename from Tests/Add-JiraFilterPermission.Tests.ps1 rename to Tests/Functions/Add-JiraFilterPermission.Unit.Tests.ps1 index d1f947c5..8e852d5a 100644 --- a/Tests/Add-JiraFilterPermission.Tests.ps1 +++ b/Tests/Functions/Add-JiraFilterPermission.Unit.Tests.ps1 @@ -1,12 +1,41 @@ -Describe 'Add-JiraFilterPermission' { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe 'Add-JiraFilterPermission' -Tag 'Unit' { + BeforeAll { - Remove-Module JiraPS -ErrorAction SilentlyContinue - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" #region Definitions $jiraServer = "https://jira.example.com" diff --git a/Tests/Add-JiraGroupMember.Tests.ps1 b/Tests/Functions/Add-JiraGroupMember.Unit.Tests.ps1 similarity index 78% rename from Tests/Add-JiraGroupMember.Tests.ps1 rename to Tests/Functions/Add-JiraGroupMember.Unit.Tests.ps1 index 7b300cb3..c7a5c697 100644 --- a/Tests/Add-JiraGroupMember.Tests.ps1 +++ b/Tests/Functions/Add-JiraGroupMember.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Add-JiraGroupMember" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Add-JiraGroupMember" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Add-JiraIssueAttachment.Tests.ps1 b/Tests/Functions/Add-JiraIssueAttachment.Unit.Tests.ps1 similarity index 87% rename from Tests/Add-JiraIssueAttachment.Tests.ps1 rename to Tests/Functions/Add-JiraIssueAttachment.Unit.Tests.ps1 index f12480a0..97656b5d 100644 --- a/Tests/Add-JiraIssueAttachment.Tests.ps1 +++ b/Tests/Functions/Add-JiraIssueAttachment.Unit.Tests.ps1 @@ -1,13 +1,44 @@ +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param() -Describe "Add-JiraIssueAttachment" { +Describe "Add-JiraIssueAttachment" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $pass = ConvertTo-SecureString -AsPlainText -Force -String "passowrd" $Cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ("user", $pass) diff --git a/Tests/Add-JiraIssueComment.Tests.ps1 b/Tests/Functions/Add-JiraIssueComment.Unit.Tests.ps1 similarity index 68% rename from Tests/Add-JiraIssueComment.Tests.ps1 rename to Tests/Functions/Add-JiraIssueComment.Unit.Tests.ps1 index c8710fb9..05805148 100644 --- a/Tests/Add-JiraIssueComment.Tests.ps1 +++ b/Tests/Functions/Add-JiraIssueComment.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Add-JiraIssueComment" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Add-JiraIssueComment" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' $issueID = 41701 diff --git a/Tests/Add-JiraIssueLink.Tests.ps1 b/Tests/Functions/Add-JiraIssueLink.Unit.Tests.ps1 similarity index 62% rename from Tests/Add-JiraIssueLink.Tests.ps1 rename to Tests/Functions/Add-JiraIssueLink.Unit.Tests.ps1 index c9cd51fc..123bb8f4 100644 --- a/Tests/Add-JiraIssueLink.Tests.ps1 +++ b/Tests/Functions/Add-JiraIssueLink.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe 'Add-JiraIssueLink' { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe 'Add-JiraIssueLink' -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Add-JiraIssueWatcher.Tests.ps1 b/Tests/Functions/Add-JiraIssueWatcher.Unit.Tests.ps1 similarity index 66% rename from Tests/Add-JiraIssueWatcher.Tests.ps1 rename to Tests/Functions/Add-JiraIssueWatcher.Unit.Tests.ps1 index bbe67ba7..1b020a93 100644 --- a/Tests/Add-JiraIssueWatcher.Tests.ps1 +++ b/Tests/Functions/Add-JiraIssueWatcher.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Add-JiraIssueWatcher" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Add-JiraIssueWatcher" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' $issueID = 41701 diff --git a/Tests/Add-JiraIssueWorklog.Tests.ps1 b/Tests/Functions/Add-JiraIssueWorklog.Unit.Tests.ps1 similarity index 76% rename from Tests/Add-JiraIssueWorklog.Tests.ps1 rename to Tests/Functions/Add-JiraIssueWorklog.Unit.Tests.ps1 index 87d1ccfc..9f85e07f 100644 --- a/Tests/Add-JiraIssueWorklog.Tests.ps1 +++ b/Tests/Functions/Add-JiraIssueWorklog.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Add-JiraIssueWorklog" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Add-JiraIssueWorklog" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' $jiraUsername = 'powershell-test' diff --git a/Tests/ConvertFrom-Json2.Tests.ps1 b/Tests/Functions/ConvertFrom-Json.Unit.Tests.ps1 similarity index 54% rename from Tests/ConvertFrom-Json2.Tests.ps1 rename to Tests/Functions/ConvertFrom-Json.Unit.Tests.ps1 index b1efd314..16fb0b10 100644 --- a/Tests/ConvertFrom-Json2.Tests.ps1 +++ b/Tests/Functions/ConvertFrom-Json.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "ConvertFrom-Json" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "ConvertFrom-Json" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $sampleJson = '{"id":"issuetype","name":"Issue Type","custom":false,"orderable":true,"navigable":true,"searchable":true,"clauseNames":["issuetype","type"],"schema":{"type":"issuetype","system":"issuetype"}}' $sampleObject = ConvertFrom-Json -InputObject $sampleJson diff --git a/Tests/ConvertFrom-URLEncoded.Tests.ps1 b/Tests/Functions/ConvertFrom-URLEncoded.Unit.Tests.ps1 similarity index 52% rename from Tests/ConvertFrom-URLEncoded.Tests.ps1 rename to Tests/Functions/ConvertFrom-URLEncoded.Unit.Tests.ps1 index 7a5f2848..5697b9ba 100644 --- a/Tests/ConvertFrom-URLEncoded.Tests.ps1 +++ b/Tests/Functions/ConvertFrom-URLEncoded.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "ConvertFrom-URLEncoded" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "ConvertFrom-URLEncoded" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" Context "Sanity checking" { $command = Get-Command -Name ConvertFrom-URLEncoded diff --git a/Tests/ConvertTo-JiraAttachment.Tests.ps1 b/Tests/Functions/ConvertTo-JiraAttachment.Unit.Tests.ps1 similarity index 70% rename from Tests/ConvertTo-JiraAttachment.Tests.ps1 rename to Tests/Functions/ConvertTo-JiraAttachment.Unit.Tests.ps1 index 158f9cac..441191ac 100644 --- a/Tests/ConvertTo-JiraAttachment.Tests.ps1 +++ b/Tests/Functions/ConvertTo-JiraAttachment.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "ConvertTo-JiraAttachment" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "ConvertTo-JiraAttachment" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/ConvertTo-JiraComment.Tests.ps1 b/Tests/Functions/ConvertTo-JiraComment.Unit.Tests.ps1 similarity index 62% rename from Tests/ConvertTo-JiraComment.Tests.ps1 rename to Tests/Functions/ConvertTo-JiraComment.Unit.Tests.ps1 index 9533207c..c3e439ed 100644 --- a/Tests/ConvertTo-JiraComment.Tests.ps1 +++ b/Tests/Functions/ConvertTo-JiraComment.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "ConvertTo-JiraComment" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "ConvertTo-JiraComment" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' $jiraUsername = 'powershell-test' diff --git a/Tests/Functions/ConvertTo-JiraComponent.Unit.Tests.ps1 b/Tests/Functions/ConvertTo-JiraComponent.Unit.Tests.ps1 new file mode 100644 index 00000000..334da0ce --- /dev/null +++ b/Tests/Functions/ConvertTo-JiraComponent.Unit.Tests.ps1 @@ -0,0 +1,66 @@ +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "ConvertTo-JiraComponent" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + InModuleScope JiraPS { + + . "$PSScriptRoot/../Shared.ps1" + + $jiraServer = 'http://jiraserver.example.com' + + $sampleJson = @" +{ + "self": "$jiraServer/rest/api/2/component/11000", + "id": "11000", + "name": "test component" +} +"@ + $sampleObject = ConvertFrom-Json -InputObject $sampleJson + + $r = ConvertTo-JiraComponent -InputObject $sampleObject + + It "Creates a PSObject out of JSON input" { + $r | Should Not BeNullOrEmpty + } + + It "Sets the type name to JiraPS.Project" { + # (Get-Member -InputObject $r).TypeName | Should Be 'JiraPS.Component' + checkType $r "JiraPS.Component" + } + + defProp $r 'Id' '11000' + defProp $r 'Name' 'test component' + defProp $r 'RestUrl' "$jiraServer/rest/api/2/component/11000" + } +} diff --git a/Tests/ConvertTo-JiraCreateMetaField.Tests.ps1 b/Tests/Functions/ConvertTo-JiraCreateMetaField.Unit.Tests.ps1 similarity index 77% rename from Tests/ConvertTo-JiraCreateMetaField.Tests.ps1 rename to Tests/Functions/ConvertTo-JiraCreateMetaField.Unit.Tests.ps1 index 0bd4ca32..d2e79995 100644 --- a/Tests/ConvertTo-JiraCreateMetaField.Tests.ps1 +++ b/Tests/Functions/ConvertTo-JiraCreateMetaField.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "ConvertTo-JiraCreateMetaField" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "ConvertTo-JiraCreateMetaField" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $sampleJson = @' { diff --git a/Tests/ConvertTo-JiraEditMetaField.Tests.ps1 b/Tests/Functions/ConvertTo-JiraEditMetaField.Unit.Tests.ps1 similarity index 72% rename from Tests/ConvertTo-JiraEditMetaField.Tests.ps1 rename to Tests/Functions/ConvertTo-JiraEditMetaField.Unit.Tests.ps1 index 5b923ed4..c488d87b 100644 --- a/Tests/ConvertTo-JiraEditMetaField.Tests.ps1 +++ b/Tests/Functions/ConvertTo-JiraEditMetaField.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "ConvertTo-JiraEditMetaField" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "ConvertTo-JiraEditMetaField" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $sampleJson = @' { diff --git a/Tests/Functions/ConvertTo-JiraField.Unit.Tests.ps1 b/Tests/Functions/ConvertTo-JiraField.Unit.Tests.ps1 new file mode 100644 index 00000000..95af1f45 --- /dev/null +++ b/Tests/Functions/ConvertTo-JiraField.Unit.Tests.ps1 @@ -0,0 +1,54 @@ +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "ConvertTo-JiraField" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + InModuleScope JiraPS { + + . "$PSScriptRoot/../Shared.ps1" + + $sampleJson = '{"id":"issuetype","name":"Issue Type","custom":false,"orderable":true,"navigable":true,"searchable":true,"clauseNames":["issuetype","type"],"schema":{"type":"issuetype","system":"issuetype"}}' + $sampleObject = ConvertFrom-Json -InputObject $sampleJson + + $r = ConvertTo-JiraField $sampleObject + It "Creates a PSObject out of JSON input" { + $r | Should Not BeNullOrEmpty + } + + checkPsType $r 'JiraPS.Field' + + defProp $r 'Id' 'issuetype' + defProp $r 'Name' 'Issue Type' + defProp $r 'Custom' $false + } +} diff --git a/Tests/ConvertTo-JiraFilter.Tests.ps1 b/Tests/Functions/ConvertTo-JiraFilter.Unit.Tests.ps1 similarity index 80% rename from Tests/ConvertTo-JiraFilter.Tests.ps1 rename to Tests/Functions/ConvertTo-JiraFilter.Unit.Tests.ps1 index 0aa7e6a4..92e5dbf8 100644 --- a/Tests/ConvertTo-JiraFilter.Tests.ps1 +++ b/Tests/Functions/ConvertTo-JiraFilter.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "ConvertTo-JiraFilter" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "ConvertTo-JiraFilter" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" # Obtained from Atlassian's public JIRA instance $sampleJson = @' diff --git a/Tests/ConvertTo-JiraFilterPermission.Tests.ps1 b/Tests/Functions/ConvertTo-JiraFilterPermission.Unit.Tests.ps1 similarity index 71% rename from Tests/ConvertTo-JiraFilterPermission.Tests.ps1 rename to Tests/Functions/ConvertTo-JiraFilterPermission.Unit.Tests.ps1 index 2c4f1475..704b5acd 100644 --- a/Tests/ConvertTo-JiraFilterPermission.Tests.ps1 +++ b/Tests/Functions/ConvertTo-JiraFilterPermission.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "ConvertTo-JiraFilterPermission" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "ConvertTo-JiraFilterPermission" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $sampleJson = @" [ diff --git a/Tests/Functions/ConvertTo-JiraGroup.Unit.Tests.ps1 b/Tests/Functions/ConvertTo-JiraGroup.Unit.Tests.ps1 new file mode 100644 index 00000000..b99720aa --- /dev/null +++ b/Tests/Functions/ConvertTo-JiraGroup.Unit.Tests.ps1 @@ -0,0 +1,71 @@ +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "ConvertTo-JiraGroup" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + InModuleScope JiraPS { + + . "$PSScriptRoot/../Shared.ps1" + + $jiraServer = 'http://jiraserver.example.com' + $groupName = 'powershell-testgroup' + + $sampleJson = @" +{ + "self": "$jiraServer/rest/api/2/group?groupname=$groupName", + "name": "$groupName", + "users": { + "size": 1, + "items": [], + "max-results": 50, + "start-index": 0, + "end-index": 0 + }, + "expand": "users" +} +"@ + $sampleObject = ConvertFrom-Json -InputObject $sampleJson + + $r = ConvertTo-JiraGroup -InputObject $sampleObject + + It "Creates a PSObject out of JSON input" { + $r | Should Not BeNullOrEmpty + } + + checkPsType $r 'JiraPS.Group' + + defProp $r 'Name' $groupName + defProp $r 'RestUrl' "$jiraServer/rest/api/2/group?groupname=$groupName" + defProp $r 'Size' 1 + } +} diff --git a/Tests/ConvertTo-JiraIssue.Tests.ps1 b/Tests/Functions/ConvertTo-JiraIssue.Unit.Tests.ps1 similarity index 97% rename from Tests/ConvertTo-JiraIssue.Tests.ps1 rename to Tests/Functions/ConvertTo-JiraIssue.Unit.Tests.ps1 index 308cf524..5c802c68 100644 --- a/Tests/ConvertTo-JiraIssue.Tests.ps1 +++ b/Tests/Functions/ConvertTo-JiraIssue.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "ConvertTo-JiraIssue" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "ConvertTo-JiraIssue" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Functions/ConvertTo-JiraIssueLink.Unit.Tests.ps1 b/Tests/Functions/ConvertTo-JiraIssueLink.Unit.Tests.ps1 new file mode 100644 index 00000000..d64fbe96 --- /dev/null +++ b/Tests/Functions/ConvertTo-JiraIssueLink.Unit.Tests.ps1 @@ -0,0 +1,84 @@ +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "ConvertTo-JiraIssueLink" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + InModuleScope JiraPS { + + . "$PSScriptRoot/../Shared.ps1" + + $jiraServer = 'http://jiraserver.example.com' + + $issueLinkId = 41313 + $issueKeyInward = "TEST-01" + $issueKeyOutward = "TEST-10" + $linkTypeName = "Composition" + + $sampleJson = @" +{ + "id": "$issueLinkId", + "type": { + "id": "10500", + "name": "$linkTypeName", + "inward": "is part of", + "outward": "composes" + }, + "inwardIssue": { + "key": "$issueKeyInward" + }, + "outwardIssue": { + "key": "$issueKeyOutward" + } +} +"@ + + $sampleObject = ConvertFrom-Json -InputObject $sampleJson + + $r = ConvertTo-JiraIssueLink -InputObject $sampleObject + It "Creates a PSObject out of JSON input" { + $r | Should Not BeNullOrEmpty + } + + checkPsType $r 'JiraPS.IssueLink' + + defProp $r 'Id' $issueLinkId + defProp $r 'Type' "Composition" + defProp $r 'InwardIssue' "[$issueKeyInward] " + defProp $r 'OutwardIssue' "[$issueKeyOutward] " + + It "Handles pipeline input" { + $r = $sampleObject | ConvertTo-JiraIssueLink + @($r).Count | Should Be 1 + } + } +} diff --git a/Tests/ConvertTo-JiraIssueLinkType.Tests.ps1 b/Tests/Functions/ConvertTo-JiraIssueLinkType.Unit.Tests.ps1 similarity index 61% rename from Tests/ConvertTo-JiraIssueLinkType.Tests.ps1 rename to Tests/Functions/ConvertTo-JiraIssueLinkType.Unit.Tests.ps1 index 4293961e..2d2464f7 100644 --- a/Tests/ConvertTo-JiraIssueLinkType.Tests.ps1 +++ b/Tests/Functions/ConvertTo-JiraIssueLinkType.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "ConvertTo-JiraIssueLinkType" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "ConvertTo-JiraIssueLinkType" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Functions/ConvertTo-JiraIssueType.Unit.Tests.ps1 b/Tests/Functions/ConvertTo-JiraIssueType.Unit.Tests.ps1 new file mode 100644 index 00000000..de7af3df --- /dev/null +++ b/Tests/Functions/ConvertTo-JiraIssueType.Unit.Tests.ps1 @@ -0,0 +1,72 @@ +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "ConvertTo-JiraIssueType" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + InModuleScope JiraPS { + + . "$PSScriptRoot/../Shared.ps1" + + $jiraServer = 'http://jiraserver.example.com' + + $issueTypeId = 2 + $issueTypeName = 'Test Issue Type' + $issueTypeDescription = 'A test issue used for...well, testing' + + $sampleJson = @" +{ + "self": "$jiraServer/rest/api/latest/issuetype/2", + "id": "$issueTypeId", + "description": "$issueTypeDescription", + "iconUrl": "$jiraServer/images/icons/issuetypes/newfeature.png", + "name": "$issueTypeName", + "subtask": false +} +"@ + $sampleObject = ConvertFrom-Json -InputObject $sampleJson + + $r = ConvertTo-JiraIssueType $sampleObject + It "Creates a PSObject out of JSON input" { + $r | Should Not BeNullOrEmpty + } + + checkPsType $r 'JiraPS.IssueType' + + defProp $r 'Id' $issueTypeId + defProp $r 'Name' $issueTypeName + defProp $r 'Description' $issueTypeDescription + defProp $r 'RestUrl' "$jiraServer/rest/api/latest/issuetype/$issueTypeId" + defProp $r 'IconUrl' "$jiraServer/images/icons/issuetypes/newfeature.png" + defProp $r 'Subtask' $false + } +} diff --git a/Tests/ConvertTo-JiraLink.Tests.ps1 b/Tests/Functions/ConvertTo-JiraLink.Unit.Tests.ps1 similarity index 51% rename from Tests/ConvertTo-JiraLink.Tests.ps1 rename to Tests/Functions/ConvertTo-JiraLink.Unit.Tests.ps1 index 48265448..c0b64335 100644 --- a/Tests/ConvertTo-JiraLink.Tests.ps1 +++ b/Tests/Functions/ConvertTo-JiraLink.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "ConvertTo-JiraLink" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "ConvertTo-JiraLink" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' $LinkID = "10000" diff --git a/Tests/Functions/ConvertTo-JiraPriority.Unit.Tests.ps1 b/Tests/Functions/ConvertTo-JiraPriority.Unit.Tests.ps1 new file mode 100644 index 00000000..c1ea4861 --- /dev/null +++ b/Tests/Functions/ConvertTo-JiraPriority.Unit.Tests.ps1 @@ -0,0 +1,71 @@ +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "ConvertTo-JiraPriority" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + InModuleScope JiraPS { + + . "$PSScriptRoot/../Shared.ps1" + + $jiraServer = 'http://jiraserver.example.com' + + $priorityId = 1 + $priorityName = 'Critical' + $priorityDescription = 'Cannot contine normal operations' + + $sampleJson = @" +{ + "self": "$jiraServer/rest/api/2/priority/1", + "statusColor": "#cc0000", + "description": "$priorityDescription", + "name": "$priorityName", + "id": "$priorityId" + } +"@ + $sampleObject = ConvertFrom-Json -InputObject $sampleJson + + $r = ConvertTo-JiraPriority -InputObject $sampleObject + + It "Creates a PSObject out of JSON input" { + $r | Should Not BeNullOrEmpty + } + + checkPsType $r 'JiraPS.Priority' + + defProp $r 'Id' $priorityId + defProp $r 'Name' $priorityName + defProp $r 'RestUrl' "$jiraServer/rest/api/2/priority/$priorityId" + defProp $r 'Description' $priorityDescription + defProp $r 'StatusColor' '#cc0000' + } +} diff --git a/Tests/ConvertTo-JiraProject.Tests.ps1 b/Tests/Functions/ConvertTo-JiraProject.Unit.Tests.ps1 similarity index 65% rename from Tests/ConvertTo-JiraProject.Tests.ps1 rename to Tests/Functions/ConvertTo-JiraProject.Unit.Tests.ps1 index 113f78cb..87abfd56 100644 --- a/Tests/ConvertTo-JiraProject.Tests.ps1 +++ b/Tests/Functions/ConvertTo-JiraProject.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "ConvertTo-JiraProject" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "ConvertTo-JiraProject" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Functions/ConvertTo-JiraProjectRole.Unit.Tests.ps1 b/Tests/Functions/ConvertTo-JiraProjectRole.Unit.Tests.ps1 new file mode 100644 index 00000000..0ffaf745 --- /dev/null +++ b/Tests/Functions/ConvertTo-JiraProjectRole.Unit.Tests.ps1 @@ -0,0 +1,80 @@ +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "ConvertTo-JiraProjectRole" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + InModuleScope JiraPS { + + . "$PSScriptRoot/../Shared.ps1" + + $sampleJson = @" +[ + { + "self": "http://www.example.com/jira/rest/api/2/project/MKY/role/10360", + "name": "Developers", + "id": 10360, + "description": "A project role that represents developers in a project", + "actors": [ + { + "id": 10240, + "displayName": "jira-developers", + "type": "atlassian-group-role-actor", + "name": "jira-developers" + }, + { + "id": 10241, + "displayName": "Fred F. User", + "type": "atlassian-user-role-actor", + "name": "fred" + } + ] + } +] +"@ + + $sampleObject = ConvertFrom-Json -InputObject $sampleJson + $r = ConvertTo-JiraProjectRole -InputObject $sampleObject + + It "Creates a PSObject out of JSON input" { + $r | Should -Not -BeNullOrEmpty + } + + checkPsType $r 'JiraPS.ProjectRole' + + defProp $r 'Id' 10360 + defProp $r 'Name' "Developers" + defProp $r 'Description' "A project role that represents developers in a project" + hasProp $r 'Actors' + defProp $r 'RestUrl' "http://www.example.com/jira/rest/api/2/project/MKY/role/10360" + } +} diff --git a/Tests/Functions/ConvertTo-JiraServerInfo.Unit.Tests.ps1 b/Tests/Functions/ConvertTo-JiraServerInfo.Unit.Tests.ps1 new file mode 100644 index 00000000..b8ffc8d4 --- /dev/null +++ b/Tests/Functions/ConvertTo-JiraServerInfo.Unit.Tests.ps1 @@ -0,0 +1,75 @@ +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "ConvertTo-JiraServerInfo" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + InModuleScope JiraPS { + + . "$PSScriptRoot/../Shared.ps1" + + $jiraServer = 'http://jiraserver.example.com' + + $sampleJson = @" +{ + "baseUrl":"$jiraServer", + "version":"1000.1323.0", + "versionNumbers":[1000,1323,0], + "deploymentType":"Cloud", + "buildNumber":100062, + "buildDate":"2017-09-26T00:00:00.000+0200", + "serverTime":"2017-09-27T09:59:25.520+0200", + "scmInfo":"f3c60100df073e3576f9741fb7a3dc759b416fde", + "serverTitle":"JIRA" +} +"@ + + $sampleObject = ConvertFrom-Json -InputObject $sampleJson + $r = ConvertTo-JiraServerInfo -InputObject $sampleObject + + It "Creates a PSObject out of JSON input" { + $r | Should Not BeNullOrEmpty + } + + checkPsType $r 'JiraPS.ServerInfo' + + + defProp $r 'BaseURL' $jiraServer + defProp $r 'Version' ([Version]"1000.1323.0") + defProp $r 'DeploymentType' "Cloud" + defProp $r 'BuildNumber' 100062 + defProp $r 'BuildDate' (Get-Date '2017-09-26T00:00:00.000+0200') + defProp $r 'ServerTime' (Get-Date '2017-09-27T09:59:25.520+0200') + defProp $r 'ScmInfo' "f3c60100df073e3576f9741fb7a3dc759b416fde" + defProp $r 'ServerTitle' "JIRA" + } +} diff --git a/Tests/Functions/ConvertTo-JiraSession.Unit.Tests.ps1 b/Tests/Functions/ConvertTo-JiraSession.Unit.Tests.ps1 new file mode 100644 index 00000000..4d88903d --- /dev/null +++ b/Tests/Functions/ConvertTo-JiraSession.Unit.Tests.ps1 @@ -0,0 +1,52 @@ +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "ConvertTo-JiraSession" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + InModuleScope JiraPS { + + . "$PSScriptRoot/../Shared.ps1" + + $sampleUsername = 'powershell-test' + $sampleSession = @{} + + $r = ConvertTo-JiraSession -Session $sampleSession -Username $sampleUsername + + It "Creates a PSObject out of Web request data" { + $r | Should Not BeNullOrEmpty + } + + checkPsType $r 'JiraPS.Session' + defProp $r 'Username' $sampleUsername + } +} diff --git a/Tests/Functions/ConvertTo-JiraStatus.Unit.Tests.ps1 b/Tests/Functions/ConvertTo-JiraStatus.Unit.Tests.ps1 new file mode 100644 index 00000000..88d71872 --- /dev/null +++ b/Tests/Functions/ConvertTo-JiraStatus.Unit.Tests.ps1 @@ -0,0 +1,78 @@ +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "ConvertTo-JiraStatus" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + InModuleScope JiraPS { + + . "$PSScriptRoot/../Shared.ps1" + + $jiraServer = 'http://jiraserver.example.com' + + $statusName = 'In Progress' + $statusId = 3 + $statusDesc = 'This issue is being actively worked on at the moment by the assignee.' + + $sampleJson = @" +{ + "self": "$jiraServer/rest/api/2/status/$statusId", + "description": "$statusDesc", + "iconUrl": "$jiraServer/images/icons/statuses/inprogress.png", + "name": "$statusName", + "id": "$statusId", + "statusCategory": { + "self": "$jiraServer/rest/api/2/statuscategory/4", + "id": 4, + "key": "indeterminate", + "colorName": "yellow", + "name": "In Progress" + } +} +"@ + $sampleObject = ConvertFrom-Json -InputObject $sampleJson + + $r = ConvertTo-JiraStatus -InputObject $sampleObject + + It "Creates a PSObject out of JSON input" { + $r | Should Not BeNullOrEmpty + } + + checkPsType $r 'JiraPS.Status' + + defProp $r 'Id' $statusId + defProp $r 'Name' $statusName + defProp $r 'Description' $statusDesc + defProp $r 'IconUrl' "$jiraServer/images/icons/statuses/inprogress.png" + defProp $r 'RestUrl' "$jiraServer/rest/api/2/status/$statusId" + } +} diff --git a/Tests/ConvertTo-JiraTransition.Tests.ps1 b/Tests/Functions/ConvertTo-JiraTransition.Unit.Tests.ps1 similarity index 50% rename from Tests/ConvertTo-JiraTransition.Tests.ps1 rename to Tests/Functions/ConvertTo-JiraTransition.Unit.Tests.ps1 index 1d1feb02..06ea0916 100644 --- a/Tests/ConvertTo-JiraTransition.Tests.ps1 +++ b/Tests/Functions/ConvertTo-JiraTransition.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "ConvertTo-JiraTransition" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "ConvertTo-JiraTransition" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/ConvertTo-JiraUser.Tests.ps1 b/Tests/Functions/ConvertTo-JiraUser.Unit.Tests.ps1 similarity index 69% rename from Tests/ConvertTo-JiraUser.Tests.ps1 rename to Tests/Functions/ConvertTo-JiraUser.Unit.Tests.ps1 index 74c72d0a..99881b94 100644 --- a/Tests/ConvertTo-JiraUser.Tests.ps1 +++ b/Tests/Functions/ConvertTo-JiraUser.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "ConvertTo-JiraUser" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "ConvertTo-JiraUser" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' $username = 'powershell-test' diff --git a/Tests/ConvertTo-JiraVersion.Tests.ps1 b/Tests/Functions/ConvertTo-JiraVersion.Unit.Tests.ps1 similarity index 52% rename from Tests/ConvertTo-JiraVersion.Tests.ps1 rename to Tests/Functions/ConvertTo-JiraVersion.Unit.Tests.ps1 index 03583050..fdca64bf 100644 --- a/Tests/ConvertTo-JiraVersion.Tests.ps1 +++ b/Tests/Functions/ConvertTo-JiraVersion.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "ConvertTo-JiraVersion" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "ConvertTo-JiraVersion" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/ConvertTo-JiraWorklogitem.Tests.ps1 b/Tests/Functions/ConvertTo-JiraWorklogitem.Unit.Tests.ps1 similarity index 68% rename from Tests/ConvertTo-JiraWorklogitem.Tests.ps1 rename to Tests/Functions/ConvertTo-JiraWorklogitem.Unit.Tests.ps1 index 6b2b8917..ae3855a1 100644 --- a/Tests/ConvertTo-JiraWorklogitem.Tests.ps1 +++ b/Tests/Functions/ConvertTo-JiraWorklogitem.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "ConvertTo-JiraWorklogitem" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "ConvertTo-JiraWorklogitem" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' $jiraUsername = 'powershell-test' diff --git a/Tests/ConvertTo-URLEncoded.Tests.ps1 b/Tests/Functions/ConvertTo-URLEncoded.Unit.Tests.ps1 similarity index 52% rename from Tests/ConvertTo-URLEncoded.Tests.ps1 rename to Tests/Functions/ConvertTo-URLEncoded.Unit.Tests.ps1 index 08640693..849f2309 100644 --- a/Tests/ConvertTo-URLEncoded.Tests.ps1 +++ b/Tests/Functions/ConvertTo-URLEncoded.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "ConvertTo-URLEncoded" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "ConvertTo-URLEncoded" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" Context "Sanity checking" { $command = Get-Command -Name ConvertTo-URLEncoded diff --git a/Tests/Format-Jira.Tests.ps1 b/Tests/Functions/Format-Jira.Unit.Tests.ps1 similarity index 78% rename from Tests/Format-Jira.Tests.ps1 rename to Tests/Functions/Format-Jira.Unit.Tests.ps1 index 858afb39..5cc46335 100644 --- a/Tests/Format-Jira.Tests.ps1 +++ b/Tests/Functions/Format-Jira.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Format-Jira" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Format-Jira" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $n = [System.Environment]::NewLine $obj = [PSCustomObject] @{ diff --git a/Tests/Get-JiraComponent.Tests.ps1 b/Tests/Functions/Get-JiraComponent.Unit.Tests.ps1 similarity index 61% rename from Tests/Get-JiraComponent.Tests.ps1 rename to Tests/Functions/Get-JiraComponent.Unit.Tests.ps1 index d1746c08..fbc1c153 100644 --- a/Tests/Get-JiraComponent.Tests.ps1 +++ b/Tests/Functions/Get-JiraComponent.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraComponent" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraComponent" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Functions/Get-JiraConfigServer.Unit.Tests.ps1 b/Tests/Functions/Get-JiraConfigServer.Unit.Tests.ps1 new file mode 100644 index 00000000..11596524 --- /dev/null +++ b/Tests/Functions/Get-JiraConfigServer.Unit.Tests.ps1 @@ -0,0 +1,54 @@ +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "Get-JiraConfigServer" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + InModuleScope JiraPS { + + . "$PSScriptRoot/../Shared.ps1" + + $jiraServer = 'http://jiraserver.example.com' + + $configFile = Join-Path -Path $TestDrive -ChildPath 'config.xml' + + It "Throws an exception if the config file does not exist" { + { Get-JiraConfigServer -ConfigFile $configFile } | Should Throw + } + + It "Returns the defined Server in the config.xml file" { + Set-JiraConfigServer -Server $jiraServer -ConfigFile $configFile + $s = Get-JiraConfigServer -ConfigFile $configFile + $s | Should Be $jiraServer + } + } +} diff --git a/Tests/Get-JiraField.Tests.ps1 b/Tests/Functions/Get-JiraField.Unit.Tests.ps1 similarity index 77% rename from Tests/Get-JiraField.Tests.ps1 rename to Tests/Functions/Get-JiraField.Unit.Tests.ps1 index 7d2a1c0a..c006e6c8 100644 --- a/Tests/Get-JiraField.Tests.ps1 +++ b/Tests/Functions/Get-JiraField.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraField" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraField" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Get-JiraFilter.Tests.ps1 b/Tests/Functions/Get-JiraFilter.Unit.Tests.ps1 similarity index 84% rename from Tests/Get-JiraFilter.Tests.ps1 rename to Tests/Functions/Get-JiraFilter.Unit.Tests.ps1 index 9106035c..acedcec9 100644 --- a/Tests/Get-JiraFilter.Tests.ps1 +++ b/Tests/Functions/Get-JiraFilter.Unit.Tests.ps1 @@ -1,12 +1,41 @@ -Describe 'Get-JiraFilter' { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe 'Get-JiraFilter' -Tag 'Unit' { + BeforeAll { - Remove-Module JiraPS -ErrorAction SilentlyContinue - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" #region Definitions $jiraServer = "https://jira.example.com" diff --git a/Tests/Get-JiraFilterPermission.Tests.ps1 b/Tests/Functions/Get-JiraFilterPermission.unit.Tests.ps1 similarity index 76% rename from Tests/Get-JiraFilterPermission.Tests.ps1 rename to Tests/Functions/Get-JiraFilterPermission.unit.Tests.ps1 index 71ff2533..89729c90 100644 --- a/Tests/Get-JiraFilterPermission.Tests.ps1 +++ b/Tests/Functions/Get-JiraFilterPermission.unit.Tests.ps1 @@ -1,12 +1,41 @@ -Describe 'Get-JiraFilterPermission' { - BeforeAll { - Remove-Module JiraPS -ErrorAction SilentlyContinue - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe 'Get-JiraFilterPermission' -Tag 'Unit' { + +BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" #region Definitions $jiraServer = "https://jira.example.com" diff --git a/Tests/Get-JiraGroup.Tests.ps1 b/Tests/Functions/Get-JiraGroup.Unit.Tests.ps1 similarity index 55% rename from Tests/Get-JiraGroup.Tests.ps1 rename to Tests/Functions/Get-JiraGroup.Unit.Tests.ps1 index 78fbd382..815b92c2 100644 --- a/Tests/Get-JiraGroup.Tests.ps1 +++ b/Tests/Functions/Get-JiraGroup.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraGroup" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraGroup" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Get-JiraGroupMember.Tests.ps1 b/Tests/Functions/Get-JiraGroupMember.Unit.Tests.ps1 similarity index 81% rename from Tests/Get-JiraGroupMember.Tests.ps1 rename to Tests/Functions/Get-JiraGroupMember.Unit.Tests.ps1 index 08f24ffc..ccdd41ef 100644 --- a/Tests/Get-JiraGroupMember.Tests.ps1 +++ b/Tests/Functions/Get-JiraGroupMember.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraGroupMember" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraGroupMember" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" #region Mocks Mock Get-JiraConfigServer -ModuleName JiraPS { diff --git a/Tests/Get-JiraIssue.Tests.ps1 b/Tests/Functions/Get-JiraIssue.Unit.Tests.ps1 similarity index 83% rename from Tests/Get-JiraIssue.Tests.ps1 rename to Tests/Functions/Get-JiraIssue.Unit.Tests.ps1 index 8ecd54fc..b8a145b0 100644 --- a/Tests/Get-JiraIssue.Tests.ps1 +++ b/Tests/Functions/Get-JiraIssue.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraIssue" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraIssue" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = "https://jira.example.com" diff --git a/Tests/Get-JiraIssueAttachment.Tests.ps1 b/Tests/Functions/Get-JiraIssueAttachment.Unit.Tests.ps1 similarity index 73% rename from Tests/Get-JiraIssueAttachment.Tests.ps1 rename to Tests/Functions/Get-JiraIssueAttachment.Unit.Tests.ps1 index 835093ba..8bfe542e 100644 --- a/Tests/Get-JiraIssueAttachment.Tests.ps1 +++ b/Tests/Functions/Get-JiraIssueAttachment.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraIssueAttachment" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraIssueAttachment" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' $issueID = 41701 diff --git a/Tests/Get-JiraIssueComment.Tests.ps1 b/Tests/Functions/Get-JiraIssueComment.Unit.Tests.ps1 similarity index 72% rename from Tests/Get-JiraIssueComment.Tests.ps1 rename to Tests/Functions/Get-JiraIssueComment.Unit.Tests.ps1 index 471af529..1ad17416 100644 --- a/Tests/Get-JiraIssueComment.Tests.ps1 +++ b/Tests/Functions/Get-JiraIssueComment.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraIssueComment" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraIssueComment" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Get-JiraIssueCreateMetadata.Tests.ps1 b/Tests/Functions/Get-JiraIssueCreateMetadata.Unit.Tests.ps1 similarity index 87% rename from Tests/Get-JiraIssueCreateMetadata.Tests.ps1 rename to Tests/Functions/Get-JiraIssueCreateMetadata.Unit.Tests.ps1 index e9066dc7..8562c198 100644 --- a/Tests/Get-JiraIssueCreateMetadata.Tests.ps1 +++ b/Tests/Functions/Get-JiraIssueCreateMetadata.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraIssueCreateMetadata" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraIssueCreateMetadata" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'https://jira.example.com' diff --git a/Tests/Get-JiraIssueEditMetadata.Tests.ps1 b/Tests/Functions/Get-JiraIssueEditMetadata.Unit.Tests.ps1 similarity index 84% rename from Tests/Get-JiraIssueEditMetadata.Tests.ps1 rename to Tests/Functions/Get-JiraIssueEditMetadata.Unit.Tests.ps1 index da3fbb5f..999102c9 100644 --- a/Tests/Get-JiraIssueEditMetadata.Tests.ps1 +++ b/Tests/Functions/Get-JiraIssueEditMetadata.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraIssueEditMetadata" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraIssueEditMetadata" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = "https://jira.example.com" $issueID = 41701 diff --git a/Tests/Get-JiraIssueLink.Tests.ps1 b/Tests/Functions/Get-JiraIssueLink.Unit.Tests.ps1 similarity index 62% rename from Tests/Get-JiraIssueLink.Tests.ps1 rename to Tests/Functions/Get-JiraIssueLink.Unit.Tests.ps1 index 2db6bc25..1980e9b0 100644 --- a/Tests/Get-JiraIssueLink.Tests.ps1 +++ b/Tests/Functions/Get-JiraIssueLink.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraIssueLink" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraIssueLink" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Get-JiraIssueLinkType.Tests.ps1 b/Tests/Functions/Get-JiraIssueLinkType.Unit.Tests.ps1 similarity index 74% rename from Tests/Get-JiraIssueLinkType.Tests.ps1 rename to Tests/Functions/Get-JiraIssueLinkType.Unit.Tests.ps1 index 5caf6f9c..73b298bd 100644 --- a/Tests/Get-JiraIssueLinkType.Tests.ps1 +++ b/Tests/Functions/Get-JiraIssueLinkType.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe 'Get-JiraIssueLinkType' { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe 'Get-JiraIssueLinkType' -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Get-JiraIssueType.Tests.ps1 b/Tests/Functions/Get-JiraIssueType.Unit.Tests.ps1 similarity index 78% rename from Tests/Get-JiraIssueType.Tests.ps1 rename to Tests/Functions/Get-JiraIssueType.Unit.Tests.ps1 index f4a01b75..f6c346d6 100644 --- a/Tests/Get-JiraIssueType.Tests.ps1 +++ b/Tests/Functions/Get-JiraIssueType.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraIssueType" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraIssueType" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Get-JiraIssueWatcher.Tests.ps1 b/Tests/Functions/Get-JiraIssueWatcher.Unit.Tests.ps1 similarity index 74% rename from Tests/Get-JiraIssueWatcher.Tests.ps1 rename to Tests/Functions/Get-JiraIssueWatcher.Unit.Tests.ps1 index 2d1f2cc0..29a8bfa8 100644 --- a/Tests/Get-JiraIssueWatcher.Tests.ps1 +++ b/Tests/Functions/Get-JiraIssueWatcher.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraIssueWatcher" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraIssueWatcher" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'https://jiraserver.example.com' $issueID = 41701 diff --git a/Tests/Get-JiraPriority.Tests.ps1 b/Tests/Functions/Get-JiraPriority.Unit.Tests.ps1 similarity index 67% rename from Tests/Get-JiraPriority.Tests.ps1 rename to Tests/Functions/Get-JiraPriority.Unit.Tests.ps1 index 31abccc6..7d84e0f6 100644 --- a/Tests/Get-JiraPriority.Tests.ps1 +++ b/Tests/Functions/Get-JiraPriority.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraPriority" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraPriority" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Get-JiraProject.Tests.ps1 b/Tests/Functions/Get-JiraProject.Unit.Tests.ps1 similarity index 72% rename from Tests/Get-JiraProject.Tests.ps1 rename to Tests/Functions/Get-JiraProject.Unit.Tests.ps1 index 0e2ea202..b54fc4b5 100644 --- a/Tests/Get-JiraProject.Tests.ps1 +++ b/Tests/Functions/Get-JiraProject.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraProject" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraProject" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Get-JiraRemoteLink.Tests.ps1 b/Tests/Functions/Get-JiraRemoteLink.Unit.Tests.ps1 similarity index 72% rename from Tests/Get-JiraRemoteLink.Tests.ps1 rename to Tests/Functions/Get-JiraRemoteLink.Unit.Tests.ps1 index bd5ad624..dd0bd0c2 100644 --- a/Tests/Get-JiraRemoteLink.Tests.ps1 +++ b/Tests/Functions/Get-JiraRemoteLink.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraRemoteLink" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraRemoteLink" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'https://jiraserver.example.com' diff --git a/Tests/Get-JiraServerInformation.Tests.ps1 b/Tests/Functions/Get-JiraServerInformation.Unit.Tests.ps1 similarity index 55% rename from Tests/Get-JiraServerInformation.Tests.ps1 rename to Tests/Functions/Get-JiraServerInformation.Unit.Tests.ps1 index 55bdfe0c..9869494d 100644 --- a/Tests/Get-JiraServerInformation.Tests.ps1 +++ b/Tests/Functions/Get-JiraServerInformation.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraServerInformation" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraServerInformation" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Functions/Get-JiraSession.Unit.Tests.ps1 b/Tests/Functions/Get-JiraSession.Unit.Tests.ps1 new file mode 100644 index 00000000..f6ba70ae --- /dev/null +++ b/Tests/Functions/Get-JiraSession.Unit.Tests.ps1 @@ -0,0 +1,47 @@ +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "Get-JiraSession" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + InModuleScope JiraPS { + + . "$PSScriptRoot/../Shared.ps1" + + It "Obtains a saved JiraPS.Session object from module PrivateData" { + # I don't know how to test this, since I can't access module PrivateData from Pester. + # The tests for New-JiraSession use this function to validate that they work, so if + # those tests pass, this function should be working as well. + # $true | Should Be $true + } + } +} diff --git a/Tests/Get-JiraUser.Tests.ps1 b/Tests/Functions/Get-JiraUser.Unit.Tests.ps1 similarity index 82% rename from Tests/Get-JiraUser.Tests.ps1 rename to Tests/Functions/Get-JiraUser.Unit.Tests.ps1 index 203ea66a..0c69089d 100644 --- a/Tests/Get-JiraUser.Tests.ps1 +++ b/Tests/Functions/Get-JiraUser.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraUser" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraUser" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Get-JiraVersion.Tests.ps1 b/Tests/Functions/Get-JiraVersion.Unit.Tests.ps1 similarity index 93% rename from Tests/Get-JiraVersion.Tests.ps1 rename to Tests/Functions/Get-JiraVersion.Unit.Tests.ps1 index 2af2a5e1..76b6116c 100644 --- a/Tests/Get-JiraVersion.Tests.ps1 +++ b/Tests/Functions/Get-JiraVersion.Unit.Tests.ps1 @@ -1,13 +1,41 @@ -Describe "Get-JiraVersion" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "Get-JiraVersion" -Tag 'Unit' { BeforeAll { - Remove-Module JiraPS -ErrorAction SilentlyContinue - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" #region Definitions $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Invoke-JiraIssueTransition.Tests.ps1 b/Tests/Functions/Invoke-JiraIssueTransition.Unit.Tests.ps1 similarity index 83% rename from Tests/Invoke-JiraIssueTransition.Tests.ps1 rename to Tests/Functions/Invoke-JiraIssueTransition.Unit.Tests.ps1 index bd91c2b2..5cc7c73c 100644 --- a/Tests/Invoke-JiraIssueTransition.Tests.ps1 +++ b/Tests/Functions/Invoke-JiraIssueTransition.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Invoke-JiraIssueTransition" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Invoke-JiraIssueTransition" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' $issueID = 41701 diff --git a/Tests/Invoke-JiraMethod.Tests.ps1 b/Tests/Functions/Invoke-JiraMethod.Unit.Tests.ps1 similarity index 80% rename from Tests/Invoke-JiraMethod.Tests.ps1 rename to Tests/Functions/Invoke-JiraMethod.Unit.Tests.ps1 index 6749f9a2..45f67dd6 100644 --- a/Tests/Invoke-JiraMethod.Tests.ps1 +++ b/Tests/Functions/Invoke-JiraMethod.Unit.Tests.ps1 @@ -1,18 +1,44 @@ +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param() -Describe "Invoke-JiraMethod" { +Describe "Invoke-JiraMethod" -Tag 'Unit' { + BeforeAll { - Remove-Module JiraPS -ErrorAction SilentlyContinue - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest } - AfterEach { - # $script:ShowMockData = $false + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* } - InModuleScope JiraPS { + InModuleScope $env:BHProjectName { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" #region Definitions @@ -50,31 +76,32 @@ Describe "Invoke-JiraMethod" { #endregion Definitions #region Mocks - Mock Resolve-DefaultParameterValue -ModuleName JiraPS { @{ } } - Mock Join-Hashtable -ModuleName JiraPS { @{ } } - Mock Set-TlsLevel -ModuleName JiraPS { } - Mock Resolve-ErrorWebResponse -ModuleName JiraPS { } - Mock Expand-Result -ModuleName JiraPS { } - Mock Convert-Result -ModuleName JiraPS { } - Mock Get-JiraSession -ModuleName JiraPS { + Mock Resolve-DefaultParameterValue -ModuleName $env:BHProjectName { @{ } } + Mock Join-Hashtable -ModuleName $env:BHProjectName { @{ } } + Mock Set-TlsLevel -ModuleName $env:BHProjectName { } + Mock Resolve-ErrorWebResponse -ModuleName $env:BHProjectName { } + Mock Expand-Result -ModuleName $env:BHProjectName { } + Mock Convert-Result -ModuleName $env:BHProjectName { } + Mock Get-JiraSession -ModuleName $env:BHProjectName { [PSCustomObject]@{ WebSession = New-Object -TypeName Microsoft.PowerShell.Commands.WebRequestSession } } - Mock Test-ServerResponse -Module JiraPS { } - Mock ConvertTo-JiraSession -ModuleName JiraPS { } + Mock Test-ServerResponse -Module $env:BHProjectName { } + Mock ConvertTo-JiraSession -ModuleName $env:BHProjectName { } foreach ($type in $supportedTypes) { - Mock -CommandName "ConvertTo-$type" -ModuleName JiraPS { } + Mock -CommandName "ConvertTo-$type" -ModuleName $env:BHProjectName { } } - Mock Invoke-WebRequest -ModuleName JiraPS { + Mock Invoke-WebRequest -ModuleName $env:BHProjectName { ShowMockInfo 'Invoke-WebRequest' -Params 'Uri', 'Method', 'Body', 'Headers', 'ContentType', 'SessionVariable', 'WebSession' $InvokeWebRequestSplat = @{ - Uri = $Uri - Method = $Method - Body = $Body - Headers = $Headers - WebSession = $WebSession - ContentType = $ContentType + Uri = $Uri + Method = $Method + Body = $Body + Headers = $Headers + WebSession = $WebSession + ContentType = $ContentType + UseBasicParsing = $true } if ($SessionVariable) { $InvokeWebRequestSplat["SessionVariable"] = $SessionVariable @@ -117,7 +144,7 @@ Describe "Invoke-JiraMethod" { $assertMockCalledSplat = @{ CommandName = 'Invoke-WebRequest' - ModuleName = 'JiraPS' + ModuleName = $env:BHProjectName Exactly = $true Times = 1 Scope = 'It' @@ -134,21 +161,21 @@ Describe "Invoke-JiraMethod" { It "resolves errors" { Invoke-JiraMethod -URI "https://postman-echo.com/status/400" -ErrorAction Stop - Assert-MockCalled -CommandName Resolve-ErrorWebResponse -ModuleName JiraPS -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Resolve-ErrorWebResponse -ModuleName $env:BHProjectName -Exactly -Times 1 -Scope It } It "supports TLS1.2 connections" { Invoke-JiraMethod -URI "https://postman-echo.com/get?test=123" -ErrorAction Stop - Assert-MockCalled -CommandName Set-TlsLevel -ModuleName JiraPS -Exactly -Times 2 -Scope It - Assert-MockCalled -CommandName Set-TlsLevel -ModuleName JiraPS -ParameterFilter {$Tls12 -eq $true} -Exactly -Times 1 -Scope It - Assert-MockCalled -CommandName Set-TlsLevel -ModuleName JiraPS -ParameterFilter {$Revert -eq $true} -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Set-TlsLevel -ModuleName $env:BHProjectName -Exactly -Times 2 -Scope It + Assert-MockCalled -CommandName Set-TlsLevel -ModuleName $env:BHProjectName -ParameterFilter {$Tls12 -eq $true} -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Set-TlsLevel -ModuleName $env:BHProjectName -ParameterFilter {$Revert -eq $true} -Exactly -Times 1 -Scope It } It "uses global default values for parameters" { Invoke-JiraMethod -URI "https://postman-echo.com/get?test=123" -ErrorAction Stop - Assert-MockCalled -CommandName Resolve-DefaultParameterValue -ModuleName JiraPS -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Resolve-DefaultParameterValue -ModuleName $env:BHProjectName -Exactly -Times 1 -Scope It } } @@ -169,7 +196,7 @@ Describe "Invoke-JiraMethod" { $assertMockCalledSplat = @{ CommandName = 'Invoke-WebRequest' - ModuleName = 'JiraPS' + ModuleName = $env:BHProjectName ParameterFilter = { $Method -eq $method } @@ -191,11 +218,11 @@ Describe "Invoke-JiraMethod" { $assertMockCalledSplat = @{ CommandName = 'Invoke-WebRequest' - ModuleName = 'JiraPS' + ModuleName = $env:BHProjectName ParameterFilter = { $Body -is [Byte[]] -and (($Body -join " ") -eq "76 111 114 101 109 32 195 153 226 128 166 195 152 194 177 195 152 194 173 195 152 194 168 195 152 194 167 32 195 144 226 128 148 195 144 194 180 195 145 226 130 172 195 144 194 176 195 144 194 178 195 145 194 129 195 145 226 128 154 195 144 194 178 195 145 198 146 195 144 194 185 195 145 226 128 154 195 144 194 181 32 195 176 197 184 203 156 194 129" -or - ($Body -join " ") -eq "76 111 114 101 109 32 217 133 216 177 216 173 216 168 216 167 32 208 151 208 180 209 128 208 176 208 178 209 129 209 130 208 178 209 131 208 185 209 130 208 181 32 240 159 152 129") + ($Body -join " ") -eq "76 111 114 101 109 32 217 133 216 177 216 173 216 168 216 167 32 208 151 208 180 209 128 208 176 208 178 209 129 209 130 208 178 209 131 208 185 209 130 208 181 32 240 159 152 129") } Exactly = $true Times = 1 @@ -215,7 +242,7 @@ Describe "Invoke-JiraMethod" { $assertMockCalledSplat = @{ CommandName = 'Invoke-WebRequest' - ModuleName = 'JiraPS' + ModuleName = $env:BHProjectName ParameterFilter = { $Body -is [String] -and $Body -eq $utf8String @@ -245,7 +272,7 @@ Describe "Invoke-JiraMethod" { $assertMockCalledSplat = @{ CommandName = 'Invoke-WebRequest' - ModuleName = 'JiraPS' + ModuleName = $env:BHProjectName ParameterFilter = { $inFile -eq "./file-does-not-exist.txt" } @@ -266,7 +293,7 @@ Describe "Invoke-JiraMethod" { $assertMockCalledSplat = @{ CommandName = 'Invoke-WebRequest' - ModuleName = 'JiraPS' + ModuleName = $env:BHProjectName ParameterFilter = { $OutFile -eq "./file-does-not-exist.txt" } @@ -288,14 +315,14 @@ Describe "Invoke-JiraMethod" { $assertMockCalledSplat = @{ CommandName = "Invoke-WebRequest" - ModuleName = 'JiraPS' + ModuleName = $env:BHProjectName ParameterFilter = {$SessionVariable -eq "newSessionVar"} Exactly = $true Times = 1 Scope = 'It' } Assert-MockCalled @assertMockCalledSplat - Assert-MockCalled -CommandName ConvertTo-JiraSession -ModuleName JiraPS -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName ConvertTo-JiraSession -ModuleName $env:BHProjectName -Exactly -Times 1 -Scope It } foreach ($type in $supportedTypes) { @@ -303,12 +330,12 @@ Describe "Invoke-JiraMethod" { Invoke-JiraMethod -Method get -URI "https://postman-echo.com/get" -OutputType $type -Paging -ErrorAction Stop $assertMockCalledSplat = @{ - CommandName = "Convert-Result" - ModuleName = 'JiraPS' + CommandName = "Convert-Result" + ModuleName = $env:BHProjectName ParameterFilter = { $OutputType -eq $type} - Exactly = $true - Times = 1 - Scope = 'It' + Exactly = $true + Times = 1 + Scope = 'It' } Assert-MockCalled @assertMockCalledSplat } @@ -317,12 +344,12 @@ Describe "Invoke-JiraMethod" { Invoke-JiraMethod -Method get -URI "https://postman-echo.com/get" -OutputType $type -ErrorAction Stop $assertMockCalledSplat = @{ - CommandName = "Convert-Result" - ModuleName = 'JiraPS' + CommandName = "Convert-Result" + ModuleName = $env:BHProjectName ParameterFilter = { $OutputType -eq $type} - Exactly = $true - Times = 0 - Scope = 'It' + Exactly = $true + Times = 0 + Scope = 'It' } Assert-MockCalled @assertMockCalledSplat } @@ -338,7 +365,7 @@ Describe "Invoke-JiraMethod" { $assertMockCalledSplat = @{ CommandName = 'Invoke-WebRequest' - ModuleName = 'JiraPS' + ModuleName = $env:BHProjectName ParameterFilter = { $WebSession -is [Microsoft.PowerShell.Commands.WebRequestSession] -and $Credential -eq $null @@ -348,11 +375,11 @@ Describe "Invoke-JiraMethod" { Scope = 'It' } Assert-MockCalled @assertMockCalledSplat - Assert-MockCalled -CommandName Get-JiraSession -ModuleName JiraPS -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Get-JiraSession -ModuleName $env:BHProjectName -Exactly -Times 1 -Scope It } It "uses -Credential even if session is present" { - Mock Get-JiraSession -ModuleName JiraPS { + Mock Get-JiraSession -ModuleName $env:BHProjectName { [PSCustomObject]@{ WebSession = New-Object -TypeName Microsoft.PowerShell.Commands.WebRequestSession } @@ -368,7 +395,7 @@ Describe "Invoke-JiraMethod" { $assertMockCalledSplat = @{ CommandName = 'Invoke-WebRequest' - ModuleName = 'JiraPS' + ModuleName = $env:BHProjectName ParameterFilter = { $SessionVariable -eq $null -and $Credential -ne $null @@ -378,11 +405,11 @@ Describe "Invoke-JiraMethod" { Scope = 'It' } Assert-MockCalled @assertMockCalledSplat - Assert-MockCalled -CommandName Get-JiraSession -ModuleName JiraPS -Exactly -Times 0 -Scope It + Assert-MockCalled -CommandName Get-JiraSession -ModuleName $env:BHProjectName -Exactly -Times 0 -Scope It } It "uses -Headers for the call" { - Mock Join-Hashtable -ModuleName JiraPS { + Mock Join-Hashtable -ModuleName $env:BHProjectName { $table = @{ } foreach ($item in $Hashtable) { foreach ($key in $item.Keys) { @@ -412,7 +439,7 @@ Describe "Invoke-JiraMethod" { $assertMockCalledSplat = @{ CommandName = "Invoke-WebRequest" - ModuleName = 'JiraPS' + ModuleName = $env:BHProjectName Exactly = $true Times = 2 Scope = 'It' @@ -421,7 +448,7 @@ Describe "Invoke-JiraMethod" { } It "uses authenticates as anonymous when no -Credential is provided and no session exists" -pending { - Mock Get-JiraSession -ModuleName JiraPS { + Mock Get-JiraSession -ModuleName $env:BHProjectName { $null } @@ -434,7 +461,7 @@ Describe "Invoke-JiraMethod" { $assertMockCalledSplat = @{ CommandName = "Invoke-WebRequest" - ModuleName = 'JiraPS' + ModuleName = $env:BHProjectName ParameterFilter = { $Credential -eq $null -and $WebSession -eq $null @@ -447,7 +474,7 @@ Describe "Invoke-JiraMethod" { } It "removes and content-type from headers and uses Invoke-WebRequest's -ContentType" { - Mock Join-Hashtable -ModuleName JiraPS { + Mock Join-Hashtable -ModuleName $env:BHProjectName { $table = @{ } foreach ($item in $Hashtable) { foreach ($key in $item.Keys) { @@ -471,7 +498,7 @@ Describe "Invoke-JiraMethod" { $assertMockCalledSplat = @{ CommandName = "Invoke-WebRequest" - ModuleName = 'JiraPS' + ModuleName = $env:BHProjectName ParameterFilter = { $Uri -notlike "*contentType*" -and $Uri -notlike "*content-Type*" -and @@ -505,7 +532,7 @@ Describe "Invoke-JiraMethod" { } Context "Paged restuls" { - Mock Invoke-WebRequest -ModuleName JiraPS { + Mock Invoke-WebRequest -ModuleName $env:BHProjectName { ShowMockInfo 'Invoke-WebRequest' -Params 'Uri', 'Method', 'Body' $response = "" @@ -520,9 +547,11 @@ Describe "Invoke-JiraMethod" { } $InvokeWebRequestSplat = @{ - Uri = "https://postman-echo.com/post" - Method = "Post" - Body = $response + Uri = "https://postman-echo.com/post" + Method = "Post" + Body = $response + UseBasicParsing = $true + } $result = Microsoft.PowerShell.Utility\Invoke-WebRequest @InvokeWebRequestSplat @@ -530,7 +559,7 @@ Describe "Invoke-JiraMethod" { $result.RawContentStream | Add-Member -MemberType ScriptMethod -Name "ToArray" -Force -Value ([Scriptblock]::Create($scriptBlock)) $result } - Mock Join-Hashtable -ModuleName JiraPS { + Mock Join-Hashtable -ModuleName $env:BHProjectName { $table = @{ } foreach ($item in $Hashtable) { foreach ($key in $item.Keys) { @@ -539,10 +568,10 @@ Describe "Invoke-JiraMethod" { } $table } - Mock Convert-Result -ModuleName JiraPS { + Mock Convert-Result -ModuleName $env:BHProjectName { $InputObject } - Mock Expand-Result -ModuleName JiraPS { + Mock Expand-Result -ModuleName $env:BHProjectName { $InputObject.issues } @@ -559,7 +588,7 @@ Describe "Invoke-JiraMethod" { $assertMockCalledSplat = @{ CommandName = 'Invoke-WebRequest' - ModuleName = 'JiraPS' + ModuleName = $env:BHProjectName Exactly = $true Times = 2 Scope = 'It' @@ -578,7 +607,7 @@ Describe "Invoke-JiraMethod" { $assertMockCalledSplat = @{ CommandName = 'Expand-Result' - ModuleName = 'JiraPS' + ModuleName = $env:BHProjectName Exactly = $true Times = 3 Scope = 'It' @@ -600,7 +629,7 @@ Describe "Invoke-JiraMethod" { $assertMockCalledSplat = @{ CommandName = 'Invoke-WebRequest' - ModuleName = 'JiraPS' + ModuleName = $env:BHProjectName Exactly = $true Times = 1 Scope = 'It' @@ -622,7 +651,7 @@ Describe "Invoke-JiraMethod" { $assertMockCalledSplat = @{ CommandName = 'Invoke-WebRequest' - ModuleName = 'JiraPS' + ModuleName = $env:BHProjectName Exactly = $true Times = 2 Scope = 'It' @@ -644,7 +673,7 @@ Describe "Invoke-JiraMethod" { $assertMockCalledSplat = @{ CommandName = 'Invoke-WebRequest' - ModuleName = 'JiraPS' + ModuleName = $env:BHProjectName Exactly = $true Times = 1 Scope = 'It' diff --git a/Tests/New-JiraFilter.Tests.ps1 b/Tests/Functions/New-JiraFilter.Unit.Tests.ps1 similarity index 76% rename from Tests/New-JiraFilter.Tests.ps1 rename to Tests/Functions/New-JiraFilter.Unit.Tests.ps1 index d198f004..85ddf1a1 100644 --- a/Tests/New-JiraFilter.Tests.ps1 +++ b/Tests/Functions/New-JiraFilter.Unit.Tests.ps1 @@ -1,12 +1,41 @@ -Describe 'New-JiraFilter' { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe 'New-JiraFilter' -Tag 'Unit' { + BeforeAll { - Remove-Module JiraPS -ErrorAction SilentlyContinue - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" #region Definitions $jiraServer = "https://jira.example.com" diff --git a/Tests/New-JiraGroup.Tests.ps1 b/Tests/Functions/New-JiraGroup.Unit.Tests.ps1 similarity index 57% rename from Tests/New-JiraGroup.Tests.ps1 rename to Tests/Functions/New-JiraGroup.Unit.Tests.ps1 index b1cfa01d..13c408d4 100644 --- a/Tests/New-JiraGroup.Tests.ps1 +++ b/Tests/Functions/New-JiraGroup.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "New-JiraGroup" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "New-JiraGroup" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/New-JiraIssue.Tests.ps1 b/Tests/Functions/New-JiraIssue.Unit.Tests.ps1 similarity index 76% rename from Tests/New-JiraIssue.Tests.ps1 rename to Tests/Functions/New-JiraIssue.Unit.Tests.ps1 index 93acf18f..cef3aa84 100644 --- a/Tests/New-JiraIssue.Tests.ps1 +++ b/Tests/Functions/New-JiraIssue.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "New-JiraIssue" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "New-JiraIssue" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'https://jira.example.com' diff --git a/Tests/New-JiraSession.Tests.ps1 b/Tests/Functions/New-JiraSession.Unit.Tests.ps1 similarity index 68% rename from Tests/New-JiraSession.Tests.ps1 rename to Tests/Functions/New-JiraSession.Unit.Tests.ps1 index 3166f732..6915dbef 100644 --- a/Tests/New-JiraSession.Tests.ps1 +++ b/Tests/Functions/New-JiraSession.Unit.Tests.ps1 @@ -1,18 +1,47 @@ -Describe "New-JiraSession" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "New-JiraSession" -Tag 'Unit' { + BeforeAll { - Remove-Module JiraPS -ErrorAction SilentlyContinue - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* } AfterEach { try { (Get-Module JiraPS).PrivateData.Remove("Session") } - catch { $null = 0 } + catch { $null } } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" #region Definitions $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/New-JiraUser.Tests.ps1 b/Tests/Functions/New-JiraUser.Unit.Tests.ps1 similarity index 57% rename from Tests/New-JiraUser.Tests.ps1 rename to Tests/Functions/New-JiraUser.Unit.Tests.ps1 index 75a437d9..a974a0c5 100644 --- a/Tests/New-JiraUser.Tests.ps1 +++ b/Tests/Functions/New-JiraUser.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "New-JiraUser" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "New-JiraUser" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/New-JiraVersion.Tests.ps1 b/Tests/Functions/New-JiraVersion.Unit.Tests.ps1 similarity index 80% rename from Tests/New-JiraVersion.Tests.ps1 rename to Tests/Functions/New-JiraVersion.Unit.Tests.ps1 index 00610c4b..31472951 100644 --- a/Tests/New-JiraVersion.Tests.ps1 +++ b/Tests/Functions/New-JiraVersion.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "New-JiraVersion" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "New-JiraVersion" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' $versionName = '1.0.0.0' diff --git a/Tests/Remove-JiraFilter.Tests.ps1 b/Tests/Functions/Remove-JiraFilter.Unit.Tests.ps1 similarity index 82% rename from Tests/Remove-JiraFilter.Tests.ps1 rename to Tests/Functions/Remove-JiraFilter.Unit.Tests.ps1 index 71dc5ac2..0a72ce25 100644 --- a/Tests/Remove-JiraFilter.Tests.ps1 +++ b/Tests/Functions/Remove-JiraFilter.Unit.Tests.ps1 @@ -1,12 +1,41 @@ -Describe 'Remove-JiraFilter' { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe 'Remove-JiraFilter' -Tag 'Unit' { + BeforeAll { - Remove-Module JiraPS -ErrorAction SilentlyContinue - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" #region Definitions $jiraServer = "https://jira.example.com" diff --git a/Tests/Remove-JiraFilterPermission.Tests.ps1 b/Tests/Functions/Remove-JiraFilterPermission.Unit.Tests.ps1 similarity index 81% rename from Tests/Remove-JiraFilterPermission.Tests.ps1 rename to Tests/Functions/Remove-JiraFilterPermission.Unit.Tests.ps1 index 8d34ed47..39fe3fee 100644 --- a/Tests/Remove-JiraFilterPermission.Tests.ps1 +++ b/Tests/Functions/Remove-JiraFilterPermission.Unit.Tests.ps1 @@ -1,12 +1,41 @@ -Describe 'Remove-JiraFilterPermission' { - BeforeAll { - Remove-Module JiraPS -ErrorAction SilentlyContinue - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe 'Remove-JiraFilterPermission' -Tag 'Unit' { + +BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" #region Definitions $jiraServer = "https://jira.example.com" diff --git a/Tests/Remove-JiraGroup.Tests.ps1 b/Tests/Functions/Remove-JiraGroup.Unit.Tests.ps1 similarity index 65% rename from Tests/Remove-JiraGroup.Tests.ps1 rename to Tests/Functions/Remove-JiraGroup.Unit.Tests.ps1 index 7f63ef95..8d58948f 100644 --- a/Tests/Remove-JiraGroup.Tests.ps1 +++ b/Tests/Functions/Remove-JiraGroup.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Remove-JiraGroup" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Remove-JiraGroup" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Remove-JiraGroupMember.Tests.ps1 b/Tests/Functions/Remove-JiraGroupMember.Unit.Tests.ps1 similarity index 85% rename from Tests/Remove-JiraGroupMember.Tests.ps1 rename to Tests/Functions/Remove-JiraGroupMember.Unit.Tests.ps1 index 8d693cb2..dccb453a 100644 --- a/Tests/Remove-JiraGroupMember.Tests.ps1 +++ b/Tests/Functions/Remove-JiraGroupMember.Unit.Tests.ps1 @@ -1,12 +1,41 @@ -Describe "Remove-JiraGroupMember" { - BeforeAll { - Remove-Module JiraPS -ErrorAction SilentlyContinue - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "Remove-JiraGroupMember" -Tag 'Unit' { + +BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" #region Definitions $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Remove-JiraIssue.Tests.ps1 b/Tests/Functions/Remove-JiraIssue.Unit.Tests.ps1 similarity index 90% rename from Tests/Remove-JiraIssue.Tests.ps1 rename to Tests/Functions/Remove-JiraIssue.Unit.Tests.ps1 index b17143a3..f8bc4cc0 100644 --- a/Tests/Remove-JiraIssue.Tests.ps1 +++ b/Tests/Functions/Remove-JiraIssue.Unit.Tests.ps1 @@ -1,9 +1,41 @@ -Describe "Remove-JiraIssue" { - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "Remove-JiraIssue" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Remove-JiraIssueAttachment.Tests.ps1 b/Tests/Functions/Remove-JiraIssueAttachment.Unit.Tests.ps1 similarity index 86% rename from Tests/Remove-JiraIssueAttachment.Tests.ps1 rename to Tests/Functions/Remove-JiraIssueAttachment.Unit.Tests.ps1 index c1a13c4d..71a73bcb 100644 --- a/Tests/Remove-JiraIssueAttachment.Tests.ps1 +++ b/Tests/Functions/Remove-JiraIssueAttachment.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Remove-JiraIssueAttachment" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Remove-JiraIssueAttachment" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' $issueKey = "FOO-123" diff --git a/Tests/Remove-JiraIssueLink.Tests.ps1 b/Tests/Functions/Remove-JiraIssueLink.Unit.Tests.ps1 similarity index 69% rename from Tests/Remove-JiraIssueLink.Tests.ps1 rename to Tests/Functions/Remove-JiraIssueLink.Unit.Tests.ps1 index f5e3e0d4..09ff2da0 100644 --- a/Tests/Remove-JiraIssueLink.Tests.ps1 +++ b/Tests/Functions/Remove-JiraIssueLink.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Remove-JiraIssueLink" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Remove-JiraIssueLink" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Remove-JiraIssueWatcher.Tests.ps1 b/Tests/Functions/Remove-JiraIssueWatcher.Unit.Tests.ps1 similarity index 67% rename from Tests/Remove-JiraIssueWatcher.Tests.ps1 rename to Tests/Functions/Remove-JiraIssueWatcher.Unit.Tests.ps1 index 1afd4c97..ef522b06 100644 --- a/Tests/Remove-JiraIssueWatcher.Tests.ps1 +++ b/Tests/Functions/Remove-JiraIssueWatcher.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Remove-JiraIssueWatcher" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Remove-JiraIssueWatcher" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' $issueID = 41701 diff --git a/Tests/Remove-JiraRemoteLink.Tests.ps1 b/Tests/Functions/Remove-JiraRemoteLink.Unit.Tests.ps1 similarity index 72% rename from Tests/Remove-JiraRemoteLink.Tests.ps1 rename to Tests/Functions/Remove-JiraRemoteLink.Unit.Tests.ps1 index c13b30a7..1c6699d4 100644 --- a/Tests/Remove-JiraRemoteLink.Tests.ps1 +++ b/Tests/Functions/Remove-JiraRemoteLink.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Remove-JiraRemoteLink" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Remove-JiraRemoteLink" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Functions/Remove-JiraSession.Unit.Tests.ps1 b/Tests/Functions/Remove-JiraSession.Unit.Tests.ps1 new file mode 100644 index 00000000..61910d40 --- /dev/null +++ b/Tests/Functions/Remove-JiraSession.Unit.Tests.ps1 @@ -0,0 +1,60 @@ +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "Remove-JiraSession" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + . "$PSScriptRoot/../Shared.ps1" + + #region Mocks + Mock Get-JiraSession -ModuleName JiraPS { + (Get-Module JiraPS).PrivateData.Session + } + #endregion Mocks + + Context "Sanity checking" { + $command = Get-Command -Name Remove-JiraSession + + defParam $command 'Session' + } + + Context "Behavior testing" { + It "Closes a removes the JiraPS.Session data from module PrivateData" { + (Get-Module JiraPS).PrivateData = @{ Session = $true } + (Get-Module JiraPS).PrivateData.Session | Should -Not -BeNullOrEmpty + + Remove-JiraSession + + (Get-Module JiraPS).PrivateData.Session | Should -BeNullOrEmpty + } + } +} diff --git a/Tests/Remove-JiraUser.Tests.ps1 b/Tests/Functions/Remove-JiraUser.Unit.Tests.ps1 similarity index 65% rename from Tests/Remove-JiraUser.Tests.ps1 rename to Tests/Functions/Remove-JiraUser.Unit.Tests.ps1 index 0feb6780..c857b0e6 100644 --- a/Tests/Remove-JiraUser.Tests.ps1 +++ b/Tests/Functions/Remove-JiraUser.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Remove-JiraUser" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Remove-JiraUser" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Remove-JiraVersion.Tests.ps1 b/Tests/Functions/Remove-JiraVersion.Unit.Tests.ps1 similarity index 84% rename from Tests/Remove-JiraVersion.Tests.ps1 rename to Tests/Functions/Remove-JiraVersion.Unit.Tests.ps1 index 9a40ac37..8aacda3e 100644 --- a/Tests/Remove-JiraVersion.Tests.ps1 +++ b/Tests/Functions/Remove-JiraVersion.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Get-JiraVersion" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Get-JiraVersion" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' $versionName = '$versionName' diff --git a/Tests/Functions/Resolve-JiraError.Unit.Tests.ps1 b/Tests/Functions/Resolve-JiraError.Unit.Tests.ps1 new file mode 100644 index 00000000..19c8a726 --- /dev/null +++ b/Tests/Functions/Resolve-JiraError.Unit.Tests.ps1 @@ -0,0 +1,71 @@ +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "Resolve-JiraError" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + InModuleScope JiraPS { + + . "$PSScriptRoot/../Shared.ps1" + + $testErrorKey = 'error' + $testError = 'This is an error message.' + + $testJson = @" +{ + "errorMessages": [], + "errors": + { + "$testErrorKey":"$testError" + } +} +"@ + $testErrorMessage = "Jira encountered an error: [$testErrorKey] - $testError" + + It "Converts a JIRA result into a PSObject with error results" { + $obj = Resolve-JiraError -InputObject (ConvertFrom-Json $testJson) + $obj | Should Not BeNullOrEmpty + $obj.Key | Should Be $testErrorKey + $obj.Message | Should Be $testError + } + + It "Writes output to the Error stream if the -WriteError parameter is passed" { + $obj = Resolve-JiraError -InputObject (ConvertFrom-Json $testJson) -WriteError -ErrorAction SilentlyContinue -ErrorVariable errOutput + $errOutput | Should Be $testErrorMessage + } + + It "Does not write a PSObject if the -WriteError parameter is passed" { + $obj = Resolve-JiraError -InputObject (ConvertFrom-Json $testJson) -WriteError -ErrorAction SilentlyContinue -ErrorVariable errOutput + $obj | Should BeNullOrEmpty + } + } +} diff --git a/Tests/Functions/Set-JiraConfigServer.Unit.Tests.ps1 b/Tests/Functions/Set-JiraConfigServer.Unit.Tests.ps1 new file mode 100644 index 00000000..f6f08ff9 --- /dev/null +++ b/Tests/Functions/Set-JiraConfigServer.Unit.Tests.ps1 @@ -0,0 +1,75 @@ +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe "Set-JiraConfigServer" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + InModuleScope JiraPS { + + . "$PSScriptRoot/../Shared.ps1" + + $jiraServer = 'http://jiraserver.example.com' + + $configFile = Join-Path -Path $TestDrive -ChildPath 'config.xml' + Set-JiraConfigServer -Server $jiraServer -ConfigFile $configFile + + It "Ensures that a config.xml file exists" { + $configFile | Should Exist + } + + $xml = New-Object -TypeName Xml + $xml.Load($configFile) + $xmlServer = $xml.Config.Server + + It "Ensures that the XML file has a Config.Server element" { + $xmlServer | Should Not BeNullOrEmpty + } + + It "Sets the config file's Server value " { + $xmlServer | Should Be $jiraServer + } + + It "Trims whitespace from the provided Server parameter" { + Set-JiraConfigServer -Server "$jiraServer " -ConfigFile $configFile + $xml = New-Object -TypeName Xml + $xml.Load($configFile) + $xml.Config.Server | Should Be $jiraServer + } + + It "Trims trailing slasher from the provided Server parameter" { + Set-JiraConfigServer -Server "$jiraServer/" -ConfigFile $configFile + $xml = New-Object -TypeName Xml + $xml.Load($configFile) + $xml.Config.Server | Should Be $jiraServer + } + } +} diff --git a/Tests/Set-JiraFilter.Tests.ps1 b/Tests/Functions/Set-JiraFilter.Unit.Tests.ps1 similarity index 89% rename from Tests/Set-JiraFilter.Tests.ps1 rename to Tests/Functions/Set-JiraFilter.Unit.Tests.ps1 index 7f550f76..e0230ce3 100644 --- a/Tests/Set-JiraFilter.Tests.ps1 +++ b/Tests/Functions/Set-JiraFilter.Unit.Tests.ps1 @@ -1,12 +1,41 @@ -Describe 'Set-JiraFilter' { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } + +Describe 'Set-JiraFilter' -Tag 'Unit' { + BeforeAll { - Remove-Module JiraPS -ErrorAction SilentlyContinue - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" #region Definitions $jiraServer = "https://jira.example.com" diff --git a/Tests/Set-JiraIssue.Tests.ps1 b/Tests/Functions/Set-JiraIssue.Unit.Tests.ps1 similarity index 87% rename from Tests/Set-JiraIssue.Tests.ps1 rename to Tests/Functions/Set-JiraIssue.Unit.Tests.ps1 index 96d6237a..249faafd 100644 --- a/Tests/Set-JiraIssue.Tests.ps1 +++ b/Tests/Functions/Set-JiraIssue.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Set-JiraIssue" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Set-JiraIssue" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = "https://jira.example.com" diff --git a/Tests/Set-JiraIssueLabel.Tests.ps1 b/Tests/Functions/Set-JiraIssueLabel.Unit.Tests.ps1 similarity index 79% rename from Tests/Set-JiraIssueLabel.Tests.ps1 rename to Tests/Functions/Set-JiraIssueLabel.Unit.Tests.ps1 index 4aba98c6..10b0620c 100644 --- a/Tests/Set-JiraIssueLabel.Tests.ps1 +++ b/Tests/Functions/Set-JiraIssueLabel.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Set-JiraIssueLabel" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } -Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Set-JiraIssueLabel" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'https://jira.example.com' diff --git a/Tests/Set-JiraUser.Tests.ps1 b/Tests/Functions/Set-JiraUser.Unit.Tests.ps1 similarity index 72% rename from Tests/Set-JiraUser.Tests.ps1 rename to Tests/Functions/Set-JiraUser.Unit.Tests.ps1 index 9e2e6023..8db76538 100644 --- a/Tests/Set-JiraUser.Tests.ps1 +++ b/Tests/Functions/Set-JiraUser.Unit.Tests.ps1 @@ -1,10 +1,41 @@ -Describe "Set-JiraUser" { +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop +Describe "Set-JiraUser" -Tag 'Unit' { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' diff --git a/Tests/Set-JiraVersion.Tests.ps1 b/Tests/Functions/Set-JiraVersion.Unit.Tests.ps1 similarity index 76% rename from Tests/Set-JiraVersion.Tests.ps1 rename to Tests/Functions/Set-JiraVersion.Unit.Tests.ps1 index acaee411..77ba26f4 100644 --- a/Tests/Set-JiraVersion.Tests.ps1 +++ b/Tests/Functions/Set-JiraVersion.Unit.Tests.ps1 @@ -1,12 +1,41 @@ -#Requires -Modules Pester +#requires -modules BuildHelpers +#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.4.0" } -Describe "Set-JiraVersion" { +Describe "Set-JiraVersion" -Tag 'Unit' { - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/../..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } InModuleScope JiraPS { - . "$PSScriptRoot/Shared.ps1" + . "$PSScriptRoot/../Shared.ps1" $jiraServer = 'http://jiraserver.example.com' $versionName = '1.0.0.0' diff --git a/Tests/Get-JiraConfigServer.Tests.ps1 b/Tests/Get-JiraConfigServer.Tests.ps1 deleted file mode 100644 index a67e5e12..00000000 --- a/Tests/Get-JiraConfigServer.Tests.ps1 +++ /dev/null @@ -1,23 +0,0 @@ -Describe "Get-JiraConfigServer" { - - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop - - InModuleScope JiraPS { - - . "$PSScriptRoot/Shared.ps1" - - $jiraServer = 'http://jiraserver.example.com' - - $configFile = Join-Path -Path $TestDrive -ChildPath 'config.xml' - - It "Throws an exception if the config file does not exist" { - { Get-JiraConfigServer -ConfigFile $configFile } | Should Throw - } - - It "Returns the defined Server in the config.xml file" { - Set-JiraConfigServer -Server $jiraServer -ConfigFile $configFile - $s = Get-JiraConfigServer -ConfigFile $configFile - $s | Should Be $jiraServer - } - } -} diff --git a/Tests/Get-JiraSession.Tests.ps1 b/Tests/Get-JiraSession.Tests.ps1 deleted file mode 100644 index 01094e67..00000000 --- a/Tests/Get-JiraSession.Tests.ps1 +++ /dev/null @@ -1,16 +0,0 @@ -Describe "Get-JiraSession" { - - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop - - InModuleScope JiraPS { - - . "$PSScriptRoot/Shared.ps1" - - It "Obtains a saved JiraPS.Session object from module PrivateData" { - # I don't know how to test this, since I can't access module PrivateData from Pester. - # The tests for New-JiraSession use this function to validate that they work, so if - # those tests pass, this function should be working as well. - $true | Should Be $true - } - } -} diff --git a/Tests/JiraPS.Help.Tests.ps1 b/Tests/Help.Tests.ps1 similarity index 63% rename from Tests/JiraPS.Help.Tests.ps1 rename to Tests/Help.Tests.ps1 index 449b9d3c..fc8af971 100644 --- a/Tests/JiraPS.Help.Tests.ps1 +++ b/Tests/Help.Tests.ps1 @@ -4,23 +4,26 @@ Describe "Help tests" -Tag Documentation { BeforeAll { - Import-Module BuildHelpers Remove-Item -Path Env:\BH* - $projectRoot = (Resolve-Path "$PSScriptRoot/..").Path if ($projectRoot -like "*Release") { $projectRoot = (Resolve-Path "$projectRoot/..").Path } + + Import-Module BuildHelpers Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + $env:BHManifestToTest = $env:BHPSModuleManifest - $isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" - if ($isBuild) { + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { $Pattern = [regex]::Escape($env:BHProjectPath) $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput $env:BHManifestToTest = $env:BHBuildModuleManifest } + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue Import-Module $env:BHManifestToTest } @@ -48,8 +51,8 @@ Describe "Help tests" -Tag Documentation { $module = Get-Module $env:BHProjectName $commands = Get-Command -Module $module -CommandType Cmdlet, Function, Workflow # Not alias - $classes = Get-ChildItem "$env:BHProjectPath/docs/en-US/classes/*" -ErrorAction SilentlyContinue - $enums = Get-ChildItem "$env:BHProjectPath/docs/en-US/enumerations/*" -ErrorAction SilentlyContinue + # $classes = Get-ChildItem "$env:BHProjectPath/docs/en-US/classes/*" + # $enums = Get-ChildItem "$env:BHProjectPath/docs/en-US/enumerations/*" #region Public Functions foreach ($command in $commands) { @@ -61,18 +64,11 @@ Describe "Help tests" -Tag Documentation { Context "Function $commandName's Help" { - #region PlatyPS external Help It "is described in a markdown file" { $markdownFile | Should -Not -BeNullOrEmpty Test-Path $markdownFile | Should -Be $true } - It "links the function to the external help" { - # required for PowerShell v3 - $Pattern = [regex]::Escape("# .ExternalHelp ..\JiraPS-help.xml") - $command.Definition -match $Pattern - } - It "does not have Comment-Based Help" { # We use .EXAMPLE, as we test this extensivly and it is never auto-generated $command.Definition | Should -Not -BeNullOrEmpty @@ -107,21 +103,23 @@ Describe "Help tests" -Tag Documentation { $markdownFile | Should -FileContentMatchExactly "layout: documentation" $markdownFile | Should -FileContentMatch "permalink: /docs/$env:BHProjectName/commands/$commandName/" } - #endregion PlatyPS external Help - #region Help Content + # Should be a synopsis for every function It "has a synopsis" { $help.Synopsis | Should -Not -BeNullOrEmpty } + # Should be a description for every function It "has a description" { $help.Description.Text -join '' | Should -Not -BeNullOrEmpty } + # Should be at least one example It "has examples" { ($help.Examples.Example | Select-Object -First 1).Code | Should -Not -BeNullOrEmpty } + # Should be at least one example description It "has desciptions for all examples" { foreach ($example in ($help.Examples.Example)) { $example.remarks.Text | Should -Not -BeNullOrEmpty @@ -131,9 +129,7 @@ Describe "Help tests" -Tag Documentation { It "has at least as many examples as ParameterSets" { ($help.Examples.Example | Measure-Object).Count | Should -BeGreaterOrEqual $command.ParameterSets.Count } - #endregion Help Content - #region Consistency with Code # It "does not define parameter position for functions with only one ParameterSet" { # if ($command.ParameterSets.Count -eq 1) { # $command.Parameters.Keys | Foreach-Object { @@ -142,11 +138,6 @@ Describe "Help tests" -Tag Documentation { # } # } - It "has all ParameterSets in the Help" { - # @($command.ParameterSets).Count | Should -Be @($help.Syntax.SyntaxItem).Count - } - - #region Parameters foreach ($parameterName in $command.Parameters.Keys) { $parameterCode = $command.Parameters[$parameterName] @@ -164,7 +155,7 @@ Describe "Help tests" -Tag Documentation { $parameterHelp.Required | Should -BeLike $isMandatory.ToString() } - It "matches the type of the parameter [-$parameterName] in code and help of $commandName" { + It "matches the type of the parameter in code and help" { $codeType = $parameterCode.ParameterType.Name if ($codeType -eq "Object") { if (($parameterCode.Attributes) -and ($parameterCode.Attributes | Get-Member -Name PSTypeName)) { @@ -179,88 +170,83 @@ Describe "Help tests" -Tag Documentation { } } } + } - It "does not have parameters that are not in the code" { - $parameter = @() - if ($help.Parameters | Get-Member -Name Parameter) { - $parameter = $help.Parameters.Parameter.Name | Sort-Object -Unique - } - foreach ($helpParm in $parameter) { - $command.Parameters.Keys | Should -Contain $helpParm - } + It "does not have parameters that are not in the code" { + $parameter = @() + if ($help.Parameters | Get-Member -Name Parameter) { + $parameter = $help.Parameters.Parameter.Name | Sort-Object -Unique + } + foreach ($helpParm in $parameter) { + $command.Parameters.Keys | Should -Contain $helpParm } } - #endregion Parameters - #endregion Consistency with Code } } #endregion Public Functions #region Classes - if ($classes) { - foreach ($class in $classes) { - Context "Classes $($class.BaseName) Help" { + <# foreach ($class in $classes) { + Context "Classes $($class.BaseName) Help" { - It "is described in a markdown file" { - $class.FullName | Should -Not -BeNullOrEmpty - Test-Path $class.FullName | Should -Be $true - } + It "is described in a markdown file" { + $class.FullName | Should -Not -BeNullOrEmpty + Test-Path $class.FullName | Should -Be $true + } - It "has no platyPS template artifacts" { - $class.FullName | Should -Not -BeNullOrEmpty - $class.FullName | Should -Not -FileContentMatch '{{.*}}' - } + It "has no platyPS template artifacts" { + $class.FullName | Should -Not -BeNullOrEmpty + $class.FullName | Should -Not -FileContentMatch '{{.*}}' + } - It "defines the frontmatter for the homepage" { - $class.FullName | Should -Not -BeNullOrEmpty - $class.FullName | Should -FileContentMatch "Module Name: $env:BHProjectName" - $class.FullName | Should -FileContentMatchExactly "layout: documentation" - $class.FullName | Should -FileContentMatch "permalink: /docs/$env:BHProjectName/classes/$commandName/" - } + It "defines the frontmatter for the homepage" { + $class.FullName | Should -Not -BeNullOrEmpty + $class.FullName | Should -FileContentMatch "Module Name: $env:BHProjectName" + $class.FullName | Should -FileContentMatchExactly "layout: documentation" + $class.FullName | Should -FileContentMatch "permalink: /docs/$env:BHProjectName/classes/$($class.BaseName)/" } } + } - Context "Missing classes" { - It "has a documentation file for every class" { - foreach ($class in ([AtlassianPS.ServerData].Assembly.GetTypes() | Where-Object IsClass)) { - $classes.BaseName | Should -Contain $class.FullName - } + + Context "Missing classes" { + It "has a documentation file for every class" { + foreach ($class in ([AtlassianPS.ServerData].Assembly.GetTypes() | Where-Object IsClass)) { + $classes.BaseName | Should -Contain $class.FullName } } - } + } #> #endregion Classes #region Enumerations - if ($enums) { - foreach ($enum in $enums) { - Context "Enumeration $($enum.BaseName) Help" { + <# foreach ($enum in $enums) { + Context "Enumeration $($enum.BaseName) Help" { - It "is described in a markdown file" { - $enum.FullName | Should -Not -BeNullOrEmpty - Test-Path $enum.FullName | Should -Be $true - } + It "is described in a markdown file" { + $enum.FullName | Should -Not -BeNullOrEmpty + Test-Path $enum.FullName | Should -Be $true + } - It "has no platyPS template artifacts" { - $enum.FullName | Should -Not -BeNullOrEmpty - $enum.FullName | Should -Not -FileContentMatch '{{.*}}' - } + It "has no platyPS template artifacts" { + $enum.FullName | Should -Not -BeNullOrEmpty + $enum.FullName | Should -Not -FileContentMatch '{{.*}}' + } - It "defines the frontmatter for the homepage" { - $enum.FullName | Should -Not -BeNullOrEmpty - $enum.FullName | Should -FileContentMatch "Module Name: $env:BHProjectName" - $enum.FullName | Should -FileContentMatchExactly "layout: documentation" - $enum.FullName | Should -FileContentMatch "permalink: /docs/$env:BHProjectName/enumerations/$commandName/" - } + It "defines the frontmatter for the homepage" { + $enum.FullName | Should -Not -BeNullOrEmpty + $enum.FullName | Should -FileContentMatch "Module Name: $env:BHProjectName" + $enum.FullName | Should -FileContentMatchExactly "layout: documentation" + $enum.FullName | Should -FileContentMatch "permalink: /docs/$env:BHProjectName/enumerations/$($enum.BaseName)/" } } + } - Context "Missing classes" { - It "has a documentation file for every class" { - foreach ($enum in ([AtlassianPS.ServerData].Assembly.GetTypes() | Where-Object IsEnum)) { - $enums.BaseName | Should -Contain $enum.FullName - } + Context "Missing enumerations" { + It "has a documentation file for every enumeration" { + foreach ($enum in ([AtlassianPS.ServerData].Assembly.GetTypes() | Where-Object IsEnum)) { + $enums.BaseName | Should -Contain $enum.FullName } } - } + } #> #endregion Enumerations } diff --git a/Tests/JiraPS.Integration.Tests.ps1 b/Tests/JiraPS.Integration.Tests.old.ps1 similarity index 98% rename from Tests/JiraPS.Integration.Tests.ps1 rename to Tests/JiraPS.Integration.Tests.old.ps1 index 0a9fafd1..120b3634 100644 --- a/Tests/JiraPS.Integration.Tests.ps1 +++ b/Tests/JiraPS.Integration.Tests.old.ps1 @@ -1,4 +1,4 @@ -Describe 'Load Module' { +Describe 'Load Module' -Tag 'Integration' { # ARRANGE Remove-Module JiraPS -Force -ErrorAction SilentlyContinue @@ -14,7 +14,7 @@ Describe 'Load Module' { InModuleScope JiraPS { . "$PSScriptRoot/Shared.ps1" - Describe 'Authenticating' { + Describe 'Authenticating' -Tag 'Integration' { # ARRANGE $Pass = ConvertTo-SecureString -AsPlainText -Force -String $env:JiraPass @@ -60,7 +60,7 @@ InModuleScope JiraPS { } - Describe 'Handling of Versions' { + Describe 'Handling of Versions' -Tag 'Integration' { $projectKey = "TV" $versionName1 = "TESTv1" @@ -201,7 +201,7 @@ InModuleScope JiraPS { } } - <# Describe 'Handling of Users and Groups' { + <# Describe 'Handling of Users and Groups' -Tag 'Integration' { Context 'New-JiraGroup' { # ARRANGE diff --git a/Tests/JiraPS.Tests.ps1 b/Tests/JiraPS.Tests.ps1 index 3512d171..5dd7b960 100644 --- a/Tests/JiraPS.Tests.ps1 +++ b/Tests/JiraPS.Tests.ps1 @@ -1,209 +1,80 @@ -#Requires -Modules PSScriptAnalyzer +#requires -modules BuildHelpers +#requires -modules Pester -Describe "JiraPS" { +Describe "General project validation" -Tag Unit { - Import-Module "$PSScriptRoot/../JiraPS/JiraPS.psd1" -Force -ErrorAction Stop - - InModuleScope JiraPS { + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } - . "$PSScriptRoot/Shared.ps1" + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue - $projectRoot = "$PSScriptRoot/.." - $moduleRoot = "$projectRoot/JiraPS" + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) - $manifestFile = "$moduleRoot/JiraPS.psd1" - $changelogFile = if (Test-Path "$moduleRoot/CHANGELOG.md") { - "$moduleRoot/CHANGELOG.md" - } - elseif (Test-Path "$projectRoot/CHANGELOG.md") { - "$projectRoot/CHANGELOG.md" - } - $appveyorFile = if (Test-Path "$projectRoot/appveyor.yml") { - "$projectRoot/appveyor.yml" - } - elseif (Test-Path "$projectRoot/../appveyor.yml") { - "$projectRoot/../appveyor.yml" + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest } - Context "All required tests are present" { - # We want to make sure that every .ps1 file in the Functions directory that isn't a Pester test has an associated Pester test. - # This helps keep me honest and makes sure I'm testing my code appropriately. - - $publicFunctions = @( - (Get-Module JiraPS).ExportedCmdlets.Keys - (Get-Module JiraPS).ExportedFunctions.Keys - ) - - It "Includes a test for each PowerShell function in the module" { - foreach ($function in $publicFunctions) { - $expectedTestFile = Join-Path $PSScriptRoot "$function.Tests.ps1" - $expectedTestFile | Should Exist - } - } - It "Includes a test for each PowerShell private function in the module" { - $privateFunctionMissingTests = @() - $functions = Get-Command -Module JiraPS | Where-Object {$_.name -notin $publicFunctions} - foreach ($function in $functions.Name) { - $expectedTestFile = Join-Path $PSScriptRoot "$function.Tests.ps1" - if (-not (Test-Path $expectedTestFile)) { - $privateFunctionMissingTests += $function - } - } - if ($privateFunctionMissingTests) { - Write-Warning ("It is recommended to have tests for the following private function:`n`t{0}" -f ($privateFunctionMissingTests -join "`n`t")) - } - } - } + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" - Context "Manifest, changelog, and AppVeyor" { - - # These tests are...erm, borrowed...from the module tests from the Pester module. - # I think they are excellent for sanity checking, and all credit for the following - # tests goes to Dave Wyatt, the genius behind Pester. I've just adapted them - # slightly to match JiraPS. - - $manifest = $null - - foreach ($line in (Get-Content $changelogFile)) { - if ($line -match "(?:##|\)\s*(?(\d+\.?){1,2})") { - $changelogVersion = $matches.Version - break - } - } - - foreach ($line in (Get-Content $appveyorFile)) { - # (?()) - non-capturing group, but named Version. This makes it - # easy to reference the inside group later. - - if ($line -match '^\D*(?(\d+\.){1,3}\d+).\{build\}') { - $appveyorVersion = $matches.Version - break - } - } - - It "Includes a valid manifest file" { - { - $manifest = Test-ModuleManifest -Path $manifestFile -ErrorAction Stop -WarningAction SilentlyContinue - } | Should Not Throw - } - - # There is a bug that prevents Test-ModuleManifest from updating correctly when the manifest file changes. See here: - # https://connect.microsoft.com/PowerShell/feedback/details/1541659/test-modulemanifest-the-psmoduleinfo-is-not-updated - - # As a temp workaround, we'll just read the manifest as a raw hashtable. - # Credit to this workaround comes from here: - # https://psescape.azurewebsites.net/pester-testing-your-module-manifest/ - $script:manifest = Invoke-Expression (Get-Content $manifestFile -Raw) - - It "Manifest file includes the correct root module" { - $script:manifest.RootModule | Should Be 'JiraPS.psm1' - } - - It "Manifest file includes the correct guid" { - $script:manifest.Guid | Should Be '4bf3eb15-037e-43b7-9e47-20a30436324f' - } - - It "Manifest file includes a valid version" { - # $script:manifest.Version -as [Version] | Should Not BeNullOrEmpty - $script:manifest.ModuleVersion -as [Version] | Should Not BeNullOrEmpty - } - - It "Includes a changelog file" { - $changelogFile | Should Exist - } - - # $changelogVersion = $null - It "Changelog includes a valid version number" { - $changelogVersion | Should Not BeNullOrEmpty - $changelogVersion -as [Version] | Should Not BeNullOrEmpty - } - - It "Changelog version matches manifest version" { - $manifest -like "$($changelogVersion.ModuleVersion)*" | Should Be $true - } - - # Back to me! Pester doesn't use AppVeyor, as far as I know, and I do. - - It "Includes an appveyor.yml file" { - $appveyorFile | Should Exist - } - - It "Appveyor.yml file includes the module version" { - $appveyorVersion | Should Not BeNullOrEmpty - $appveyorVersion -as [Version] | Should Not BeNullOrEmpty - } - - It "Appveyor version matches manifest version" { - $manifest -like "$($appveyorVersion.ModuleVersion)*" | Should Be $true - } - } + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + # Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } - Context "Style checking" { - - # This section is again from the mastermind, Dave Wyatt. Again, credit - # goes to him for these tests. - - $files = @( - Get-ChildItem $here -Include *.ps1, *.psm1 -Recurse - ) - - It 'Source files contain no trailing whitespace' { - $badLines = @( - foreach ($file in $files) { - $lines = [System.IO.File]::ReadAllLines($file.FullName) - $lineCount = $lines.Count - - for ($i = 0; $i -lt $lineCount; $i++) { - if ($lines[$i] -match '\s+$') { - 'File: {0}, Line: {1}' -f $file.FullName, ($i + 1) - } - } - } - ) - - if ($badLines.Count -gt 0) { - throw "The following $($badLines.Count) lines contain trailing whitespace: `r`n`r`n$($badLines -join "`r`n")" - } - } - - It 'Source files all end with a newline' { - $badFiles = @( - foreach ($file in $files) { - $string = [System.IO.File]::ReadAllText($file.FullName) - if ($string.Length -gt 0 -and $string[-1] -ne "`n") { - $file.FullName - } - } - ) - - if ($badFiles.Count -gt 0) { - throw "The following files do not end with a newline: `r`n`r`n$($badFiles -join "`r`n")" - } - } - } + It "passes Test-ModuleManifest" { + { Test-ModuleManifest -Path $env:BHManifestToTest -ErrorAction Stop } | Should -Not -Throw + } - Context 'PSScriptAnalyzer Rules' { - if ($PSVersionTable.PSVersion.Major -gt 3) { - Import-Module $manifestFile -Force -ErrorAction Stop - - $invokeScriptAnalyzerSplat = @{ - Path = "$moduleRoot" - Settings = "$projectRoot/PSScriptAnalyzerSettings.psd1" - Recurse = $true - ErrorAction = 'SilentlyContinue' - } - $analysis = Invoke-ScriptAnalyzer @invokeScriptAnalyzerSplat - $scriptAnalyzerRules = Get-ScriptAnalyzerRule - - forEach ($rule in $scriptAnalyzerRules) { - It "Should pass $rule" { - if (($analysis) -and ($analysis.RuleName -contains $rule)) { - $analysis | Where-Object RuleName -eq $rule -OutVariable failures | Out-Default - $failures.Count | Should Be 0 - } - } - } - } - } + It "module '$env:BHProjectName' can import cleanly" { + { Import-Module $env:BHManifestToTest } | Should Not Throw } + + It "module '$env:BHProjectName' exports functions" { + Import-Module $env:BHManifestToTest + + (Get-Command -Module $env:BHProjectName | Measure-Object).Count | Should -BeGreaterThan 0 + } + + It "module uses the correct root module" { + Get-Metadata -Path $env:BHManifestToTest -PropertyName RootModule | Should -Be 'JiraPS.psm1' + } + + It "module uses the correct guid" { + Get-Metadata -Path $env:BHManifestToTest -PropertyName Guid | Should -Be '4bf3eb15-037e-43b7-9e47-20a30436324f' + } + + It "module uses a valid version" { + [Version](Get-Metadata -Path $env:BHManifestToTest -PropertyName ModuleVersion) | Should -Not -BeNullOrEmpty + [Version](Get-Metadata -Path $env:BHManifestToTest -PropertyName ModuleVersion) | Should -BeOfType [Version] + } + + # It "module is imported with default prefix" { + # $prefix = Get-Metadata -Path $env:BHManifestToTest -PropertyName DefaultCommandPrefix + + # Import-Module $env:BHManifestToTest -Force -ErrorAction Stop + # (Get-Command -Module $env:BHProjectName).Name | ForEach-Object { + # $_ | Should -Match "\-$prefix" + # } + # } + + # It "module is imported with custom prefix" { + # $prefix = "Wiki" + + # Import-Module $env:BHManifestToTest -Prefix $prefix -Force -ErrorAction Stop + # (Get-Command -Module $env:BHProjectName).Name | ForEach-Object { + # $_ | Should -Match "\-$prefix" + # } + # } } diff --git a/Tests/PSScriptAnalyzer.Tests.ps1 b/Tests/PSScriptAnalyzer.Tests.ps1 new file mode 100644 index 00000000..b346ecf6 --- /dev/null +++ b/Tests/PSScriptAnalyzer.Tests.ps1 @@ -0,0 +1,87 @@ +#requires -modules BuildHelpers +#requires -modules Pester +#requires -modules PSScriptAnalyzer + +Describe "PSScriptAnalyzer Tests" -Tag Unit { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + # Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + $settingsPath = if ($script:isBuild) { + "$env:BHBuildOutput/PSScriptAnalyzerSettings.psd1" + } + else { + "$env:BHProjectPath/PSScriptAnalyzerSettings.psd1" + } + + $Params = @{ + Path = $env:BHModulePath + Settings = $settingsPath + Severity = @('Error', 'Warning') + Recurse = $true + Verbose = $false + ErrorVariable = 'ErrorVariable' + ErrorAction = 'SilentlyContinue' + } + $ScriptWarnings = Invoke-ScriptAnalyzer @Params + $scripts = Get-ChildItem $env:BHModulePath -Include *.ps1, *.psm1 -Recurse + + foreach ($Script in $scripts) { + $RelPath = $Script.FullName.Replace($env:BHProjectPath, '') -replace '^\\', '' + + Context "$RelPath" { + + $Rules = $ScriptWarnings | + Where-Object {$_.ScriptPath -like $Script.FullName} | + Select-Object -ExpandProperty RuleName -Unique + + foreach ($rule in $Rules) { + It "passes $rule" { + $BadLines = $ScriptWarnings | + Where-Object {$_.ScriptPath -like $Script.FullName -and $_.RuleName -like $rule} | + Select-Object -ExpandProperty Line + $BadLines | Should -Be $null + } + } + + $Exceptions = $null + if ($ErrorVariable) { + $Exceptions = $ErrorVariable.Exception.Message | + Where-Object {$_ -match [regex]::Escape($Script.FullName)} + } + + It "has no parse errors" { + foreach ($Exception in $Exceptions) { + $Exception | Should -BeNullOrEmpty + } + } + } + } +} diff --git a/Tests/Project.Tests.ps1 b/Tests/Project.Tests.ps1 new file mode 100644 index 00000000..4217fa92 --- /dev/null +++ b/Tests/Project.Tests.ps1 @@ -0,0 +1,112 @@ +#requires -modules BuildHelpers +#requires -modules Pester + +Describe "General project validation" -Tag Unit { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + $module = Get-Module $env:BHProjectName + $testFiles = Get-ChildItem $PSScriptRoot -Include "*.Tests.ps1" -Recurse + + Context "Public functions" { + $publicFunctions = (Get-ChildItem "$env:BHModulePath/Public/*.ps1").BaseName + + foreach ($function in $publicFunctions) { + + # TODO + It "has a test file for $function" { + $expectedTestFile = "$function.Unit.Tests.ps1" + + $testFiles.Name | Should -Contain $expectedTestFile + } + + It "exports $function" { + $expectedFunctionName = $function -replace "\-", "-$($module.Prefix)" + + $module.ExportedCommands.keys | Should -Contain $expectedFunctionName + } + } + } + + Context "Private functions" { + $privateFunctions = (Get-ChildItem "$env:BHModulePath/Private/*.ps1").BaseName + + foreach ($function in $privateFunctions) { + + # TODO + # It "has a test file for $function" { + # $expectedTestFile = "$function.Unit.Tests.ps1" + + # $testFiles.Name | Should -Contain $expectedTestFile + # } + + It "does not export $function" { + $expectedFunctionName = $function -replace "\-", "-$($module.Prefix)" + + $module.ExportedCommands.keys | Should -Not -Contain $expectedFunctionName + } + } + } + + <# + Context "Classes" { + + foreach ($class in ([AtlassianPS.ServerData].Assembly.GetTypes() | Where-Object IsClass)) { + It "has a test file for $class" { + $expectedTestFile = "$class.Unit.Tests.ps1" + $testFiles.Name | Should -Contain $expectedTestFile + } + } + } + + Context "Enumeration" { + + foreach ($enum in ([AtlassianPS.ServerData].Assembly.GetTypes() | Where-Object IsEnum)) { + It "has a test file for $enum" { + $expectedTestFile = "$enum.Unit.Tests.ps1" + $testFiles.Name | Should -Contain $expectedTestFile + } + } + } +#> + + Context "Project stucture" { + $publicFunctions = (Get-Module -Name $env:BHProjectName).ExportedFunctions.Keys + + It "has all the public functions as a file in '$env:BHProjectName/Public'" { + foreach ($function in $publicFunctions) { + # $function = $function.Replace((Get-Module -Name $env:BHProjectName).Prefix, '') + + (Get-ChildItem "$env:BHModulePath/Public").BaseName | Should -Contain $function + } + } + } +} diff --git a/Tests/Remove-JiraSession.Tests.ps1 b/Tests/Remove-JiraSession.Tests.ps1 deleted file mode 100644 index a194ecb9..00000000 --- a/Tests/Remove-JiraSession.Tests.ps1 +++ /dev/null @@ -1,31 +0,0 @@ -Describe "Remove-JiraSession" { - BeforeAll { - Remove-Module JiraPS -ErrorAction SilentlyContinue - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop - } - - . "$PSScriptRoot/Shared.ps1" - - #region Mocks - Mock Get-JiraSession -ModuleName JiraPS { - (Get-Module JiraPS).PrivateData.Session - } - #endregion Mocks - - Context "Sanity checking" { - $command = Get-Command -Name Remove-JiraSession - - defParam $command 'Session' - } - - Context "Behavior testing" { - It "Closes a removes the JiraPS.Session data from module PrivateData" { - (Get-Module JiraPS).PrivateData = @{ Session = $true } - (Get-Module JiraPS).PrivateData.Session | Should -Not -BeNullOrEmpty - - Remove-JiraSession - - (Get-Module JiraPS).PrivateData.Session | Should -BeNullOrEmpty - } - } -} diff --git a/Tests/Resolve-JiraError.Tests.ps1 b/Tests/Resolve-JiraError.Tests.ps1 deleted file mode 100644 index 938a319b..00000000 --- a/Tests/Resolve-JiraError.Tests.ps1 +++ /dev/null @@ -1,40 +0,0 @@ -Describe "Resolve-JiraError" { - - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop - - InModuleScope JiraPS { - - . "$PSScriptRoot/Shared.ps1" - - $testErrorKey = 'error' - $testError = 'This is an error message.' - - $testJson = @" -{ - "errorMessages": [], - "errors": - { - "$testErrorKey":"$testError" - } -} -"@ - $testErrorMessage = "Jira encountered an error: [$testErrorKey] - $testError" - - It "Converts a JIRA result into a PSObject with error results" { - $obj = Resolve-JiraError -InputObject (ConvertFrom-Json $testJson) - $obj | Should Not BeNullOrEmpty - $obj.Key | Should Be $testErrorKey - $obj.Message | Should Be $testError - } - - It "Writes output to the Error stream if the -WriteError parameter is passed" { - $obj = Resolve-JiraError -InputObject (ConvertFrom-Json $testJson) -WriteError -ErrorAction SilentlyContinue -ErrorVariable errOutput - $errOutput | Should Be $testErrorMessage - } - - It "Does not write a PSObject if the -WriteError parameter is passed" { - $obj = Resolve-JiraError -InputObject (ConvertFrom-Json $testJson) -WriteError -ErrorAction SilentlyContinue -ErrorVariable errOutput - $obj | Should BeNullOrEmpty - } - } -} diff --git a/Tests/Set-JiraConfigServer.Tests.ps1 b/Tests/Set-JiraConfigServer.Tests.ps1 deleted file mode 100644 index 28484d31..00000000 --- a/Tests/Set-JiraConfigServer.Tests.ps1 +++ /dev/null @@ -1,44 +0,0 @@ -Describe "Set-JiraConfigServer" { - - Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop - - InModuleScope JiraPS { - - . "$PSScriptRoot/Shared.ps1" - - $jiraServer = 'http://jiraserver.example.com' - - $configFile = Join-Path -Path $TestDrive -ChildPath 'config.xml' - Set-JiraConfigServer -Server $jiraServer -ConfigFile $configFile - - It "Ensures that a config.xml file exists" { - $configFile | Should Exist - } - - $xml = New-Object -TypeName Xml - $xml.Load($configFile) - $xmlServer = $xml.Config.Server - - It "Ensures that the XML file has a Config.Server element" { - $xmlServer | Should Not BeNullOrEmpty - } - - It "Sets the config file's Server value " { - $xmlServer | Should Be $jiraServer - } - - It "Trims whitespace from the provided Server parameter" { - Set-JiraConfigServer -Server "$jiraServer " -ConfigFile $configFile - $xml = New-Object -TypeName Xml - $xml.Load($configFile) - $xml.Config.Server | Should Be $jiraServer - } - - It "Trims trailing slasher from the provided Server parameter" { - Set-JiraConfigServer -Server "$jiraServer/" -ConfigFile $configFile - $xml = New-Object -TypeName Xml - $xml.Load($configFile) - $xml.Config.Server | Should Be $jiraServer - } - } -} diff --git a/Tests/Style.Tests.ps1 b/Tests/Style.Tests.ps1 new file mode 100644 index 00000000..009d651c --- /dev/null +++ b/Tests/Style.Tests.ps1 @@ -0,0 +1,131 @@ +#requires -modules BuildHelpers +#requires -modules Pester + +Describe "Validation of code styling" { + + BeforeAll { + Remove-Item -Path Env:\BH* + $projectRoot = (Resolve-Path "$PSScriptRoot/..").Path + if ($projectRoot -like "*Release") { + $projectRoot = (Resolve-Path "$projectRoot/..").Path + } + + Import-Module BuildHelpers + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -Path $projectRoot -ErrorAction SilentlyContinue + + $env:BHManifestToTest = $env:BHPSModuleManifest + $script:isBuild = $PSScriptRoot -like "$env:BHBuildOutput*" + if ($script:isBuild) { + $Pattern = [regex]::Escape($env:BHProjectPath) + + $env:BHBuildModuleManifest = $env:BHPSModuleManifest -replace $Pattern, $env:BHBuildOutput + $env:BHManifestToTest = $env:BHBuildModuleManifest + } + + Import-Module "$env:BHProjectPath/Tools/BuildTools.psm1" + + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + # Import-Module $env:BHManifestToTest + } + AfterAll { + Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue + Remove-Module BuildHelpers -ErrorAction SilentlyContinue + Remove-Item -Path Env:\BH* + } + + $docFiles = Get-ChildItem "$PSScriptRoot/.." -Include *.md -Recurse + $codeFiles = Get-ChildItem "$PSScriptRoot/.." -Include *.ps1, *.psm1 -Recurse + + It "has no trailing whitespace in code files" { + $badLines = @( + foreach ($file in $codeFiles) { + $lines = [System.IO.File]::ReadAllLines($file.FullName) + $lineCount = $lines.Count + + for ($i = 0; $i -lt $lineCount; $i++) { + if ($lines[$i] -match '\s+$') { + 'File: {0}, Line: {1}' -f $file.FullName, ($i + 1) + } + } + } + ) + + if ($badLines.Count -gt 0) { + throw "The following $($badLines.Count) lines contain trailing whitespace: `r`n`r`n$($badLines -join "`r`n")" + } + } + + It "has one newline at the end of the file" { + $badFiles = @( + foreach ($file in @($codeFiles + $docFiles)) { + $string = [System.IO.File]::ReadAllText($file.FullName) + if ($string.Length -gt 0 -and $string[-1] -ne "`n") { + $file.FullName + } + } + ) + + if ($badFiles.Count -gt 0) { + throw "The following files do not end with a newline: `r`n`r`n$($badFiles -join "`r`n")" + } + } + + It "uses UTF-8 for code files" { + $badFiles = @( + foreach ($file in $codeFiles) { + $encoding = Get-FileEncoding -Path $file.FullName + if ($encoding -and $encoding.encoding -ne "UTF8") { + $file.FullName + } + } + ) + + if ($badFiles.Count -gt 0) { + throw "The following files are not encoded with UTF-8 (no BOM): `r`n`r`n$($badFiles -join "`r`n")" + } + } + It "uses UTF-8 for documentation files" { + $badFiles = @( + foreach ($file in $docFiles) { + $encoding = Get-FileEncoding -Path $file.FullName + if ($encoding -and $encoding.encoding -ne "UTF8") { + $file.FullName + } + } + ) + + if ($badFiles.Count -gt 0) { + throw "The following files are not encoded with UTF-8 (no BOM): `r`n`r`n$($badFiles -join "`r`n")" + } + } + + It "uses CRLF as newline character in code files" { + $badFiles = @( + foreach ($file in $codeFiles) { + $string = [System.IO.File]::ReadAllText($file.FullName) + if ($string.Length -gt 0 -and $string -notmatch "\r\n$") { + $file.FullName + } + } + ) + + if ($badFiles.Count -gt 0) { + throw "The following files do not use CRLF as line break: `r`n`r`n$($badFiles -join "`r`n")" + } + } + + It "uses CRLF as newline character in documentation files" { + $badFiles = @( + foreach ($file in $docFiles) { + $string = [System.IO.File]::ReadAllText($file.FullName) + if ($string.Length -gt 0 -and $string -notmatch "\r\n$") { + $file.FullName + } + } + ) + + if ($badFiles.Count -gt 0) { + throw "The following files do not use CRLF as line break: `r`n`r`n$($badFiles -join "`r`n")" + } + } +} diff --git a/Tools/BuildTools.psm1 b/Tools/BuildTools.psm1 new file mode 100644 index 00000000..5cf3c3db --- /dev/null +++ b/Tools/BuildTools.psm1 @@ -0,0 +1,449 @@ +[CmdletBinding()] +param() + +function Invoke-Init { + [Alias("Init")] + [CmdletBinding()] + param() + begin { + Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -ErrorAction SilentlyContinue + Add-ToModulePath -Path $env:BHBuildOutput + } +} + +function Assert-True { + [CmdletBinding( DefaultParameterSetName = 'ByBool' )] + param( + [Parameter( Position = 0, Mandatory, ParameterSetName = 'ByScriptBlock' )] + [ScriptBlock]$ScriptBlock, + [Parameter( Position = 0, Mandatory, ParameterSetName = 'ByBool' )] + [Bool]$Bool, + [Parameter( Position = 1, Mandatory )] + [String]$Message + ) + + if ($ScriptBlock) { + $Bool = & $ScriptBlock + } + + if (-not $Bool) { + throw $Message + } +} + +function LogCall { + Assert-True { Test-Path TestDrive:\ } "This function only work inside pester" + + Set-Content -Value "$($MyInvocation.Invocationname) $($MyInvocation.UnBoundArguments -join " ")" -Path "TestDrive:\FunctionCalled.$($MyInvocation.Invocationname).txt" -Force +} + +function Add-ToModulePath ([String]$Path) { + $PSModulePath = $env:PSModulePath -split ([IO.Path]::PathSeparator) + if ($Path -notin $PSModulePath) { + $PSModulePath += $Path + $env:PSModulePath = $PSModulePath -join ([IO.Path]::PathSeparator) + } +} + +function Install-PSDepend { + if (-not (Get-Module PSDepend -ListAvailable)) { + if (Get-Module PowershellGet -ListAvailable) { + Install-Module PSDepend -Scope CurrentUser -ErrorAction Stop -Verbose + } + else { + throw "The PowershellGet module is not available." + } + } +} + +function Get-AppVeyorBuild { + param() + + Assert-True { $env:APPVEYOR_API_TOKEN } "missing api token for AppVeyor." + Assert-True { $env:APPVEYOR_ACCOUNT_NAME } "not an appveyor build." + + $invokeRestMethodSplat = @{ + Uri = "https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG" + Method = 'GET' + Headers = @{ + "Authorization" = "Bearer $env:APPVEYOR_API_TOKEN" + "Content-type" = "application/json" + } + } + Invoke-RestMethod @invokeRestMethodSplat +} + +function Get-TravisBuild { + param() + + Assert-True { $env:TRAVIS_API_TOKEN } "missing api token for Travis-CI." + Assert-True { $env:APPVEYOR_ACCOUNT_NAME } "not an appveyor build." + + $invokeRestMethodSplat = @{ + Uri = "https://api.travis-ci.org/builds?limit=10" + Method = 'Get' + Headers = @{ + "Authorization" = "token $env:TRAVIS_API_TOKEN" + "Travis-API-Version" = "3" + } + } + Invoke-RestMethod @invokeRestMethodSplat +} + +function Test-IsLastJob { + param() + + if (-not ('AppVeyor' -eq $env:BHBuildSystem)) { + return $true + } + Assert-True { $env:APPVEYOR_JOB_ID } "Invalid Job identifier" + + $buildData = Get-AppVeyorBuild + $lastJob = ($buildData.build.jobs | Select-Object -Last 1).jobId + + if ($lastJob -eq $env:APPVEYOR_JOB_ID) { + return $true + } + else { + return $false + } +} + +function Test-ShouldDeploy { + if (-not ($env:ShouldDeploy -eq $true)) { + return $false + } + # only deploy master branch + if (-not ('master' -eq $env:BHBranchName)) { + return $false + } + # it cannot be a PR + if ($env:APPVEYOR_PULL_REQUEST_NUMBER) { + return $false + } + # only deploy from AppVeyor + if (-not ($env:APPVEYOR_JOB_ID)) { + return $false + } + # must be last job of AppVeyor + if (-not (Test-IsLastJob)) { + return $false + } + # Travis-CI must be finished (if used) + # TODO: (Test-TravisProgress) -and + # it cannot have a commit message that contains "skip-deploy" + if ($env:BHCommitMessage -like '*skip-deploy*') { + return $false + } + + return $true +} + +function Publish-GithubRelease { + param( + [Parameter( Mandatory )] + [ValidateNotNullOrEmpty()] + [String]$GITHUB_ACCESS_TOKEN, + [String]$ProjectOwner = "AtlassianPS", + [String]$ReleaseText, + [Object]$NextBuildVersion + ) + + Assert-True { $env:BHProjectName } "Missing AppVeyor's Repo Name" + + $body = @{ + "tag_name" = "v$NextBuildVersion" + "target_commitish" = "master" + "name" = "v$NextBuildVersion" + "body" = $ReleaseText + "draft" = $false + "prerelease" = $false + } | ConvertTo-Json + + $releaseParams = @{ + Uri = "https://api.github.com/repos/{0}/{1}/releases" -f $ProjectOwner, $env:BHProjectName + Method = 'POST' + Headers = @{ + Authorization = 'Basic ' + [Convert]::ToBase64String( + [Text.Encoding]::ASCII.GetBytes($GITHUB_ACCESS_TOKEN + ":x-oauth-basic") + ) + } + ContentType = 'application/json' + Body = $body + ErrorAction = "Stop" + } + Invoke-RestMethod @releaseParams +} + +function Publish-GithubReleaseArtifact { + param( + [Parameter( Mandatory )] + [ValidateNotNullOrEmpty()] + [String]$GITHUB_ACCESS_TOKEN, + [Uri]$Uri, + [String]$Path + ) + + $body = [System.IO.File]::ReadAllBytes($Path) + $assetParams = @{ + Uri = $Uri + Method = 'POST' + Headers = @{ + Authorization = 'Basic ' + [Convert]::ToBase64String( + [Text.Encoding]::ASCII.GetBytes($GITHUB_ACCESS_TOKEN + ":x-oauth-basic") + ) + } + ContentType = "application/zip" + Body = $body + } + Invoke-RestMethod @assetParams +} + +function Set-AppVeyorBuildNumber { + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseShouldProcessForStateChangingFunctions', '')] + param() + + Assert-True { $env:APPVEYOR_REPO_NAME } "Is not an AppVeyor Job" + Assert-True { $env:APPVEYOR_API_TOKEN } "Is missing AppVeyor's API token" + + $separator = "-" + $headers = @{ + "Authorization" = "Bearer $env:APPVEYOR_API_TOKEN" + "Content-type" = "application/json" + } + $apiURL = "https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG" + $history = Invoke-RestMethod -Uri "$apiURL/history?recordsNumber=2" -Headers $headers -Method Get + if ($history.builds.Count -eq 2) { + $s = Invoke-RestMethod -Uri "$apiURL/settings" -Headers $headers -Method Get + $s.settings.nextBuildNumber = ($s.settings.nextBuildNumber - 1) + Invoke-RestMethod -Uri 'https://ci.appveyor.com/api/projects' -Headers $headers -Body ($s.settings | ConvertTo-Json -Depth 10) -Method Put + $previousVersion = $history.builds[1].version + if ($previousVersion.IndexOf("$separator") -ne "-1") {$previousVersion = $previousVersion.SubString(0, $previousVersion.IndexOf("$separator"))} + Update-AppveyorBuild -Version $previousVersion$separator$((New-Guid).ToString().SubString(0,8)) + } +} + +#region Old +# function allJobsFinished { +# param() + +# if (-not ('AppVeyor' -eq $env:BHBuildSystem)) { +# return $true +# } +# if (-not ($env:APPVEYOR_API_TOKEN)) { +# Write-Warning "Missing `$env:APPVEYOR_API_TOKEN" +# return $true +# } +# if (-not ($env:APPVEYOR_ACCOUNT_NAME)) { +# Write-Warning "Missing `$env:APPVEYOR_ACCOUNT_NAME" +# return $true +# } + +# Test-IsLastJob + +# Write-Host "[IDLE] :: waiting for other jobs to complete" + +# [datetime]$stop = ([datetime]::Now).AddMinutes($env:TimeOutMins) + +# do { +# $project = Get-AppVeyorBuild +# $continue = @() +# $project.build.jobs | Where-Object {$_.jobId -ne $env:APPVEYOR_JOB_ID} | Foreach-Object { +# $job = $_ +# switch -regex ($job.status) { +# "failed" { throw "AppVeyor's Job ($($job.jobId)) failed." } +# "(running|success)" { $continue += $true; continue } +# Default { $continue += $false; Write-Host "new state: $_.status" } +# } +# } +# if ($false -notin $continue) { return $true } +# Start-sleep 5 +# } while (([datetime]::Now) -lt $stop) + +# throw "Test jobs were not finished in $env:TimeOutMins minutes" +# } +#endregion Old + +function Get-FileEncoding { + <# + .SYNOPSIS + Attempt to determine a file type based on a BOM or file header. + .DESCRIPTION + This script attempts to determine file types based on a byte sequence at the beginning of the file. + + If an identifiable byte sequence is not present the file type cannot be determined using this method. + The order signatures appear in is critical where signatures overlap. For example, UTF32-LE must be evaluated before UTF16-LE. + .LINK + https://en.wikipedia.org/wiki/Byte_order_mark#cite_note-b-15 + https://filesignatures.net + + .SOURCE + https://gist.github.com/indented-automation/8e603144167c7acca4dd8f653d47441e + #> + + [CmdletBinding()] + [OutputType('EncodingInfo')] + param ( + # The path to a file to analyze. + [Parameter(Mandatory, Position = 1, ValueFromPipeline, ValueFromPipelineByPropertyName)] + [ValidateScript( { Test-Path $_ -PathType Leaf } )] + [Alias('FullName')] + [String]$Path, + + # Test the file against a small set of signature definitions for binary file types. + # + # Identification should be treated as tentative. Several file formats cannot be identified using the sequence at the start alone. + [Switch]$IncludeBinary + ) + + begin { + $signatures = [Ordered]@{ + 'UTF32-LE' = 'FF-FE-00-00' + 'UTF32-BE' = '00-00-FE-FF' + 'UTF8-BOM' = 'EF-BB-BF' + 'UTF16-LE' = 'FF-FE' + 'UTF16-BE' = 'FE-FF' + 'UTF7' = '2B-2F-76-38', '2B-2F-76-39', '2B-2F-76-2B', '2B-2F-76-2F' + 'UTF1' = 'F7-64-4C' + 'UTF-EBCDIC' = 'DD-73-66-73' + 'SCSU' = '0E-FE-FF' + 'BOCU-1' = 'FB-EE-28' + 'GB-18030' = '84-31-95-33' + } + + if ($IncludeBinary) { + $signatures += [Ordered]@{ + 'LNK' = '4C-00-00-00-01-14-02-00' + 'MSEXCEL' = '50-4B-03-04-14-00-06-00' + 'PNG' = '89-50-4E-47-0D-0A-1A-0A' + 'MSOFFICE' = 'D0-CF-11-E0-A1-B1-1A-E1' + '7ZIP' = '37-7A-BC-AF-27-1C' + 'RTF' = '7B-5C-72-74-66-31' + 'GIF' = '47-49-46-38' + 'REGPOL' = '50-52-65-67' + 'JPEG' = 'FF-D8' + 'MSEXE' = '4D-5A' + 'ZIP' = '50-4B' + } + } + + # Convert sequence strings to byte arrays. Intended to simplify signature maintenance. + [String[]]$keys = $signatures.Keys + foreach ($name in $keys) { + [System.Collections.Generic.List[System.Collections.Generic.List[Byte]]]$values = foreach ($value in $signatures[$name]) { + [System.Collections.Generic.List[Byte]]$signatureBytes = foreach ($byte in $value.Split('-')) { + [Convert]::ToByte($byte, 16) + } + , $signatureBytes + } + $signatures[$name] = $values + } + } + + process { + try { + $Path = $pscmdlet.GetUnresolvedProviderPathFromPSPath($Path) + + $bytes = [Byte[]]::new(8) + $stream = New-Object System.IO.StreamReader($Path) + $null = $stream.Peek() + $enc = $stream.CurrentEncoding + $stream.Close() + $stream = [System.IO.File]::OpenRead($Path) + $null = $stream.Read($bytes, 0, $bytes.Count) + $bytes = [System.Collections.Generic.List[Byte]]$bytes + $stream.Close() + + if ($enc -eq [System.Text.Encoding]::UTF8) { + $encoding = "UTF8" + } + + foreach ($name in $signatures.Keys) { + $sampleEncoding = foreach ($sequence in $signatures[$name]) { + $sample = $bytes.GetRange(0, $sequence.Count) + + if ([System.Linq.Enumerable]::SequenceEqual($sample, $sequence)) { + $name + break + } + } + if ($sampleEncoding) { + $encoding = $sampleEncoding + break + } + } + + if (-not $encoding) { + $encoding = "ASCII" + } + + [PSCustomObject]@{ + Name = Split-Path $Path -Leaf + Extension = [System.IO.Path]::GetExtension($Path) + Encoding = $encoding + Path = $Path + } | Add-Member -TypeName 'EncodingInfo' -PassThru + } + catch { + $pscmdlet.WriteError($_) + } + } +} + +function Remove-Utf8Bom { + <# + .SYNOPSIS + Removes a UTF8 BOM from a file. + .DESCRIPTION + Removes a UTF8 BOM from a file if the BOM appears to be present. + The UTF8 BOM is identified by the byte sequence 0xEF 0xBB 0xBF at the beginning of the file. + .EXAMPLE + Remove-Utf8Bom -Path c:\file.txt + Remove a BOM from a single file. + .EXAMPLE + Get-ChildItem c:\folder -Recurse -File | Remove-Utf8Bom + Remove the BOM from every file returned by Get-ChildItem. + .LINK + https://gist.github.com/indented-automation/5f6b87f31c438f14905f62961025758b + #> + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseShouldProcessForStateChangingFunctions', '')] + [CmdletBinding()] + param ( + # The path to a file which should be updated. + [Parameter(Mandatory, Position = 1, ValueFromPipeline, ValueFromPipelineByPropertyName)] + [ValidateScript( { Test-Path $_ -PathType Leaf } )] + [Alias('FullName')] + [String]$Path + ) + + begin { + $encoding = [System.Text.UTF8Encoding]::new($false) + } + + process { + $Path = $pscmdlet.GetUnresolvedProviderPathFromPSPath($Path) + + try { + $bom = [Byte[]]::new(3) + $stream = [System.IO.File]::OpenRead($Path) + $null = $stream.Read($bom, 0, 3) + $stream.Close() + + if ([BitConverter]::ToString($bom, 0) -eq 'EF-BB-BF') { + [System.IO.File]::WriteAllLines( + $Path, + [System.IO.File]::ReadAllLines($Path), + $encoding + ) + } + else { + Write-Verbose ('A UTF8 BOM was not detected on the file {0}' -f $Path) + } + } + catch { + Write-Error -ErrorRecord $_ + } + } +} + +Export-ModuleMember -Function * -Alias * diff --git a/Tools/PackageManagement_x64.msi b/Tools/PackageManagement_x64.msi deleted file mode 100644 index 6f97aae8..00000000 Binary files a/Tools/PackageManagement_x64.msi and /dev/null differ diff --git a/Tools/build.psm1 b/Tools/build.psm1 deleted file mode 100644 index f3732dce..00000000 --- a/Tools/build.psm1 +++ /dev/null @@ -1,200 +0,0 @@ -# requires -module InvokeBuild -[CmdletBinding()] -param() - -function Assert-True { - param( - [ScriptBlock]$ScriptBlock, - [String]$Message - ) - - if (-not $ScriptBlock) { - throw $Message - } -} - -function Add-ToModulePath ([String]$Path) { - $PSModulePath = $env:PSModulePath -split ([IO.Path]::PathSeparator) - if ($Path -notin $PSModulePath) { - $PSModulePath += $Path - $env:PSModulePath = $PSModulePath -join ([IO.Path]::PathSeparator) - } -} -function Install-PSDepend { - if (-not (Get-Module PSDepend -ListAvailable)) { - if (Get-Module PowershellGet -ListAvailable) { - Install-Module PSDepend -Scope CurrentUser -ErrorAction Stop -Verbose - } - else { - throw "The PowershellGet module is not available." - } - } -} - -function Get-AppVeyorBuild { - param() - - Assert-True { $env:APPVEYOR_API_TOKEN } "missing api token for AppVeyor." - Assert-True { $env:APPVEYOR_ACCOUNT_NAME } "not an appveyor build." - - Invoke-RestMethod -Uri "https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG" -Method GET -Headers @{ - "Authorization" = "Bearer $env:APPVEYOR_API_TOKEN" - "Content-type" = "application/json" - } -} - -function Get-TravisBuild { - param() - - Assert-True { $env:TRAVIS_API_TOKEN } "missing api token for Travis-CI." - Assert-True { $env:APPVEYOR_ACCOUNT_NAME } "not an appveyor build." - - Invoke-RestMethod -Uri "https://api.travis-ci.org/builds?limit=10" -Method Get -Headers @{ - "Authorization" = "token $env:TRAVIS_API_TOKEN" - "Travis-API-Version" = "3" - } -} - -function Test-IsLastJob { - param() - - if (-not ('AppVeyor' -eq $env:BHBuildSystem)) { - return $true - } - Assert-True { $env:APPVEYOR_JOB_ID } "Invalid Job identifier" - - $buildData = Get-AppVeyorBuild - $lastJob = ($buildData.build.jobs | Select-Object -Last 1).jobId - - if ($lastJob -eq $env:APPVEYOR_JOB_ID) { - return $true - } - else { - return $false - } -} - -function Test-ShouldDeploy { - # only deploy master branch - if (-not ('master' -eq $env:BHBranchName)) { - return $false - } - # it cannot be a PR - if ($env:APPVEYOR_PULL_REQUEST_NUMBER) { - return $false - } - # only deploy from AppVeyor - if (-not ('AppVeyor' -eq $env:BHBuildSystem)) { - return $false - } - # must be last job of AppVeyor - if (-not (Test-IsLastJob)) { - return $false - } - # Travis-CI must be finished (if used) - # TODO: (Test-TravisProgress) -and - # it cannot have a commit message that contains "skip-deploy" - if ($env:BHCommitMessage -like '*skip-deploy*') { - return $false - } - - return $true -} - -function Publish-GithubRelease { - param( - [String]$ReleaseText, - [Object]$NextBuildVersion - ) - - Assert-True { $env:access_token } "Missing Github authentication" - Assert-True { $env:APPVEYOR_REPO_NAME } "Missing AppVeyor's Repo Name" - - $body = @{ - "tag_name" = "v$NextBuildVersion" - "target_commitish" = "master" - "name" = "v$NextBuildVersion" - "body" = $ReleaseText - "draft" = $false - "prerelease" = $false - } | ConvertTo-Json - - $releaseParams = @{ - Uri = "https://api.github.com/repos/{0}/releases" -f $env:APPVEYOR_REPO_NAME - Method = 'POST' - Headers = @{ - Authorization = 'Basic ' + [Convert]::ToBase64String( - [Text.Encoding]::ASCII.GetBytes($env:access_token + ":x-oauth-basic") - ) - } - ContentType = 'application/json' - Body = $body - ErrorAction = "Stop" - } - Invoke-RestMethod @releaseParams -} - -function Publish-GithubReleaseArtifact { - param( - [Uri]$Uri, - [String]$Path - ) - - Assert-True { $env:access_token } "Missing Github authentication" - Assert-True { $env:APPVEYOR_REPO_NAME } "Missing AppVeyor's Repo Name" - - $body = [System.IO.File]::ReadAllBytes($Path) - $assetParams = @{ - Uri = $Uri - Method = 'POST' - Headers = @{ - Authorization = 'Basic ' + [Convert]::ToBase64String( - [Text.Encoding]::ASCII.GetBytes($env:access_token + ":x-oauth-basic") - ) - } - ContentType = "application/zip" - Body = $body - } - Invoke-RestMethod @assetParams -} - -#region Old -# function allJobsFinished { -# param() - -# if (-not ('AppVeyor' -eq $env:BHBuildSystem)) { -# return $true -# } -# if (-not ($env:APPVEYOR_API_TOKEN)) { -# Write-Warning "Missing `$env:APPVEYOR_API_TOKEN" -# return $true -# } -# if (-not ($env:APPVEYOR_ACCOUNT_NAME)) { -# Write-Warning "Missing `$env:APPVEYOR_ACCOUNT_NAME" -# return $true -# } - -# Test-IsLastJob - -# Write-Host "[IDLE] :: waiting for other jobs to complete" - -# [datetime]$stop = ([datetime]::Now).AddMinutes($env:TimeOutMins) - -# do { -# $project = Get-AppVeyorBuild -# $continue = @() -# $project.build.jobs | Where-Object {$_.jobId -ne $env:APPVEYOR_JOB_ID} | Foreach-Object { -# $job = $_ -# switch -regex ($job.status) { -# "failed" { throw "AppVeyor's Job ($($job.jobId)) failed." } -# "(running|success)" { $continue += $true; continue } -# Default { $continue += $false; Write-Host "new state: $_.status" } -# } -# } -# if ($false -notin $continue) { return $true } -# Start-sleep 5 -# } while (([datetime]::Now) -lt $stop) - -# throw "Test jobs were not finished in $env:TimeOutMins minutes" -# } -#endregion Old diff --git a/Tools/build.requirements.psd1 b/Tools/build.requirements.psd1 index 48501742..f168bcd5 100644 --- a/Tools/build.requirements.psd1 +++ b/Tools/build.requirements.psd1 @@ -10,11 +10,17 @@ } Version = "latest" } + Configuration = @{ + Parameters = @{ + AllowClobber = $true + } + Version = "latest" + } Pester = @{ Parameters = @{ SkipPublisherCheck = $true } - Version = "4.3.1" + Version = "4.4.2" } platyPS = "latest" PSScriptAnalyzer = @{ diff --git a/Tools/setup.ps1 b/Tools/setup.ps1 index a6c620d5..06cce0cf 100644 --- a/Tools/setup.ps1 +++ b/Tools/setup.ps1 @@ -1,22 +1,9 @@ +#requires -Module PowerShellGet + [CmdletBinding()] [System.Diagnostics.CodeAnalysis.SuppressMessage('PSAvoidUsingWriteHost', '')] param() -# If PowerShellGet is not available (PSv4 and PSv3), it must be installed -if ($PSVersionTable.PSVersion.Major -in @(3, 4)) { - if (-not (Get-Module PowerShellGet -ListAvailable)) { - Write-Host "Installing PowershellGet" - Start-Process -FilePath "$env:SystemRoot\System32\msiexec.exe" -ArgumentList "/qn /quiet /i $(Join-Path $PSScriptRoot "PackageManagement_x64.msi")" -Wait - $null = Install-PackageProvider -Name NuGet -Force -ErrorAction SilentlyContinue - } -} - -# Fail if PowerShellGet could not be found -Import-Module PowerShellGet -ErrorAction SilentlyContinue -if (-not (Get-Module PowerShellGet)) { - throw "PowerShellGet still not available" -} - # PowerShell 5.1 and bellow need the PSGallery to be intialized if (-not ($gallery = Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue)) { Write-Host "Installing PackageProvider NuGet" @@ -26,7 +13,7 @@ if (-not ($gallery = Get-PSRepository -Name PSGallery -ErrorAction SilentlyConti # Make PSGallery trusted, to aviod a confirmation in the console if (-not ($gallery.Trusted)) { Write-Host "Trusting PSGallery" - # Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted -ErrorAction SilentlyContinue + Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted -ErrorAction SilentlyContinue } Write-Host "Installing PSDepend" diff --git a/_posts/2017-06-24-JiraPS-v2.0.md b/_posts/2017-06-24-JiraPS-v2.0.md index dab3b6c5..ce387300 100644 --- a/_posts/2017-06-24-JiraPS-v2.0.md +++ b/_posts/2017-06-24-JiraPS-v2.0.md @@ -1,6 +1,6 @@ --- layout: article -permalink: /article/:categories/:title +permalink: /article/Announcement/JiraPS-v2.0.0 title: JiraPS v2.0.0 date: 2017-06-24 13:00:00 categories: Announcement @@ -15,11 +15,14 @@ We have just uploaded a new version of the **JiraPS** module to the [Gallery](ht # Description + This is the first release of **JiraPS** under the _AtlassianPS_ organization. This release **contains breaking changes** – so please be aware and careful when updating the module. # CHANGELOG + ## Changes to the code module + * Move module to organization _AtlassianPS_ * Rename of the module to `JiraPS` **[breaking change]** * Rename of module’s custom objects to `JiraPS.*` **[breaking change]** diff --git a/_posts/2017-06-25-JiraPS-v2.1.md b/_posts/2017-06-25-JiraPS-v2.1.md index 1eaa3435..ea4b2ee0 100644 --- a/_posts/2017-06-25-JiraPS-v2.1.md +++ b/_posts/2017-06-25-JiraPS-v2.1.md @@ -1,6 +1,6 @@ --- layout: article -permalink: /article/:categories/:title +permalink: /article/Announcement/JiraPS-v2.1.0 title: JiraPS v2.1.0 date: 2017-06-25 12:00:00 categories: Announcement @@ -15,7 +15,9 @@ We have just uploaded a new version of the **JiraPS** module to the [Gallery](ht # Description + This release brings a lot of new functionality, improvements and bug fixes that has been submitted by our contributors. Including: + * Managing RemoteLinks * Managing IssueLinks * Managing Watchers @@ -25,44 +27,47 @@ This release brings a lot of new functionality, improvements and bug fixes that **We highly recommend updating, as this release contains really great stuff.** # CHANGELOG -## FEATURES: - - `Get-JiraIssueEditMetadata`: Returns metadata required to create an issue in JIRA (#65, [@lipkau][]) - - `Get-JiraRemoteLink`: Returns a remote link from a JIRA issue (#80, [@lipkau][]) - - `Remove-JiraRemoteLink`: Removes a remote link from a JIRA issue (#80, [@lipkau][]) - - `Get-JiraComponent`: Returns a Component from JIRA (#68, [@axxelG][]) - - `Add-JiraIssueWorklog`: Add worklog items to an issue (#83, [@jkknorr][]) - - Added support for getting and managing Issue Watchers (`Add-JiraIssueWatcher`, `Get-JiraIssueWatcher`, `Remove-JiraIssueWatcher`) (#73, [@ebekker][]) - - Added IssueLink functionality (`Add-JiraIssueLink`, `Get-JiraIssueLink`, `Get-JiraIssueLinkType`, `Remove-JiraIssueLink`) (#131, [@lipkau][]) -## IMPROVEMENTS: - - `New-JiraIssue`: _Description_ and _Priority_ are no longer mandatory (#53, [@brianbunke][]) - - Added property `Components` to `PSjira.Project` (#68, [@axxelG][]) - - `Invoke-JiraIssueTransition`: add support for parameters _Fields_, _Comment_ and _Assignee_ (#38, [@padgers][]) - - `New-JiraIssue`: support parameter _FixVersion_ (#103, [@Dejulia489][]) - - `Set-JiraIssue`: support parameter _FixVersion_ (#103, [@Dejulia489][]) - - Respect the global `$PSDefaultParameterValues` inside the module (#110, [@lipkau][]) - - `New-JiraSession`: Display warning when login needs CAPTCHA (#111, [@lipkau][]) - - Switched to _Basic Authentication_ when generating the session (#116, [@lipkau][]) - - Added more tests for the CI (#142, [@lipkau][]) +## FEATURES + +* `Get-JiraIssueEditMetadata`: Returns metadata required to create an issue in JIRA (#65, [@lipkau][]) +* `Get-JiraRemoteLink`: Returns a remote link from a JIRA issue (#80, [@lipkau][]) +* `Remove-JiraRemoteLink`: Removes a remote link from a JIRA issue (#80, [@lipkau][]) +* `Get-JiraComponent`: Returns a Component from JIRA (#68, [@axxelG][]) +* `Add-JiraIssueWorklog`: Add worklog items to an issue (#83, [@jkknorr][]) +* Added support for getting and managing Issue Watchers (`Add-JiraIssueWatcher`, `Get-JiraIssueWatcher`, `Remove-JiraIssueWatcher`) (#73, [@ebekker][]) +* Added IssueLink functionality (`Add-JiraIssueLink`, `Get-JiraIssueLink`, `Get-JiraIssueLinkType`, `Remove-JiraIssueLink`) (#131, [@lipkau][]) + +## IMPROVEMENTS -## BUG FIXES: - - `Invoke-JiraMethod`: Error when Invoke-WebRequest returns '204 No content' (#42, [@colhal][]) - - `Invoke-JiraIssueTransition`: Error when Invoke-WebRequest returns '204 No content' (#43, [@colhal][]) - - `Set-JiraIssueLabel`: Forced label property to be an array (#88, [@kittholland][]) - - `Invoke-JiraMethod`: Send ContentType as Parameter instead of in the Header (#121, [@lukhase][]) +* `New-JiraIssue`: _Description_ and _Priority_ are no longer mandatory (#53, [@brianbunke][]) +* Added property `Components` to `PSJira.Project` (#68, [@axxelG][]) +* `Invoke-JiraIssueTransition`: add support for parameters _Fields_, _Comment_ and _Assignee_ (#38, [@padgers][]) +* `New-JiraIssue`: support parameter _FixVersion_ (#103, [@Dejulia489][]) +* `Set-JiraIssue`: support parameter _FixVersion_ (#103, [@Dejulia489][]) +* Respect the global `$PSDefaultParameterValues` inside the module (#110, [@lipkau][]) +* `New-JiraSession`: Display warning when login needs CAPTCHA (#111, [@lipkau][]) +* Switched to _Basic Authentication_ when generating the session (#116, [@lipkau][]) +* Added more tests for the CI (#142, [@lipkau][]) +## BUG FIXES +* `Invoke-JiraMethod`: Error when Invoke-WebRequest returns '204 No content' (#42, [@colhal][]) +* `Invoke-JiraIssueTransition`: Error when Invoke-WebRequest returns '204 No content' (#43, [@colhal][]) +* `Set-JiraIssueLabel`: Forced label property to be an array (#88, [@kittholland][]) +* `Invoke-JiraMethod`: Send ContentType as Parameter instead of in the Header (#121, [@lukhase][]) -[@alexsuslin]: https://github.com/alexsuslin -[@axxelG]: https://github.com/axxelG -[@brianbunke]: https://github.com/brianbunke -[@colhal]: https://github.com/colhal -[@Dejulia489]: https://github.com/Dejulia489 -[@ebekker]: https://github.com/ebekker -[@jkknorr]: https://github.com/jkknorr -[@kittholland]: https://github.com/kittholland -[@LiamLeane]: https://github.com/LiamLeane -[@lipkau]: https://github.com/lipkau -[@lukhase]: https://github.com/lukhase -[@padgers]: https://github.com/padgers -[@ThePSAdmin]: https://github.com/ThePSAdmin + + [@alexsuslin]: https://github.com/alexsuslin + [@axxelG]: https://github.com/axxelG + [@brianbunke]: https://github.com/brianbunke + [@colhal]: https://github.com/colhal + [@Dejulia489]: https://github.com/Dejulia489 + [@ebekker]: https://github.com/ebekker + [@jkknorr]: https://github.com/jkknorr + [@kittholland]: https://github.com/kittholland + [@LiamLeane]: https://github.com/LiamLeane + [@lipkau]: https://github.com/lipkau + [@lukhase]: https://github.com/lukhase + [@padgers]: https://github.com/padgers + [@ThePSAdmin]: https://github.com/ThePSAdmin diff --git a/_posts/2017-08-05-JiraPS-v2.2.md b/_posts/2017-08-05-JiraPS-v2.2.md index 92f1a3a4..2f8714fb 100644 --- a/_posts/2017-08-05-JiraPS-v2.2.md +++ b/_posts/2017-08-05-JiraPS-v2.2.md @@ -1,6 +1,6 @@ --- layout: article -permalink: /article/:categories/:title +permalink: /article/Announcement/JiraPS-v2.2.0 title: JiraPS v2.2.0 date: 2017-08-05 12:00:00 categories: Announcement @@ -15,30 +15,34 @@ We have just uploaded a new version of the **JiraPS** module to the [Gallery](ht # Description + This release brings new functionality, improvements and bug fixes that has been submitted by our contributors. Including: + * Functions to manage Versions in Jira -_Details are listed below_ +Details are listed below # CHANGELOG -## FEATURES: -- `New-JiraVerion`: Create a new Version in a project (#158, [@Dejulia489][]) -- `Get-JiraVerion`: Create a new Version in a project (#158, [@Dejulia489][]) -- `Set-JiraVerion`: Create a new Version in a project (#158, [@Dejulia489][]) -- `Remove-JiraVerion`: Create a new Version in a project (#158, [@Dejulia489][]) -- New custom object for Versions (#158, [@Dejulia489][]) - - -[@alexsuslin]: https://github.com/alexsuslin -[@axxelG]: https://github.com/axxelG -[@brianbunke]: https://github.com/brianbunke -[@colhal]: https://github.com/colhal -[@Dejulia489]: https://github.com/Dejulia489 -[@ebekker]: https://github.com/ebekker -[@jkknorr]: https://github.com/jkknorr -[@kittholland]: https://github.com/kittholland -[@LiamLeane]: https://github.com/LiamLeane -[@lipkau]: https://github.com/lipkau -[@lukhase]: https://github.com/lukhase -[@padgers]: https://github.com/padgers -[@ThePSAdmin]: https://github.com/ThePSAdmin + +## FEATURES + +* `New-JiraVersion`: Create a new Version in a project (#158, [@Dejulia489][]) +* `Get-JiraVersion`: Create a new Version in a project (#158, [@Dejulia489][]) +* `Set-JiraVersion`: Create a new Version in a project (#158, [@Dejulia489][]) +* `Remove-JiraVersion`: Create a new Version in a project (#158, [@Dejulia489][]) +* New custom object for Versions (#158, [@Dejulia489][]) + + + [@alexsuslin]: https://github.com/alexsuslin + [@axxelG]: https://github.com/axxelG + [@brianbunke]: https://github.com/brianbunke + [@colhal]: https://github.com/colhal + [@Dejulia489]: https://github.com/Dejulia489 + [@ebekker]: https://github.com/ebekker + [@jkknorr]: https://github.com/jkknorr + [@kittholland]: https://github.com/kittholland + [@LiamLeane]: https://github.com/LiamLeane + [@lipkau]: https://github.com/lipkau + [@lukhase]: https://github.com/lukhase + [@padgers]: https://github.com/padgers + [@ThePSAdmin]: https://github.com/ThePSAdmin diff --git a/_posts/2017-10-07-JiraPS-v2.3.md b/_posts/2017-10-07-JiraPS-v2.3.md index 90ab9a60..b46b4b96 100644 --- a/_posts/2017-10-07-JiraPS-v2.3.md +++ b/_posts/2017-10-07-JiraPS-v2.3.md @@ -1,6 +1,6 @@ --- layout: article -permalink: /article/:categories/:title +permalink: /article/Announcement/JiraPS-v2.3 title: JiraPS v2.3 date: 2017-10-07 13:50:00 categories: Announcement @@ -15,31 +15,35 @@ We have just uploaded a new version of the **JiraPS** module to the [Gallery](ht # Description + This release brings new functionality, improvements and bug fixes that has been submitted by our contributors. -_Details are listed below_ +Details are listed below # CHANGELOG + ## FEATURES - - `Get-JiraServerInformation`: Fetches the information about the server (#187, [@lipkau][]) + +* `Get-JiraServerInformation`: Fetches the information about the server (#187, [@lipkau][]) ## IMPROVEMENTS - - Added `-AddComment` to `Set-JiraIssue`. Allowing the user to write a comment for the changes to the issue (#167, [@Clijsters][]) - - Changed the default visibility of comments (#172, [@lipkau][]) - - Added more properties to `JiraPS.User` objects (#152, [@lipkau][]) - - -[@alexsuslin]: https://github.com/alexsuslin -[@axxelG]: https://github.com/axxelG -[@brianbunke]: https://github.com/brianbunke -[@Clijsters]: https://github.com/Clijsters -[@colhal]: https://github.com/colhal -[@Dejulia489]: https://github.com/Dejulia489 -[@ebekker]: https://github.com/ebekker -[@jkknorr]: https://github.com/jkknorr -[@kittholland]: https://github.com/kittholland -[@LiamLeane]: https://github.com/LiamLeane -[@lipkau]: https://github.com/lipkau -[@lukhase]: https://github.com/lukhase -[@padgers]: https://github.com/padgers -[@ThePSAdmin]: https://github.com/ThePSAdmin + +* Added `-AddComment` to `Set-JiraIssue`. Allowing the user to write a comment for the changes to the issue (#167, [@Clijsters][]) +* Changed the default visibility of comments (#172, [@lipkau][]) +* Added more properties to `JiraPS.User` objects (#152, [@lipkau][]) + + + [@alexsuslin]: https://github.com/alexsuslin + [@axxelG]: https://github.com/axxelG + [@brianbunke]: https://github.com/brianbunke + [@Clijsters]: https://github.com/Clijsters + [@colhal]: https://github.com/colhal + [@Dejulia489]: https://github.com/Dejulia489 + [@ebekker]: https://github.com/ebekker + [@jkknorr]: https://github.com/jkknorr + [@kittholland]: https://github.com/kittholland + [@LiamLeane]: https://github.com/LiamLeane + [@lipkau]: https://github.com/lipkau + [@lukhase]: https://github.com/lukhase + [@padgers]: https://github.com/padgers + [@ThePSAdmin]: https://github.com/ThePSAdmin diff --git a/_posts/2017-12-05-JiraPS-v2.4.md b/_posts/2017-12-05-JiraPS-v2.4.md index 1a3b9bae..d7715dd3 100644 --- a/_posts/2017-12-05-JiraPS-v2.4.md +++ b/_posts/2017-12-05-JiraPS-v2.4.md @@ -1,6 +1,6 @@ --- layout: article -permalink: /article/:categories/:title +permalink: /article/Announcement/JiraPS-v2.4 title: JiraPS v2.4 date: 2017-12-05 23:51:07 categories: Announcement @@ -15,32 +15,36 @@ We have just uploaded a new version of the **JiraPS** module to the [Gallery](ht # Description + This release brings new functionality, improvements and bug fixes that has been submitted by our contributors. -_Details are listed below_ +Details are listed below # CHANGELOG + ## FEATURES - - `Add-JiraIssueAttachment`: Add an attachment to an issue (#137, [@beaudryj][]) - - `Get-JiraIssueAttachment`: Get attachments from issues (#137, [@beaudryj][]) - - `Remove-JiraIssueAttachment`: Remove attachments from issues (#137, [@beaudryj][]) - -IMPROVEMENTS: - - `JiraPS.Issue` now has a property for Attachments `JiraPS.Attachment` (#137, [@beaudryj][]) - - -[@alexsuslin]: https://github.com/alexsuslin -[@axxelG]: https://github.com/axxelG -[@beaudryj]: https://github.com/beaudryj -[@brianbunke]: https://github.com/brianbunke -[@Clijsters]: https://github.com/Clijsters -[@colhal]: https://github.com/colhal -[@Dejulia489]: https://github.com/Dejulia489 -[@ebekker]: https://github.com/ebekker -[@jkknorr]: https://github.com/jkknorr -[@kittholland]: https://github.com/kittholland -[@LiamLeane]: https://github.com/LiamLeane -[@lipkau]: https://github.com/lipkau -[@lukhase]: https://github.com/lukhase -[@padgers]: https://github.com/padgers -[@ThePSAdmin]: https://github.com/ThePSAdmin + +* `Add-JiraIssueAttachment`: Add an attachment to an issue (#137, [@beaudryj][]) +* `Get-JiraIssueAttachment`: Get attachments from issues (#137, [@beaudryj][]) +* `Remove-JiraIssueAttachment`: Remove attachments from issues (#137, [@beaudryj][]) + +### IMPROVEMENTS + +* `JiraPS.Issue` now has a property for Attachments `JiraPS.Attachment` (#137, [@beaudryj][]) + + + [@alexsuslin]: https://github.com/alexsuslin + [@axxelG]: https://github.com/axxelG + [@beaudryj]: https://github.com/beaudryj + [@brianbunke]: https://github.com/brianbunke + [@Clijsters]: https://github.com/Clijsters + [@colhal]: https://github.com/colhal + [@Dejulia489]: https://github.com/Dejulia489 + [@ebekker]: https://github.com/ebekker + [@jkknorr]: https://github.com/jkknorr + [@kittholland]: https://github.com/kittholland + [@LiamLeane]: https://github.com/LiamLeane + [@lipkau]: https://github.com/lipkau + [@lukhase]: https://github.com/lukhase + [@padgers]: https://github.com/padgers + [@ThePSAdmin]: https://github.com/ThePSAdmin diff --git a/_posts/2018-03-22-JiraPS-v2.5.md b/_posts/2018-03-22-JiraPS-v2.5.md index 6543d48b..4ce3eafa 100644 --- a/_posts/2018-03-22-JiraPS-v2.5.md +++ b/_posts/2018-03-22-JiraPS-v2.5.md @@ -1,6 +1,6 @@ --- layout: article -permalink: /article/:categories/:title +permalink: /article/Announcement/JiraPS-v2.5 title: JiraPS v2.5 date: 2018-03-22 20:10:00 categories: Announcement @@ -32,22 +32,22 @@ Here you can see some how they changed: ## IMPROVEMENTS -- Harmonized code style (#162, [@lipkau][]) -- Harmonized verbose messages (#162, [@lipkau][]) -- Harmonized debug messages (#162, [@lipkau][]) -- Improved debug behavior (#162, [@lipkau][]) -- Update of VS code config to reflect code styling (#162, [@lipkau][]) -- Few improvements in test cases (#162, [@lipkau][]) -- Added parameter validation (#162, [@lipkau][]) -- Updated manifest (#162, [@lipkau][]) -- Minor preparations for pwsh support (#162, [@lipkau][]) -- Execute Tests against `./Release` (#162, [@lipkau][]) -- Removed unused `$ConfigFile` variable (#219, [@lipkau][]) -- `Invoke-JiraMethod` now sets the TLS to 1.2 before every call (#84, [@lipkau][]) -- Fixed _date_ and _timespan_ representation in _Body_ of `Add-JiraIssueWorklog` (#214, [@lipkau][]) -- Improved output of `Get-JiraProject` (#216, [@lipkau][]) +* Harmonized code style (#162, [@lipkau][]) +* Harmonized verbose messages (#162, [@lipkau][]) +* Harmonized debug messages (#162, [@lipkau][]) +* Improved debug behavior (#162, [@lipkau][]) +* Update of VS code config to reflect code styling (#162, [@lipkau][]) +* Few improvements in test cases (#162, [@lipkau][]) +* Added parameter validation (#162, [@lipkau][]) +* Updated manifest (#162, [@lipkau][]) +* Minor preparations for pwsh support (#162, [@lipkau][]) +* Execute Tests against `./Release` (#162, [@lipkau][]) +* Removed unused `$ConfigFile` variable (#219, [@lipkau][]) +* `Invoke-JiraMethod` now sets the TLS to 1.2 before every call (#84, [@lipkau][]) +* Fixed _date_ and _timespan_ representation in _Body_ of `Add-JiraIssueWorklog` (#214, [@lipkau][]) +* Improved output of `Get-JiraProject` (#216, [@lipkau][]) -_Full list of issues can be found in [Milestone v2.5](https://github.com/AtlassianPS/JiraPS/milestone/8)._ +Full list of issues can be found in [Milestone v2.5](https://github.com/AtlassianPS/JiraPS/milestone/8). [@alexsuslin]: https://github.com/alexsuslin diff --git a/_posts/2018-05-04-JiraPS-v2.6.md b/_posts/2018-05-04-JiraPS-v2.6.md index b52f5d9c..b2051d9d 100644 --- a/_posts/2018-05-04-JiraPS-v2.6.md +++ b/_posts/2018-05-04-JiraPS-v2.6.md @@ -1,6 +1,6 @@ --- layout: article -permalink: /article/:categories/:title +permalink: /article/Announcement/JiraPS-v2.6 title: JiraPS v2.6 date: 2018-05-04 22:30:00 categories: Announcement @@ -14,34 +14,34 @@ tags: We have just uploaded a new version of the **JiraPS** module to the [Gallery](https://www.powershellgallery.com/packages/JiraPS/2.6.0) and to [GitHub](https://github.com/AtlassianPS/JiraPS/tree/v2.6.0). -## Description +# Description This release brings new functionality, improvements and bug fixes that has been submitted by our contributors. -## CHANGELOG +# CHANGELOG -### FEATURES +## FEATURES -- Added `-Passthru` parameter to `Invoke-JiraIssueTransition` (#239, [@lipkau][]) -- Added `Get-JiraUser` functionality to find the current user (#231, [@lipkau][]) -- Added full support for PowerShell Core (v6) and Linux/MacOS support (#230, [@lipkau][]) -- Added JiraPS documentation on the homepage (#230, [@lipkau][]) +* Added `-Passthru` parameter to `Invoke-JiraIssueTransition` (#239, [@lipkau][]) +* Added `Get-JiraUser` functionality to find the current user (#231, [@lipkau][]) +* Added full support for PowerShell Core (v6) and Linux/MacOS support (#230, [@lipkau][]) +* Added JiraPS documentation on the homepage (#230, [@lipkau][]) -### IMPROVEMENTS +## IMPROVEMENTS -- Exposed `Invoke-JiraMethod` as a public function (#233, [@lipkau][]) -- Migrated to External Help (instead of Comment-Based Help) (#230, [@lipkau][]) +* Exposed `Invoke-JiraMethod` as a public function (#233, [@lipkau][]) +* Migrated to External Help (instead of Comment-Based Help) (#230, [@lipkau][]) ### BUG FIXES -- Index Into Null Object (#209, [@lipkau][]) -- Fix empty header (#206, [@lipkau][]) -- Bad Body (#224, [@lipkau][]) -- Add Labels to array (#226, [@lipkau][]) -- Fix removing labels with `Set-JiraIssueLabel -Remove` (#244, [lipkau][]) -- Fix adding of multiple labels at once with `Set-JiraIssueLabel -Add` (#244, [lipkau][]) +* Index Into Null Object (#209, [@lipkau][]) +* Fix empty header (#206, [@lipkau][]) +* Bad Body (#224, [@lipkau][]) +* Add Labels to array (#226, [@lipkau][]) +* Fix removing labels with `Set-JiraIssueLabel -Remove` (#244, [lipkau][]) +* Fix adding of multiple labels at once with `Set-JiraIssueLabel -Add` (#244, [lipkau][]) -_Full list of issues can be found in [Milestone v2.6](https://github.com/AtlassianPS/JiraPS/milestone/9)._ +Full list of issues can be found in [Milestone v2.6](https://github.com/AtlassianPS/JiraPS/milestone/9). [@alexsuslin]: https://github.com/alexsuslin diff --git a/_posts/2018-05-13-JiraPS-v2.7.md b/_posts/2018-05-13-JiraPS-v2.7.md index f4be5c1f..3a6ee675 100644 --- a/_posts/2018-05-13-JiraPS-v2.7.md +++ b/_posts/2018-05-13-JiraPS-v2.7.md @@ -1,6 +1,6 @@ --- layout: article -permalink: /article/:categories/:title +permalink: /article/Announcement/JiraPS-v2.7 title: JiraPS v2.7 date: 2018-05-13 20:00:00 categories: Announcement @@ -14,7 +14,7 @@ tags: We have just uploaded a new version of the **JiraPS** module to the [Gallery](https://www.powershellgallery.com/packages/JiraPS/2.7.0) and to [GitHub](https://github.com/AtlassianPS/JiraPS/tree/v2.7.0). -## Description +# Description This release brings new functionality, improvements and bug fixes that has been submitted by our contributors. @@ -24,33 +24,33 @@ Therefore this version was released earlier than anticipated to avoid those vers Further, this release brings with it a major refactoring of the build script. You can read all about it bellow. -## CHANGELOG +# CHANGELOG -### IMPROVEMENTS +## IMPROVEMENTS -- Improved build script (#252, [@lipkau][]) - - This project now uses `PSDepend` to declare and fulfill it's dependencies - - Tagging of the repository and publishing of a github is no longer part of AppVeyor's configuration. +* Improved build script (#252, [@lipkau][]) + * This project now uses `PSDepend` to declare and fulfill it's dependencies + * Tagging of the repository and publishing of a github is no longer part of AppVeyor's configuration. This was generating tags and releases before the CI could be sure it passes - it was doing so with the first job that succeeded. Not the build script makes sure only the last job of the build can perform these actions. - - Extracted detailed and long logics into functions and removed from the script - no it's a `build.psm1` module - - Removed conversion of `.md` files to html - and the dependency to _pandoc_ with it - - Clean-up -- Reduced the Pester output in CI build for PR (#257, [@lipkau][]) -- Evaluate the Headers returned by the API for better authentication handling (#256, [@lipkau][]) -- Writing and throwing of errors show better context (#199, [@lipkau][]) -- Improved validation of parameters in `Add-JiraGroupMember` (#250, [@WindowsAdmin92][]) -- Improved casting to `-Fields` by defining it's type as `[PSCustomObject]` (#255, [@lipkau][]) + * Extracted detailed and long logics into functions and removed from the script - no it's a `build.psm1` module + * Removed conversion of `.md` files to html - and the dependency to _pandoc_ with it + * Clean-up +* Reduced the Pester output in CI build for PR (#257, [@lipkau][]) +* Evaluate the Headers returned by the API for better authentication handling (#256, [@lipkau][]) +* Writing and throwing of errors show better context (#199, [@lipkau][]) +* Improved validation of parameters in `Add-JiraGroupMember` (#250, [@WindowsAdmin92][]) +* Improved casting to `-Fields` by defining it's type as `[PSCustomObject]` (#255, [@lipkau][]) -### BUG FIXES +## BUG FIXES -- Build script was not publishing to the PSGallery (#252, [@lipkau][]) -- Build script was publishing a new tag to repository even in case the build failed (#252, [@lipkau][]) -- Fixed CI icon in README (#245, [@lipkau][]) -- Fixed the adding multiple labels and the removal of those in `Set-JiraIssueLabel` (#244, [@lipkau][]) -- Allow `Get-JiraUser` to return more than 1 result (#246, [@lipkau][]) +* Build script was not publishing to the PSGallery (#252, [@lipkau][]) +* Build script was publishing a new tag to repository even in case the build failed (#252, [@lipkau][]) +* Fixed CI icon in README (#245, [@lipkau][]) +* Fixed the adding multiple labels and the removal of those in `Set-JiraIssueLabel` (#244, [@lipkau][]) +* Allow `Get-JiraUser` to return more than 1 result (#246, [@lipkau][]) -_Full list of issues can be found in [Milestone v2.7](https://github.com/AtlassianPS/JiraPS/milestone/10)._ +Full list of issues can be found in [Milestone v2.7](https://github.com/AtlassianPS/JiraPS/milestone/10). [@alexsuslin]: https://github.com/alexsuslin diff --git a/_posts/2018-06-28-JiraPS-v2.8.md b/_posts/2018-06-28-JiraPS-v2.8.md index c52df538..a9d83252 100644 --- a/_posts/2018-06-28-JiraPS-v2.8.md +++ b/_posts/2018-06-28-JiraPS-v2.8.md @@ -1,6 +1,6 @@ --- layout: article -permalink: /article/:categories/:title +permalink: /article/Announcement/JiraPS-v2.8 title: JiraPS v2.8 date: 2018-06-28 12:00:00 categories: Announcement @@ -14,80 +14,79 @@ tags: We have just uploaded a new version of the **JiraPS** module to the [Gallery](https://www.powershellgallery.com/packages/JiraPS/2.8.0) and to [GitHub](https://github.com/AtlassianPS/JiraPS/tree/v2.8.0). -## Description +# Description This release brings new functionality, improvements and bug fixes that has been submitted by our contributors. -## CHANGELOG +# CHANGELOG -### IMPROVEMENTS +## IMPROVEMENTS -- Added support for paginated response from API server by means of `-Paging` (#291, [@lipkau[]]) - - moved default values to `JiraPS.psm1` so that they could be changed from outside of the module +* Added support for paginated response from API server by means of `-Paging` (#291, [@lipkau[]]) + * moved default values to `JiraPS.psm1` so that they could be changed from outside of the module _in preparation for using `Configuration`_ - - added logic for `Command parameters` > `Global defaults` > `module defaults` - - huge improvement to Unit Tests for `Invoke-JiraMethod` - - improved how HTTP responses > 399 are handled (`Resolve-ErrorWebResponse`) - - added `.EXTERNALHELP` to all functions (needed for Powershell v3) - - updated all functions which can use paging so that they use the new `-Paging` functionality - - `Get-JiraGroupMember` - - `Get-JiraIssue -Query` - - `Get-JiraIssue -Filter` - - `Get-JiraIssueComment` - - `Get-JiraVersion` - - added `-Sort` to influence the sorting of the results - - added default `PageSize` - - marked parameters which duplicate `[SupportsPaging]` parameter as **deprecated**. These are: - - `Get-JiraGroupMember -StartIndex` - - `Get-JiraGroupMember -MaxResults` - - `Get-JiraIssue -StartIndex` - - `Get-JiraIssue -MaxResults` - - added `-Headers` logic to `New-JiraSession` -- Updated `Pester` to version `4.3.1` (#289, [@lipkau[]]) -- Added full set of functions to manage Filter Permissions (#289, [@lipkau[]]) - - introduced a new Object _`[JiraPS.FilterPermission]`_ - - added property `FilterPermissions` to _`[JiraPS.Filter]`_ which is the list of _`[JiraPS.FilterPermission]`_ - of this Filter - - introduced a new Object _`[JiraPS.ProjectRole]`_ - - added `Add-JiraFilterPermission` - - added `Get-JiraFilterPermission` - - added `Remove-JiraFilterPermission` -- Added `-Id` parameter to `Remove-JiraFilter` (#288, [@lipkau[]]) - - by adding `-Id` parameter (which accepts a value by pipeline), this function can now + * added logic for `Command parameters` > `Global defaults` > `module defaults` + * huge improvement to Unit Tests for `Invoke-JiraMethod` + * improved how HTTP responses > 399 are handled (`Resolve-ErrorWebResponse`) + * added `.EXTERNALHELP` to all functions (needed for Powershell v3) + * updated all functions which can use paging so that they use the new `-Paging` functionality + * `Get-JiraGroupMember` + * `Get-JiraIssue -Query` + * `Get-JiraIssue -Filter` + * `Get-JiraIssueComment` + * `Get-JiraVersion` + * added `-Sort` to influence the sorting of the results + * added default `PageSize` + * marked parameters which duplicate `[SupportsPaging]` parameter as **deprecated**. These are: + * `Get-JiraGroupMember -StartIndex` + * `Get-JiraGroupMember -MaxResults` + * `Get-JiraIssue -StartIndex` + * `Get-JiraIssue -MaxResults` + * added `-Headers` logic to `New-JiraSession` +* Updated `Pester` to version `4.3.1` (#289, [@lipkau[]]) +* Added full set of functions to manage Filter Permissions (#289, [@lipkau[]]) + * introduced a new Object _`[JiraPS.FilterPermission]`_ + * added property `FilterPermissions` to _`[JiraPS.Filter]`_ which is the list of _`[JiraPS.FilterPermission]`_ of this Filter + * introduced a new Object _`[JiraPS.ProjectRole]`_ + * added `Add-JiraFilterPermission` + * added `Get-JiraFilterPermission` + * added `Remove-JiraFilterPermission` +* Added `-Id` parameter to `Remove-JiraFilter` (#288, [@lipkau[]]) + * by adding `-Id` parameter (which accepts a value by pipeline), this function can now be used in scenarios like `Get-Content "listOfFilter.txt | Remover-JiraFilter` -- Changed logic of `Get-JiraUser` to return multiple results for a search (#272, [@lipkau[]]) - - `Get-JiraUser` was hardcoded to return only one result, while the API can return multiple results - - added parameter (`-MaxResults`, `-Skip`) to influence the results of the API - - _API has a limitation of 1000 items in response_ -- Added posts for homepage to the module's repository (#268, [@lipkau[]]) - - by maintaining the posts of the homepage in the module's repository, the new version of the +* Changed logic of `Get-JiraUser` to return multiple results for a search (#272, [@lipkau[]]) + * `Get-JiraUser` was hard-coded to return only one result, while the API can return multiple results + * added parameter (`-MaxResults`, `-Skip`) to influence the results of the API + * _API has a limitation of 1000 items in response_ +* Added posts for homepage to the module's repository (#268, [@lipkau[]]) + * by maintaining the posts of the homepage in the module's repository, the new version of the module can be deployed without manual changes to the homepage (thanks to #259 mentioned bellow) -- Improved handling of _Credentials_ (#271, [@lipkau[]]) - - added an empty _`[Credential]`_ object as default value - - `-Credentail "Username"` now uses the _`[String]`_ as value for the Username in the Credentials dialog - - this change is important for Powershell v3 compatibility -- Added missing interactions with _Filters_ (#266, [@lipkau[]]) - - added `-Favorite` to `Get-JiraFilter`, which lists all Filters marked as favorite by the user - - added `New-JiraFilter` - - added `Remove-JiraFilter` - - added `Set-JiraFilter` -- Added `Remove-JiraIssue` (#265, [@hmmwhatsthisdo[]]) -- Improved Build script (to deploy changes to the homepage) (#259, [@lipkau[]]) +* Improved handling of _Credentials_ (#271, [@lipkau[]]) + * added an empty _`[Credential]`_ object as default value + * `-Credential "Username"` now uses the _`[String]`_ as value for the Username in the Credentials dialog + * this change is important for Powershell v3 compatibility +* Added missing interactions with _Filters_ (#266, [@lipkau[]]) + * added `-Favorite` to `Get-JiraFilter`, which lists all Filters marked as favorite by the user + * added `New-JiraFilter` + * added `Remove-JiraFilter` + * added `Set-JiraFilter` +* Added `Remove-JiraIssue` (#265, [@hmmwhatsthisdo[]]) +* Improved Build script (to deploy changes to the homepage) (#259, [@lipkau[]]) -### BUG FIXES +## BUG FIXES -- Reverted `Add-JiraIssueAttachament` as JiraPS v2.7 broke it (#287, [@lipkau[]]) - - `JiraPS v2.7` tried to move the logic for generating the `multipart/form-data` to `Invoke-WebRequest` - - this is still desired, but as it broke the functionality of `Add-JiraIssueAttachament`, +* Reverted `Add-JiraIssueAttachment` as JiraPS v2.7 broke it (#287, [@lipkau[]]) + * `JiraPS v2.7` tried to move the logic for generating the `multipart/form-data` to `Invoke-WebRequest` + * this is still desired, but as it broke the functionality of `Add-JiraIssueAttachment`, this was rolled-back - - shall be fixed/re-implemented with [#284](https://github.com/AtlassianPS/JiraPS/issues/284) -- Fixed resolving of Remote Link (#286, [@lipkau[]]) - - function was using the wrong private function for converting the response to custom object -- Improved error handling for ErrorDetails and non-JSON/HTML responses (#277, [@hmmwhatsthisdo[]]) -- Fully support Powershell v3 (#273, [@lipkau[]]) -- Fixed parameter used in documentation but not in code (#263, [@lipkau[]]) - - added alias `-Issue` to `Get-JiraIssue -Key` as the documentation used it - - updated documentation to use the `-Key` parameter + * shall be fixed/re-implemented with [#284](https://github.com/AtlassianPS/JiraPS/issues/284) +* Fixed resolving of Remote Link (#286, [@lipkau[]]) + * function was using the wrong private function for converting the response to custom object +* Improved error handling for ErrorDetails and non-JSON/HTML responses (#277, [@hmmwhatsthisdo[]]) +* Fully support Powershell v3 (#273, [@lipkau[]]) +* Fixed parameter used in documentation but not in code (#263, [@lipkau[]]) + * added alias `-Issue` to `Get-JiraIssue -Key` as the documentation used it + * updated documentation to use the `-Key` parameter _Full list of issues can be found in [Milestone v2.8](https://github.com/AtlassianPS/JiraPS/milestone/11)._ diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 46d23e84..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,50 +0,0 @@ -environment: - PSGalleryAPIKey: - secure: Ezd2JjB6rbNZOiJmcek2bZSSdXB34fjoC6JXdXcICf6KZGoBOIRZAG9KfHAYiMa7 - # Must be updated to use contact@AtlassianPS.net user - access_token: - secure: PX1R0Ds6r3TTm+wxVbx8MRAgjCRV/juO3cYSEz1MedB/OXvZ3YkqpQGE+X47bcFT - matrix: - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - # waiting on https://github.com/RamblingCookieMonster/BuildHelpers/pull/60 - # - APPVEYOR_BUILD_WORKER_IMAGE: WMF 4 - - APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu - PowershellVersion: "6.0.0" - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - PowershellVersion: "6.0.0" - -matrix: - fast_finish: true - -version: 2.8.{build} - -# Don't rebuild when I tag a release on GitHub -skip_tags: true - -# Ignore testing a commit if only the readme changed -# Or if I include "skip-tests" in the commit message -skip_commits: - message: /skip\-tests/ - -# PRs, by definition, don't change anything and therefore should not increment the version -# To be fair, this is not important, and is really just AppVeyor enabling my pedantry -pull_requests: - do_not_increment_build_number: true - -init: - - ps: | - if (-not ($env:PowershellVersion)) {$env:PowershellVersion = "5.1"} - if (([version]$env:PowershellVersion).Major -ge 6) {$env:posh = "pwsh"} else {$env:posh = "powershell"} - Add-Content (Join-Path $Home ".git-credentials") "https://$($env:access_token):x-oauth-basic@github.com`n" - - git config --global credential.helper "store --file ~/.git-credentials" - - git config --global user.email "support@atlassianps.org" - - git config --global user.name "AtlassianPS automation" - -install: - - ps: '& $env:posh -File "./Tools/setup.ps1"' - -build_script: - - ps: '& $env:posh -Command "Invoke-Build"' - -# on_failure: - # - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 00000000..56c1bff7 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,198 @@ + +resources: +- repo: self + clean: true + +trigger: + branches: + include: + - master + - "*" + exclude: + - refs/tag/* + +phases: +- phase: Phase_1 + displayName: Build Module + + condition: succeeded() + queue: + name: Hosted VS2017 + + steps: + - powershell: | + . ./Tools/setup.ps1 + Invoke-Build -Task ShowInfo + displayName: Setup + + - powershell: 'Invoke-Build -Task Clean, Build' + displayName: Build + + - task: PublishBuildArtifacts@1 + displayName: 'Publish Artifact: Built Module' + inputs: + PathtoPublish: Release + ArtifactName: Release + + +- phase: Phase_2 + displayName: Test Module on Windows (PSv5) + + dependsOn: Phase_1 + condition: succeeded() + queue: + name: Hosted VS2017 + + steps: + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifacts' + inputs: + artifactName: Release + downloadPath: '$(Build.SourcesDirectory)' + + - powershell: | + . ./Tools/setup.ps1 + Invoke-Build -Task ShowInfo + displayName: Setup + + - powershell: 'Invoke-Build -Task Test' + displayName: Test + + - task: PublishTestResults@2 + displayName: 'Publish Test Results **/Test*.xml' + inputs: + testRunner: NUnit + testResultsFiles: '**/Test*.xml' + condition: succeededOrFailed() + + +- phase: Phase_3 + displayName: Test Module on Ubuntu + + dependsOn: Phase_1 + condition: succeeded() + queue: + name: Hosted Ubuntu 1604 + + steps: + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifacts' + inputs: + artifactName: Release + downloadPath: '$(Build.SourcesDirectory)' + + + - powershell: | + . ./Tools/setup.ps1 + Invoke-Build -Task ShowInfo + displayName: Setup + + - powershell: 'Invoke-Build -Task Test' + displayName: Test + + - task: PublishTestResults@2 + displayName: 'Publish Test Results **/Test*.xml' + inputs: + testRunner: NUnit + testResultsFiles: '**/Test*.xml' + condition: succeededOrFailed() + + +- phase: Phase_4 + displayName: Test Module on macOS + + dependsOn: Phase_1 + condition: succeeded() + queue: + name: Hosted macOS + + steps: + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifacts' + inputs: + artifactName: Release + downloadPath: '$(Build.SourcesDirectory)' + + - powershell: | + . ./Tools/setup.ps1 + Invoke-Build -Task ShowInfo + displayName: Setup + + - powershell: 'Invoke-Build -Task Test' + displayName: Test + + - task: PublishTestResults@2 + displayName: 'Publish Test Results **/Test*.xml' + inputs: + testRunner: NUnit + testResultsFiles: '**/Test*.xml' + condition: succeededOrFailed() + + +# Waiting for the agent to support pwsh: +# https://github.com/Microsoft/azure-pipelines-image-generation/issues/232 +# - phase: Phase_5 +# displayName: Test Module on Windows (PSv6) + +# dependsOn: Phase_1 +# condition: succeeded() +# queue: +# name: Hosted VS2017 + +# steps: +# - task: DownloadBuildArtifacts@0 +# displayName: 'Download Build Artifacts' +# inputs: +# artifactName: Release +# downloadPath: '$(Build.SourcesDirectory)' + +# - powershell: | +# . ./Tools/setup.ps1 +# Invoke-Build -Task ShowInfo +# displayName: Setup +# pwsh: true + +# - powershell: 'Invoke-Build -Task Test' +# displayName: Test +# pwsh: true + +# - task: PublishTestResults@2 +# displayName: 'Publish Test Results **/Test-*.xml' +# inputs: +# testRunner: NUnit +# testResultsFiles: '**/Test*.xml' +# condition: succeededOrFailed() + +- phase: Phase_6 + displayName: Test Module against Cloud Server + + dependsOn: Phase_1 + condition: succeeded() + queue: + name: Hosted VS2017 + + steps: + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifacts' + inputs: + artifactName: Release + downloadPath: '$(Build.SourcesDirectory)' + + - powershell: | + . ./Tools/setup.ps1 + Invoke-Build -Task ShowInfo + displayName: Setup + + - powershell: 'Invoke-Build -Task Test -Tag "Integration" -ExcludeTag ""' + env: + JiraURI: JiraURI + JiraUser: JiraUser + JiraPass: JiraPass + displayName: Test + + - task: PublishTestResults@2 + displayName: 'Publish Test Results **/Test*.xml' + inputs: + testRunner: NUnit + testResultsFiles: '**/Test*.xml' + condition: succeededOrFailed()