Skip to content

Commit

Permalink
Merge pull request #511 from lipkau/fix/testing
Browse files Browse the repository at this point in the history
Fix testing
  • Loading branch information
lipkau authored Jun 13, 2024
2 parents dd19e22 + df30da3 commit 6b00950
Show file tree
Hide file tree
Showing 31 changed files with 91 additions and 80 deletions.
2 changes: 1 addition & 1 deletion JiraPS/JiraPS.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Dependencies
#region Dependencies
# Load the ConfluencePS namespace from C#
# if (!("" -as [Type])) {
# Add-Type -Path (Join-Path $PSScriptRoot JiraPS.Types.cs) -ReferencedAssemblies Microsoft.CSharp, Microsoft.PowerShell.Commands.Utility, System.Management.Automation
Expand Down
1 change: 1 addition & 0 deletions JiraPS/Private/ConvertFrom-Json.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ if ($PSVersionTable.PSVersion.Major -lt 6) {
ConvertFrom-Json implementation does not allow for overriding JSON maxlength.
The default limit is easy to exceed with large issue lists.
#>
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSAvoidOverwritingBuiltInCmdlets', '')]
[CmdletBinding()]
param(
[Parameter( Mandatory, ValueFromPipeline )]
Expand Down
6 changes: 4 additions & 2 deletions JiraPS/Private/Invoke-WebRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function Invoke-WebRequest {
Cmdlet
#>
[CmdletBinding(HelpUri = 'https://go.microsoft.com/fwlink/?LinkID=217035')]
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSAvoidOverwritingBuiltInCmdlets', '')] # TODO: fix this
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
"PSAvoidUsingConvertToSecureStringWithPlainText",
"",
Expand Down Expand Up @@ -129,7 +130,7 @@ Content-Type: application/octet-stream
$PSBoundParameters['OutBuffer'] = 1
}
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Utility\Invoke-WebRequest', [System.Management.Automation.CommandTypes]::Cmdlet)
$scriptCmd = {& $wrappedCmd @PSBoundParameters }
$scriptCmd = { & $wrappedCmd @PSBoundParameters }
$steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)
$steppablePipeline.Begin($PSCmdlet)
}
Expand Down Expand Up @@ -169,6 +170,7 @@ if ($PSVersionTable.PSVersion.Major -ge 6) {
.ForwardHelpCategory
Cmdlet
#>
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSAvoidOverwritingBuiltInCmdlets', '')] # TODO: fix this
[CmdletBinding(DefaultParameterSetName = 'StandardMethod', HelpUri = 'https://go.microsoft.com/fwlink/?LinkID=217035')]
param(
[switch]
Expand Down Expand Up @@ -316,7 +318,7 @@ if ($PSVersionTable.PSVersion.Major -ge 6) {
$PSBoundParameters['OutBuffer'] = 1
}
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Utility\Invoke-WebRequest', [System.Management.Automation.CommandTypes]::Cmdlet)
$scriptCmd = {& $wrappedCmd @PSBoundParameters }
$scriptCmd = { & $wrappedCmd @PSBoundParameters }
$steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)
$steppablePipeline.Begin($PSCmdlet)
}
Expand Down
4 changes: 2 additions & 2 deletions JiraPS/Private/Resolve-JiraError.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Resolve-JiraError {
function Resolve-JiraError {
[CmdletBinding()]
param(
[Parameter( ValueFromPipeline )]
Expand Down Expand Up @@ -44,7 +44,7 @@
}
}
elseif ($i.errors) {
$keys = (Get-Member -InputObject $i.errors | Where-Object -FilterScript {$_.MemberType -eq 'NoteProperty'}).Name
$keys = (Get-Member -InputObject $i.errors | Where-Object -FilterScript { $_.MemberType -eq 'NoteProperty' }).Name
foreach ($k in $keys) {
if ($WriteError) {
$exception = ([System.ArgumentException]"Server responded with Error")
Expand Down
30 changes: 16 additions & 14 deletions JiraPS/Private/Resolve-JiraIssueObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,21 @@ function Resolve-JiraIssueObject {
$Credential = [System.Management.Automation.PSCredential]::Empty
)

# As we are not able to use proper type casting in the parameters, this is a workaround
# to extract the data from a JiraPS.Issue object
# This shall be removed once we have custom classes for the module
if ("JiraPS.Issue" -in $InputObject.PSObject.TypeNames -and $InputObject.RestURL) {
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Using `$InputObject as object"
return $InputObject
}
elseif ("JiraPS.Issue" -in $InputObject.PSObject.TypeNames -and $InputObject.Key) {
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Resolve Issue to object"
return (Get-JiraIssue -Key $InputObject.Key -Credential $Credential -ErrorAction Stop)
}
else {
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Resolve Issue to object"
return (Get-JiraIssue -Key $InputObject.ToString() -Credential $Credential -ErrorAction Stop)
process {
# As we are not able to use proper type casting in the parameters, this is a workaround
# to extract the data from a JiraPS.Issue object
# This shall be removed once we have custom classes for the module
if ("JiraPS.Issue" -in $InputObject.PSObject.TypeNames -and $InputObject.RestURL) {
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Using `$InputObject as object"
return $InputObject
}
elseif ("JiraPS.Issue" -in $InputObject.PSObject.TypeNames -and $InputObject.Key) {
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Resolve Issue to object"
return (Get-JiraIssue -Key $InputObject.Key -Credential $Credential -ErrorAction Stop)
}
else {
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Resolve Issue to object"
return (Get-JiraIssue -Key $InputObject.ToString() -Credential $Credential -ErrorAction Stop)
}
}
}
22 changes: 12 additions & 10 deletions JiraPS/Private/Resolve-JiraUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ function Resolve-JiraUser {
$Credential = [System.Management.Automation.PSCredential]::Empty
)

# As we are not able to use proper type casting in the parameters, this is a workaround
# to extract the data from a JiraPS.Issue object
# This shall be removed once we have custom classes for the module
if ("JiraPS.User" -in $InputObject.PSObject.TypeNames) {
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Using `$InputObject as object"
return $InputObject
}
else {
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Resolve User to object"
return (Get-JiraUser -UserName $InputObject -Exact:$Exact -Credential $Credential -ErrorAction Stop)
process {
# As we are not able to use proper type casting in the parameters, this is a workaround
# to extract the data from a JiraPS.Issue object
# This shall be removed once we have custom classes for the module
if ("JiraPS.User" -in $InputObject.PSObject.TypeNames) {
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Using `$InputObject as object"
return $InputObject
}
else {
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Resolve User to object"
return (Get-JiraUser -UserName $InputObject -Exact:$Exact -Credential $Credential -ErrorAction Stop)
}
}
}
16 changes: 7 additions & 9 deletions JiraPS/Private/Set-TlsLevel.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ function Set-TlsLevel {
)

begin {
switch ($PSCmdlet.ParameterSetName) {
"Set" {
$Script:OriginalTlsSettings = [Net.ServicePointManager]::SecurityProtocol
if ($Tls12) {
$Script:OriginalTlsSettings = [Net.ServicePointManager]::SecurityProtocol

[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
}
"Revert" {
if ($Script:OriginalTlsSettings) {
[Net.ServicePointManager]::SecurityProtocol = $Script:OriginalTlsSettings
}
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
}
if ($Revert) {
if ($Script:OriginalTlsSettings) {
[Net.ServicePointManager]::SecurityProtocol = $Script:OriginalTlsSettings
}
}
}
Expand Down
1 change: 1 addition & 0 deletions JiraPS/Private/ThrowError.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function ThrowError {
Thanks to Jaykul:
https://github.com/PoshCode/Configuration/blob/master/Source/Metadata.psm1
#>
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSAvoidOverwritingBuiltInCmdlets', '')] # TODO: fix this
param
(
[Parameter()]
Expand Down
2 changes: 1 addition & 1 deletion JiraPS/Public/Add-JiraFilterPermission.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Add-JiraFilterPermission {
function Add-JiraFilterPermission {
# .ExternalHelp ..\JiraPS-help.xml
[CmdletBinding( SupportsShouldProcess, DefaultParameterSetName = 'ByInputObject' )]
# [OutputType( [JiraPS.FilterPermission] )]
Expand Down
2 changes: 1 addition & 1 deletion JiraPS/Public/Add-JiraIssueWatcher.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Add-JiraIssueWatcher {
function Add-JiraIssueWatcher {
# .ExternalHelp ..\JiraPS-help.xml
[CmdletBinding( SupportsShouldProcess )]
param(
Expand Down
4 changes: 2 additions & 2 deletions JiraPS/Public/Get-JiraField.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-JiraField {
function Get-JiraField {
# .ExternalHelp ..\JiraPS-help.xml
[CmdletBinding( DefaultParameterSetName = '_All' )]
param(
Expand Down Expand Up @@ -43,7 +43,7 @@

$allFields = Get-JiraField -Credential $Credential

Write-Output ($allFields | Where-Object -FilterScript {($_.Id -eq $_field) -or ($_.Name -like $_field)})
Write-Output ($allFields | Where-Object -FilterScript { ($_.Id -eq $_field) -or ($_.Name -like $_field) })
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion JiraPS/Public/Get-JiraFilter.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-JiraFilter {
function Get-JiraFilter {
# .ExternalHelp ..\JiraPS-help.xml
[CmdletBinding(DefaultParameterSetName = 'ByFilterID')]
param(
Expand Down
1 change: 1 addition & 0 deletions JiraPS/Public/Get-JiraIssueCreateMetadata.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function Get-JiraIssueCreateMetadata {
# .ExternalHelp ..\JiraPS-help.xml
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseSingularNouns', '')]
[CmdletBinding()]
param(
[Parameter( Mandatory )]
Expand Down
1 change: 1 addition & 0 deletions JiraPS/Public/Get-JiraIssueEditMetadata.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function Get-JiraIssueEditMetadata {
# .ExternalHelp ..\JiraPS-help.xml
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseSingularNouns', '')]
[CmdletBinding()]
param(
[Parameter( Mandatory )]
Expand Down
6 changes: 3 additions & 3 deletions JiraPS/Public/Get-JiraIssueType.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-JiraIssueType {
function Get-JiraIssueType {
# .ExternalHelp ..\JiraPS-help.xml
[CmdletBinding( DefaultParameterSetName = '_All' )]
param(
Expand Down Expand Up @@ -43,8 +43,8 @@

$allIssueTypes = Get-JiraIssueType -Credential $Credential

Write-Output ($allIssueTypes | Where-Object -FilterScript {$_.Id -eq $_issueType})
Write-Output ($allIssueTypes | Where-Object -FilterScript {$_.Name -like $_issueType})
Write-Output ($allIssueTypes | Where-Object -FilterScript { $_.Id -eq $_issueType })
Write-Output ($allIssueTypes | Where-Object -FilterScript { $_.Name -like $_issueType })
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion JiraPS/Public/Get-JiraIssueWatcher.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-JiraIssueWatcher {
function Get-JiraIssueWatcher {
# .ExternalHelp ..\JiraPS-help.xml
[CmdletBinding()]
param(
Expand Down
4 changes: 2 additions & 2 deletions JiraPS/Public/Get-JiraVersion.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-JiraVersion {
function Get-JiraVersion {
# .ExternalHelp ..\JiraPS-help.xml
[CmdletBinding( SupportsPaging, DefaultParameterSetName = 'byId' )]
param(
Expand Down Expand Up @@ -109,7 +109,7 @@
$result | Where-Object {
$__ = $_.Name
Write-DebugMessage ($__ | Out-String)
$Name | Foreach-Object {
$Name | ForEach-Object {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Matching $_ against $($__)"
$__ -like $_
}
Expand Down
5 changes: 3 additions & 2 deletions JiraPS/Public/Move-JiraVersion.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Move-JiraVersion {
function Move-JiraVersion {
# .ExternalHelp ..\JiraPS-help.xml
[CmdletBinding( DefaultParameterSetName = 'ByAfter' )]
param(
Expand Down Expand Up @@ -95,7 +95,8 @@

if ($Version.Id) {
$versionId = $Version.Id
} else {
}
else {
$versionId = $Version
}

Expand Down
2 changes: 1 addition & 1 deletion JiraPS/Public/New-JiraGroup.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function New-JiraGroup {
function New-JiraGroup {
# .ExternalHelp ..\JiraPS-help.xml
[CmdletBinding( SupportsShouldProcess )]
param(
Expand Down
12 changes: 6 additions & 6 deletions JiraPS/Public/New-JiraVersion.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function New-JiraVersion {
function New-JiraVersion {
# .ExternalHelp ..\JiraPS-help.xml
[CmdletBinding( SupportsShouldProcess, DefaultParameterSetName = 'byObject' )]
param(
Expand Down Expand Up @@ -35,18 +35,18 @@
[ValidateNotNullOrEmpty()]
[ValidateScript(
{
$Input = $_
$_input = $_

switch ($true) {
{"JiraPS.Project" -in $Input.PSObject.TypeNames} { return $true }
{$Input -is [String]} { return $true}
{ "JiraPS.Project" -in $_input.PSObject.TypeNames } { return $true }
{ $_input -is [String] } { return $true }
Default {
$exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting]
$errorId = 'ParameterType.NotJiraProject'
$errorCategory = 'InvalidArgument'
$errorTarget = $Input
$errorTarget = $_input
$errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget
$errorItem.ErrorDetails = "Wrong object type provided for Project. Expected [JiraPS.Project] or [String], but was $($Input.GetType().Name)"
$errorItem.ErrorDetails = "Wrong object type provided for Project. Expected [JiraPS.Project] or [String], but was $($_input.GetType().Name)"
$PSCmdlet.ThrowTerminatingError($errorItem)
<#
#ToDo:CustomClass
Expand Down
2 changes: 1 addition & 1 deletion JiraPS/Public/Remove-JiraFilterPermission.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Remove-JiraFilterPermission {
function Remove-JiraFilterPermission {
# .ExternalHelp ..\JiraPS-help.xml
[CmdletBinding( SupportsShouldProcess, DefaultParameterSetName = 'ByFilterId' )]
param(
Expand Down
2 changes: 1 addition & 1 deletion JiraPS/Public/Remove-JiraGroup.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Remove-JiraGroup {
function Remove-JiraGroup {
# .ExternalHelp ..\JiraPS-help.xml
[CmdletBinding( SupportsShouldProcess, ConfirmImpact = 'High' )]
param(
Expand Down
12 changes: 6 additions & 6 deletions JiraPS/Public/Remove-JiraIssueLink.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ function Remove-JiraIssueLink {
[ValidateNotNullOrEmpty()]
[ValidateScript(
{
$Input = $_
$objectProperties = $Input | Get-Member -MemberType *Property
$_input = $_
$objectProperties = $_input | Get-Member -MemberType *Property
switch ($true) {
{("JiraPS.Issue" -in $Input.PSObject.TypeNames) -and ("issueLinks" -in $objectProperties.Name)} { return $true }
{("JiraPS.IssueLink" -in $Input.PSObject.TypeNames) -and ("Id" -in $objectProperties.Name)} { return $true }
{ ("JiraPS.Issue" -in $_input.PSObject.TypeNames) -and ("issueLinks" -in $objectProperties.Name) } { return $true }
{ ("JiraPS.IssueLink" -in $_input.PSObject.TypeNames) -and ("Id" -in $objectProperties.Name) } { return $true }
default {
$exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting]
$errorId = 'ParameterType.NotJiraIssue'
$errorCategory = 'InvalidArgument'
$errorTarget = $Input
$errorTarget = $_input
$errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget
$errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue], [JiraPS.IssueLink] or [String], but was $($Input.GetType().Name)"
$errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue], [JiraPS.IssueLink] or [String], but was $($_input.GetType().Name)"
$PSCmdlet.ThrowTerminatingError($errorItem)
<#
#ToDo:CustomClass
Expand Down
2 changes: 1 addition & 1 deletion JiraPS/Public/Remove-JiraIssueWatcher.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Remove-JiraIssueWatcher {
function Remove-JiraIssueWatcher {
# .ExternalHelp ..\JiraPS-help.xml
[CmdletBinding( SupportsShouldProcess )]
param(
Expand Down
2 changes: 1 addition & 1 deletion JiraPS/Public/Remove-JiraVersion.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Remove-JiraVersion {
function Remove-JiraVersion {
# .ExternalHelp ..\JiraPS-help.xml
[CmdletBinding( ConfirmImpact = 'High', SupportsShouldProcess )]
param(
Expand Down
4 changes: 2 additions & 2 deletions JiraPS/Public/Set-JiraIssueLabel.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Set-JiraIssueLabel {
function Set-JiraIssueLabel {
# .ExternalHelp ..\JiraPS-help.xml
[CmdletBinding( SupportsShouldProcess, DefaultParameterSetName = 'ReplaceLabels' )]
param(
Expand Down Expand Up @@ -69,7 +69,7 @@
# Find the proper object for the Issue
$issueObj = Resolve-JiraIssueObject -InputObject $_issue -Credential $Credential

$labels = [System.Collections.ArrayList]@($issueObj.labels | Where-Object {$_})
$labels = [System.Collections.ArrayList]@($issueObj.labels | Where-Object { $_ })

# As of JIRA 6.4, the Add and Remove verbs in the REST API for
# updating issues do not support arrays of parameters - you
Expand Down
2 changes: 1 addition & 1 deletion JiraPS/Public/Set-JiraVersion.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Set-JiraVersion {
function Set-JiraVersion {
# .ExternalHelp ..\JiraPS-help.xml
[CmdletBinding( SupportsShouldProcess )]
param(
Expand Down
8 changes: 4 additions & 4 deletions Tests/Build.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#requires -modules BuildHelpers
#requires -modules Configuration
#requires -modules Metadata
#requires -modules Pester

Describe "Validation of build environment" -Tag Unit {
Expand Down Expand Up @@ -44,7 +44,7 @@ Describe "Validation of build environment" -Tag Unit {
Context "CHANGELOG" {

foreach ($line in (Get-Content $changelogFile)) {
if ($line -match "(?:##|\<h2.*?\>)\s*\[(?<Version>(\d+\.?){1,2})\]") {
if ($line -match "(?:##|\<h2.*?\>)\s*\[(?<Version>(\d+\.?){1,2})(\-(?<Prerelease>(?:alpha|beta|rc)\d*))?\]") {
$changelogVersion = $matches.Version
break
}
Expand All @@ -55,12 +55,12 @@ Describe "Validation of build environment" -Tag Unit {
}

It "has a valid version in the changelog" {
$changelogVersion | Should -Not -BeNullOrEmpty
$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*"
Metadata\Get-Metadata -Path $env:BHManifestToTest -PropertyName ModuleVersion | Should -BeLike "$changelogVersion*"
}
}
}
Loading

0 comments on commit 6b00950

Please sign in to comment.