From 2e8a1fb39a21f80b5aa6fe94e0df46fbd4eb4092 Mon Sep 17 00:00:00 2001 From: RoderickB <13252390+webtonize@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:33:39 +0100 Subject: [PATCH] Fix Add -PassThru Parameter to Export Cmdlets #79 (#92) * Fix Add -PassThru Parameter to Export Cmdlets #79 --- .../Functions/Common.ps1 | 23 +++++- .../Functions/DevOps.Groups.ps1 | 16 +++- .../Functions/DevOps.Pipelines.Core.ps1 | 54 +++++++++---- .../DevOps.Pipelines.Environments.ps1 | 23 ++++-- .../Functions/DevOps.Pipelines.Releases.ps1 | 21 +++-- .../Functions/DevOps.Pipelines.Settings.ps1 | 16 +++- .../Functions/DevOps.Repos.ps1 | 22 ++++-- .../Functions/DevOps.RetentionSettings.ps1 | 17 +++- .../Functions/DevOps.ServiceConnections.ps1 | 18 ++++- .../Functions/DevOps.Tasks.VariableGroups.ps1 | 21 +++-- .../PSRule.Rules.AzureDevOps.psm1 | 79 +++++++++++++------ tests/Common.Tests.ps1 | 33 ++++++++ tests/DevOps.Groups.Tests.ps1 | 32 ++++++++ tests/DevOps.Pipelines.Core.Tests.ps1 | 37 +++++++++ tests/DevOps.Pipelines.Environments.Tests.ps1 | 37 +++++++++ tests/DevOps.Pipelines.Releases.Tests.ps1 | 39 +++++++++ tests/DevOps.Pipelines.Settings.Tests.ps1 | 32 ++++++++ tests/DevOps.Repos.Tests.ps1 | 33 ++++++++ tests/DevOps.RetentionSettings.Tests.ps1 | 40 ++++++++++ tests/DevOps.ServiceConnections.Tests.ps1 | 35 ++++++++ tests/DevOps.Tasks.VariableGroups.Tests.ps1 | 35 ++++++++ 21 files changed, 588 insertions(+), 75 deletions(-) diff --git a/src/PSRule.Rules.AzureDevOps/Functions/Common.ps1 b/src/PSRule.Rules.AzureDevOps/Functions/Common.ps1 index 6c83438..eba8efe 100644 --- a/src/PSRule.Rules.AzureDevOps/Functions/Common.ps1 +++ b/src/PSRule.Rules.AzureDevOps/Functions/Common.ps1 @@ -157,6 +157,15 @@ function Get-AzDevOpsProject { .DESCRIPTION Export the Azure DevOps Project using Azure DevOps Rest API to a JSON file + .PARAMETER Project + Project name for Azure DevOps + + .PARAMETER OutputPath + Output path for JSON files + + .PARAMETER PassThru + Return the exported project as objects to the pipeline instead of writing to a file + .EXAMPLE Export-AzDevOpsProject -Project $Project -OutputPath $OutputPath @@ -170,9 +179,12 @@ function Export-AzDevOpsProject { [Parameter(Mandatory=$true)] [string] $Project, - [Parameter(Mandatory=$true)] + [Parameter(ParameterSetName = 'JsonFile')] [string] - $OutputPath + $OutputPath, + [Parameter(ParameterSetName = 'PassThru')] + [switch] + $PassThru ) if ($null -eq $script:connection) { throw "Not connected to Azure DevOps. Run Connect-AzDevOps first" @@ -188,6 +200,11 @@ function Export-AzDevOpsProject { catch { throw "Failed to get project $Project from Azure DevOps" } - $response | ConvertTo-Json | Out-File -FilePath "$OutputPath/$Project.prj.ado.json" + if($PassThru) { + Write-Output $response + } else { + Write-Verbose "Exporting project $Project as file $Project.prj.ado.json" + $response | ConvertTo-Json | Out-File -FilePath "$OutputPath/$Project.prj.ado.json" + } } # End of Function Export-AzDevOpsProject diff --git a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Groups.ps1 b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Groups.ps1 index e3bb497..3cea138 100644 --- a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Groups.ps1 +++ b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Groups.ps1 @@ -122,6 +122,9 @@ Export-ModuleMember -Function Get-AzDevOpsGroupDetails .PARAMETER OutputPath The folder path to the JSON file to export to + .PARAMETER PassThru + Return the group details as an object instead of exporting to a file + .EXAMPLE Export-AzDevOpsGroups -Project 'MyProject' -OutputPath 'C:\Temp\' @@ -134,9 +137,12 @@ Function Export-AzDevOpsGroups { [Parameter(Mandatory=$true)] [string] $Project, - [Parameter(Mandatory=$true)] + [Parameter(ParameterSetName='JsonFile')] [string] - $OutputPath + $OutputPath, + [Parameter(ParameterSetName='PassThru')] + [switch] + $PassThru ) if($null -eq $script:connection) { throw 'Not connected to Azure DevOps. Run Connect-AzDevOps first.' @@ -157,7 +163,11 @@ Function Export-AzDevOpsGroups { $groupDetails += $thisGroup } - $groupDetails | ConvertTo-Json -Depth 100 | Out-File -FilePath "$OutputPath\groups.ado.json" + if($PassThru) { + Write-Output $groupDetails + } else { + $groupDetails | ConvertTo-Json -Depth 100 | Out-File -FilePath "$OutputPath\groups.ado.json" + } } Export-ModuleMember -Function Export-AzDevOpsGroups # End of Function Export-AzDevOpsGroups diff --git a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Core.ps1 b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Core.ps1 index 7cab6cd..9bd5513 100644 --- a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Core.ps1 +++ b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Core.ps1 @@ -203,6 +203,9 @@ Export-ModuleMember -Function Get-AzDevOpsPipelineYaml .PARAMETER OutputPath Output path for YAML file + .PARAMETER PassThru + Pass the YAML definition to the pipeline object + .EXAMPLE Export-AzDevOpsPipelineYaml -Project $Project -PipelineId $PipelineId -OutputPath $OutputPath #> @@ -218,9 +221,12 @@ function Export-AzDevOpsPipelineYaml { [Parameter(Mandatory)] [string] $PipelineName, - [Parameter(Mandatory)] + [Parameter(ParameterSetName = 'YamlFile')] [string] - $OutputPath + $OutputPath, + [Parameter(ParameterSetName = 'PassThru')] + [switch] + $PassThru ) if ($null -eq $script:connection) { throw "Not connected to Azure DevOps. Run Connect-AzDevOps first" @@ -236,8 +242,12 @@ function Export-AzDevOpsPipelineYaml { return $null } else { $yaml += $yamlTemp} - Write-Verbose "Exporting YAML definition to $OutputPath\$PipelineName.yaml" - $yaml | Out-File "$OutputPath\$PipelineName.yaml" + if ($PassThru) { + Write-Output $yaml + } else { + Write-Verbose "Exporting YAML definition to $OutputPath\$PipelineName.yaml" + $yaml | Out-File "$OutputPath\$PipelineName.yaml" + } } Export-ModuleMember -Function Export-AzDevOpsPipelineYaml # End of Function Export-AzDevOpsPipelineYaml @@ -256,6 +266,9 @@ Export-ModuleMember -Function Export-AzDevOpsPipelineYaml .PARAMETER OutputPath Output path for JSON files + .PARAMETER PassThru + Pass the pipeline object to the pipeline object instead of exporting to a file + .EXAMPLE Export-AzDevOpsPipelines -Project $Project -OutputPath $OutputPath #> @@ -265,9 +278,12 @@ function Export-AzDevOpsPipelines { [Parameter(Mandatory)] [string] $Project, - [Parameter(Mandatory)] + [Parameter(ParameterSetName = 'JsonFile')] [string] - $OutputPath + $OutputPath, + [Parameter(ParameterSetName = 'PassThru')] + [switch] + $PassThru ) if ($null -eq $script:connection) { throw "Not connected to Azure DevOps. Run Connect-AzDevOps first" @@ -290,16 +306,24 @@ function Export-AzDevOpsPipelines { } else { Write-Verbose "Token Type is set to ReadOnly, no pipeline ACLs will be returned" } - Write-Verbose "Exporting pipeline $($pipeline.name) to JSON file" - Write-Verbose "Exporting pipeline as JSON file to $OutputPath\$($pipeline.name).ado.pl.json" - $pipeline | ConvertTo-Json -Depth 100 | Out-File "$OutputPath\$($pipeline.name).ado.pl.json" - if ($pipeline.configuration.type -eq 'yaml' -and $pipeline.configuration.repository.type -eq 'azureReposGit') { - Write-Verbose "Pipeline $($pipeline.name) is a YAML pipeline" - Write-Verbose "Getting YAML definition for pipeline $($pipeline.name)" - Export-AzDevOpsPipelineYaml -Project $Project -PipelineId $pipeline.id -PipelineName $pipeline.name -OutputPath $OutputPath - + If ($PassThru) { + if ($pipeline.configuration.type -eq 'yaml' -and $pipeline.configuration.repository.type -eq 'azureReposGit') { + Write-Verbose "Pipeline $($pipeline.name) is a YAML pipeline" + Write-Verbose "Getting YAML definition for pipeline $($pipeline.name)" + Export-AzDevOpsPipelineYaml -Project $Project -PipelineId $pipeline.id -PipelineName $pipeline.name -PassThru + } + Write-Output $pipeline + } else { + Write-Verbose "Exporting pipeline $($pipeline.name) to JSON file" + Write-Verbose "Exporting pipeline as JSON file to $OutputPath\$($pipeline.name).ado.pl.json" + $pipeline | ConvertTo-Json -Depth 100 | Out-File "$OutputPath\$($pipeline.name).ado.pl.json" + if ($pipeline.configuration.type -eq 'yaml' -and $pipeline.configuration.repository.type -eq 'azureReposGit') { + Write-Verbose "Pipeline $($pipeline.name) is a YAML pipeline" + Write-Verbose "Getting YAML definition for pipeline $($pipeline.name)" + + Export-AzDevOpsPipelineYaml -Project $Project -PipelineId $pipeline.id -PipelineName $pipeline.name -OutputPath $OutputPath + } } - } } Export-ModuleMember -Function Export-AzDevOpsPipelines diff --git a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Environments.ps1 b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Environments.ps1 index 02c1323..99c8bf8 100644 --- a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Environments.ps1 +++ b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Environments.ps1 @@ -126,6 +126,12 @@ Export-ModuleMember -Function Get-AzDevOpsEnvironmentChecks .PARAMETER Project Project name for Azure DevOps + .PARAMETER OutputPath + Path to output JSON files + + .PARAMETER PassThru + Return the exported environments as objects to the pipeline instead of writing to a file + .EXAMPLE Export-AzDevOpsEnvironmentChecks -Project $Project #> @@ -136,9 +142,12 @@ function Export-AzDevOpsEnvironmentChecks { [Parameter(Mandatory)] [string] $Project, - [Parameter(Mandatory)] + [Parameter(ParameterSetName = 'JsonFile')] [string] - $OutputPath + $OutputPath, + [Parameter(ParameterSetName = 'PassThru')] + [switch] + $PassThru ) if ($null -eq $script:connection) { @@ -159,9 +168,13 @@ function Export-AzDevOpsEnvironmentChecks { $environment | Add-Member -MemberType NoteProperty -Name ObjectName -Value ("{0}.{1}.{2}" -f $script:connection.Organization,$Project,$environment.name) $checks = @(Get-AzDevOpsEnvironmentChecks -Project $Project -Environment $environment.id) $environment | Add-Member -MemberType NoteProperty -Name checks -Value $checks - Write-Verbose "Exporting environment $($environment.name) to JSON" - Write-Verbose "Output file: $OutputPath\$($environment.name).ado.env.json" - $environment | ConvertTo-Json -Depth 100 | Out-File -FilePath "$OutputPath\$($environment.name).ado.env.json" + if($PassThru) { + Write-Output $environment + } else { + Write-Verbose "Exporting environment $($environment.name) to JSON" + Write-Verbose "Output file: $OutputPath\$($environment.name).ado.env.json" + $environment | ConvertTo-Json -Depth 100 | Out-File -FilePath "$OutputPath\$($environment.name).ado.env.json" + } } } } diff --git a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Releases.ps1 b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Releases.ps1 index 5417988..9184813 100644 --- a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Releases.ps1 +++ b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Releases.ps1 @@ -122,6 +122,9 @@ Export-ModuleMember -Function Get-AzDevOpsReleaseDefinitionAcls .PARAMETER OutputPath The path to the directory where the JSON files will be exported. + .PARAMETER PassThru + If set, the function will return the release definitions as objects instead of writing them to a file. + .EXAMPLE Export-AzDevOpsReleaseDefinitions -Project 'myproject' -OutputPath 'C:\temp' #> @@ -131,8 +134,11 @@ Function Export-AzDevOpsReleaseDefinitions { [Parameter(Mandatory)] [string]$Project, - [Parameter(Mandatory)] - [string]$OutputPath + [Parameter(ParameterSetName = 'JsonFile')] + [string]$OutputPath, + + [Parameter(ParameterSetName = 'PassThru')] + [switch]$PassThru ) if ($null -eq $script:connection) { throw "Not connected to Azure DevOps. Run Connect-AzDevOps first" @@ -155,8 +161,6 @@ Function Export-AzDevOpsReleaseDefinitions { throw $_.Exception.Message } $definitionName = $response.name - Write-Verbose "Exporting release definition $definitionName as file $definitionName.ado.rd.json" - $definitionPath = Join-Path -Path $OutputPath -ChildPath "$definitionName.ado.rd.json" # Add an ObjectType of Azure.DevOps.Pipelines.Releases.Definition to the response $response | Add-Member -MemberType NoteProperty -Name 'ObjectType' -Value 'Azure.DevOps.Pipelines.Releases.Definition' $response | Add-Member -MemberType NoteProperty -Name 'ObjectName' -Value ("{0}.{1}.{2}" -f $script:connection.Organization,$Project,$definitionName) @@ -178,7 +182,14 @@ Function Export-AzDevOpsReleaseDefinitions { } else { Write-Warning "The ReadOnly token type is not supported for ACL export" } - $response | ConvertTo-Json -Depth 100 | Out-File -FilePath $definitionPath + # If the PassThru switch is set, return the response object + if ($PassThru) { + Write-Output $response + } else { + Write-Verbose "Exporting release definition $definitionName as file $definitionName.ado.rd.json" + $definitionPath = Join-Path -Path $OutputPath -ChildPath "$definitionName.ado.rd.json" + $response | ConvertTo-Json -Depth 100 | Out-File -FilePath $definitionPath + } } } } diff --git a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Settings.ps1 b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Settings.ps1 index 9d862d2..3802027 100644 --- a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Settings.ps1 +++ b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Pipelines.Settings.ps1 @@ -53,6 +53,9 @@ Export-ModuleMember -Function Get-AzDevOpsPipelinesSettings .PARAMETER OutputPath Output path for JSON files + .PARAMETER PassThru + Return the exported pipelines settings as objects to the pipeline instead of writing to a file + .EXAMPLE Export-AzDevOpsPipelinesSettings -Project $Project -OutputPath $OutputPath #> @@ -62,9 +65,12 @@ function Export-AzDevOpsPipelinesSettings { [Parameter(Mandatory)] [string] $Project, - [Parameter(Mandatory)] + [Parameter(ParameterSetName = 'JsonFile')] [string] - $OutputPath + $OutputPath, + [Parameter(ParameterSetName = 'PassThru')] + [switch] + $PassThru ) if ($null -eq $script:connection) { throw "Not connected to Azure DevOps. Run Connect-AzDevOps first" @@ -74,7 +80,11 @@ function Export-AzDevOpsPipelinesSettings { $pipelinesSettings | Add-Member -MemberType NoteProperty -Name ObjectType -Value 'Azure.DevOps.Pipelines.Settings' $pipelinesSettings | Add-Member -MemberType NoteProperty -Name ObjectName -Value ("{0}.{1}.PipelineSettings" -f $script:connection.Organization,$Project) $pipelinesSettings | Add-Member -MemberType NoteProperty -Name Name -Value $Project - $pipelinesSettings | ConvertTo-Json -Depth 10 | Out-File (Join-Path -Path $OutputPath -ChildPath "$Project.ado.pls.json") + if ($PassThru) { + Write-Output $pipelinesSettings + } else { + $pipelinesSettings | ConvertTo-Json -Depth 10 | Out-File (Join-Path -Path $OutputPath -ChildPath "$Project.ado.pls.json") + } } Export-ModuleMember -Function Export-AzDevOpsPipelinesSettings # End of Function Export-AzDevOpsPipelinesSettings diff --git a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Repos.ps1 b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Repos.ps1 index 7e77f64..c0c8c15 100644 --- a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Repos.ps1 +++ b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Repos.ps1 @@ -392,6 +392,9 @@ Export-ModuleMember -Function Get-AzDevOpsRepositoryGhas .PARAMETER OutputPath Output path for JSON file + .PARAMETER PassThru + Return the exported repos as objects to the pipeline instead of writing to a file + .EXAMPLE Export-AzDevOpsReposAndBranchPolicies -Project $Project -OutputPath $OutputPath @@ -404,9 +407,12 @@ function Export-AzDevOpsReposAndBranchPolicies { [Parameter(Mandatory)] [string] $Project, - [Parameter(Mandatory)] + [Parameter(ParameterSetName = 'JsonFile')] [string] - $OutputPath + $OutputPath, + [Parameter(ParameterSetName = 'PassThru')] + [switch] + $PassThru ) if ($null -eq $script:connection) { throw "Not connected to Azure DevOps. Run Connect-AzDevOps first" @@ -471,11 +477,15 @@ function Export-AzDevOpsReposAndBranchPolicies { $repoAcls = Get-AzDevOpsRepositoryAcls -ProjectId $repo.project.id -RepositoryId $repo.id $repo | Add-Member -MemberType NoteProperty -Name Acls -Value $repoAcls } - - # Export repo object to JSON file - Write-Verbose "Exporting repo $($repo.name) and its branches to JSON as file $($repo.name).ado.repo.json" $branches += $repo - $branches | ConvertTo-Json -Depth 100 | Out-File -FilePath "$OutputPath\$($repo.name).ado.repo.json" + # If the PassThru switch is set, return the repo object + if ($PassThru) { + Write-Output $branches + } else { + # Export repo object to JSON file + Write-Verbose "Exporting repo $($repo.name) and its branches to JSON as file $($repo.name).ado.repo.json" + $branches | ConvertTo-Json -Depth 100 | Out-File -FilePath "$OutputPath\$($repo.name).ado.repo.json" + } } } } diff --git a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.RetentionSettings.ps1 b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.RetentionSettings.ps1 index 83b75a9..2dc932b 100644 --- a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.RetentionSettings.ps1 +++ b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.RetentionSettings.ps1 @@ -62,6 +62,9 @@ Export-ModuleMember -Function Get-AzDevOpsRetentionSettings .PARAMETER OutputPath The path to export the retention settings to. + .PARAMETER PassThru + If set, the function will return the retention settings as objects instead of writing them to a file. + .EXAMPLE Get-AzDevOpsRetentionSettings -Project 'MyProject' -OutputPath 'C:\Temp\' @@ -75,11 +78,19 @@ Function Export-AzDevOpsRetentionSettings { [string] $Project, - [Parameter(Mandatory=$true)] + [Parameter(ParameterSetName = 'JsonFile')] [string] - $OutputPath + $OutputPath, + + [Parameter(ParameterSetName = 'PassThru')] + [switch] + $PassThru ) $settings = Get-AzDevOpsRetentionSettings -Project $Project - $settings | ConvertTo-Json -Depth 100 | Out-File -FilePath "$OutputPath\$($Project).ret.ado.json" + if($PassThru) { + Write-Output $settings + } else { + $settings | ConvertTo-Json -Depth 100 | Out-File -FilePath "$OutputPath\$($Project).ret.ado.json" + } } Export-ModuleMember -Function Export-AzDevOpsRetentionSettings diff --git a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.ServiceConnections.ps1 b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.ServiceConnections.ps1 index 3ee458e..e523ce0 100644 --- a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.ServiceConnections.ps1 +++ b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.ServiceConnections.ps1 @@ -104,6 +104,9 @@ Export-ModuleMember -Function Get-AzDevOpsServiceConnectionChecks .PARAMETER OutputPath Output path for JSON files + .PARAMETER PassThru + Return the exported service connections as objects to the pipeline instead of writing to a file + .EXAMPLE Export-AzDevOpsServiceConnections -Project $Project -OutputPath $OutputPath @@ -116,9 +119,12 @@ function Export-AzDevOpsServiceConnections { [Parameter(Mandatory)] [string] $Project, - [Parameter(Mandatory)] + [Parameter(ParameterSetName = 'JsonFile')] [string] - $OutputPath + $OutputPath, + [Parameter(ParameterSetName = 'PassThru')] + [switch] + $PassThru ) if ($null -eq $script:connection) { throw "Not connected to Azure DevOps. Run Connect-AzDevOps first" @@ -135,8 +141,12 @@ function Export-AzDevOpsServiceConnections { # Get checks for service connection $serviceConnectionChecks = @(Get-AzDevOpsServiceConnectionChecks -Project $Project -ServiceConnectionId $serviceConnection.id) $serviceConnection | Add-Member -MemberType NoteProperty -Name Checks -Value $serviceConnectionChecks - Write-Verbose "Exporting service connection $($serviceConnection.name) as file $($serviceConnection.name).ado.sc.json" - $serviceConnection | ConvertTo-Json -Depth 100 | Out-File "$OutputPath/$($serviceConnection.name).ado.sc.json" + if ($PassThru) { + Write-Output $serviceConnection + } else { + Write-Verbose "Exporting service connection $($serviceConnection.name) as file $($serviceConnection.name).ado.sc.json" + $serviceConnection | ConvertTo-Json -Depth 100 | Out-File "$OutputPath/$($serviceConnection.name).ado.sc.json" + } } } Export-ModuleMember -Function Export-AzDevOpsServiceConnections diff --git a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Tasks.VariableGroups.ps1 b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Tasks.VariableGroups.ps1 index 3f1ede8..141e5db 100644 --- a/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Tasks.VariableGroups.ps1 +++ b/src/PSRule.Rules.AzureDevOps/Functions/DevOps.Tasks.VariableGroups.ps1 @@ -54,6 +54,9 @@ Export-ModuleMember -Function Get-AzDevOpsVariableGroups .PARAMETER OutputPath The path to export variable groups to. + .PARAMETER PassThru + Return the exported variable groups as objects to the pipeline instead of writing to a file. + .EXAMPLE Export-AzDevOpsVariableGroups -Project 'myproject' -OutputPath 'C:\temp' @@ -69,9 +72,13 @@ Function Export-AzDevOpsVariableGroups { [string] $Project, - [Parameter(Mandatory)] + [Parameter(ParameterSetName = 'JsonFile')] [string] - $OutputPath + $OutputPath, + + [Parameter(ParameterSetName = 'PassThru')] + [switch] + $PassThru ) if ($null -eq $script:connection) { throw "Not connected to Azure DevOps. Run Connect-AzDevOps first" @@ -83,9 +90,13 @@ Function Export-AzDevOpsVariableGroups { $variableGroup | Add-Member -MemberType NoteProperty -Name 'ObjectType' -Value 'Azure.DevOps.Tasks.VariableGroup' $variableGroup | Add-Member -MemberType NoteProperty -Name 'ObjectName' -Value "$Organization.$Project.$($variableGroup.name)" $variableGroupName = $variableGroup.name - $variableGroupPath = Join-Path -Path $OutputPath -ChildPath "$variableGroupName.ado.vg.json" - Write-Verbose "Exporting variable group $variableGroupName as file $variableGroupName.ado.vg.json" - $variableGroup | ConvertTo-Json -Depth 100 | Out-File -FilePath $variableGroupPath -Encoding UTF8 + if ($PassThru) { + Write-Output $variableGroup + } else { + $variableGroupPath = Join-Path -Path $OutputPath -ChildPath "$variableGroupName.ado.vg.json" + Write-Verbose "Exporting variable group $variableGroupName as file $variableGroupName.ado.vg.json" + $variableGroup | ConvertTo-Json -Depth 100 | Out-File -FilePath $variableGroupPath -Encoding UTF8 + } } } Export-ModuleMember -Function Export-AzDevOpsVariableGroups diff --git a/src/PSRule.Rules.AzureDevOps/PSRule.Rules.AzureDevOps.psm1 b/src/PSRule.Rules.AzureDevOps/PSRule.Rules.AzureDevOps.psm1 index 6b02632..8f30033 100644 --- a/src/PSRule.Rules.AzureDevOps/PSRule.Rules.AzureDevOps.psm1 +++ b/src/PSRule.Rules.AzureDevOps/PSRule.Rules.AzureDevOps.psm1 @@ -27,6 +27,9 @@ Get-ChildItem -Path "$PSScriptRoot/Functions/*.ps1" | ForEach-Object { .PARAMETER OutputPath Output path for JSON files + .PARAMETER PassThru + Return the exported project as objects to the pipeline instead of writing to a file + .EXAMPLE Export-AzDevOpsRuleData -Project $Project -OutputPath $OutputPath #> @@ -36,31 +39,61 @@ Function Export-AzDevOpsRuleData { [Parameter(Mandatory)] [string] $Project, - [Parameter(Mandatory)] + [Parameter(ParameterSetName = 'JsonFile')] [string] - $OutputPath + $OutputPath, + [Parameter(ParameterSetName = 'PassThru')] + [switch] + $PassThru ) - Write-Verbose "Exporting rule data for project $Project to $OutputPath" - Write-Verbose "Exporting project" - Export-AzDevOpsProject -Project $Project -OutputPath $OutputPath - Write-Verbose "Exporting repos and branch policies" - Export-AzDevOpsReposAndBranchPolicies -Project $Project -OutputPath $OutputPath - Write-Verbose "Exporting environment checks" - Export-AzDevOpsEnvironmentChecks -Project $Project -OutputPath $OutputPath - Write-Verbose "Exporting service connections" - Export-AzDevOpsServiceConnections -Project $Project -OutputPath $OutputPath - Write-Verbose "Exporting pipelines" - Export-AzDevOpsPipelines -Project $Project -OutputPath $OutputPath - Write-Verbose "Exporting pipelines settings" - Export-AzDevOpsPipelinesSettings -Project $Project -OutputPath $OutputPath - Write-Verbose "Exporting variable groups" - Export-AzDevOpsVariableGroups -Project $Project -OutputPath $OutputPath - Write-Verbose "Exporting release definitions" - Export-AzDevOpsReleaseDefinitions -Project $Project -OutputPath $OutputPath - Write-Verbose "Exporting groups" - Export-AzDevOpsGroups -Project $Project -OutputPath $OutputPath - Write-Verbose "Exporting retention settings" - Export-AzDevOpsRetentionSettings -Project $Project -OutputPath $OutputPath + if ($null -eq $script:connection) { + throw "Not connected to Azure DevOps. Run Connect-AzDevOps first" + } + if($PassThru) { + Write-Verbose "Exporting rule data for project $Project to $OutputPath" + Write-Verbose "Exporting project" + Export-AzDevOpsProject -Project $Project -PassThru + Write-Verbose "Exporting repos and branch policies" + Export-AzDevOpsReposAndBranchPolicies -Project $Project -PassThru + Write-Verbose "Exporting environment checks" + Export-AzDevOpsEnvironmentChecks -Project $Project -PassThru + Write-Verbose "Exporting service connections" + Export-AzDevOpsServiceConnections -Project $Project -PassThru + Write-Verbose "Exporting pipelines" + Export-AzDevOpsPipelines -Project $Project -PassThru + Write-Verbose "Exporting pipelines settings" + Export-AzDevOpsPipelinesSettings -Project $Project -PassThru + Write-Verbose "Exporting variable groups" + Export-AzDevOpsVariableGroups -Project $Project -PassThru + Write-Verbose "Exporting release definitions" + Export-AzDevOpsReleaseDefinitions -Project $Project -PassThru + Write-Verbose "Exporting groups" + Export-AzDevOpsGroups -Project $Project -PassThru + Write-Verbose "Exporting retention settings" + Export-AzDevOpsRetentionSettings -Project $Project -PassThru + } else { + Write-Verbose "Exporting rule data for project $Project to $OutputPath" + Write-Verbose "Exporting project" + Export-AzDevOpsProject -Project $Project -OutputPath $OutputPath + Write-Verbose "Exporting repos and branch policies" + Export-AzDevOpsReposAndBranchPolicies -Project $Project -OutputPath $OutputPath + Write-Verbose "Exporting environment checks" + Export-AzDevOpsEnvironmentChecks -Project $Project -OutputPath $OutputPath + Write-Verbose "Exporting service connections" + Export-AzDevOpsServiceConnections -Project $Project -OutputPath $OutputPath + Write-Verbose "Exporting pipelines" + Export-AzDevOpsPipelines -Project $Project -OutputPath $OutputPath + Write-Verbose "Exporting pipelines settings" + Export-AzDevOpsPipelinesSettings -Project $Project -OutputPath $OutputPath + Write-Verbose "Exporting variable groups" + Export-AzDevOpsVariableGroups -Project $Project -OutputPath $OutputPath + Write-Verbose "Exporting release definitions" + Export-AzDevOpsReleaseDefinitions -Project $Project -OutputPath $OutputPath + Write-Verbose "Exporting groups" + Export-AzDevOpsGroups -Project $Project -OutputPath $OutputPath + Write-Verbose "Exporting retention settings" + Export-AzDevOpsRetentionSettings -Project $Project -OutputPath $OutputPath + } } Export-ModuleMember -Function Export-AzDevOpsRuleData -Alias Export-AzDevOpsProjectRuleData # End of Function Export-AzDevOpsRuleData diff --git a/tests/Common.Tests.ps1 b/tests/Common.Tests.ps1 index 1fc633b..eb66f90 100644 --- a/tests/Common.Tests.ps1 +++ b/tests/Common.Tests.ps1 @@ -284,6 +284,39 @@ Describe "Functions: Common.Tests" { } | Should -Throw } } + + Context " Export-AzDevOpsProject -PassThru" { + BeforeAll { + Connect-AzDevOps -Organization $env:ADO_ORGANIZATION -PAT $env:ADO_PAT + $project = Get-AzDevOpsProject -Project $env:ADO_PROJECT + $projectDetails = Export-AzDevOpsProject -Project $project.name -PassThru + $ruleResult = $projectDetails | Invoke-PSRule -Module @('PSRule.Rules.AzureDevOps') -Culture en + } + + It " The output should be of type [PSCustomObject]" { + $projectDetails | Should -BeOfType [PSCustomObject] + } + + It " The output should have a ObjectType property" { + $projectDetails | Select -ExpandProperty ObjectType | Should -Not -BeNullOrEmpty + } + + It " The output should have a ObjectName property" { + $projectDetails | Select -ExpandProperty ObjectName | Should -Not -BeNullOrEmpty + } + + It " The output should have results with Invoke-PSRule" { + $ruleResult | Should -Not -BeNullOrEmpty + } + + It " The output should have results with Invoke-PSRule that are of type [PSRule.Rules.RuleRecord]" { + $ruleResult[0] | Should -BeOfType [PSRule.Rules.RuleRecord] + } + + AfterAll { + Disconnect-AzDevOps + } + } } AfterAll { diff --git a/tests/DevOps.Groups.Tests.ps1 b/tests/DevOps.Groups.Tests.ps1 index dfda0b0..50c88dc 100644 --- a/tests/DevOps.Groups.Tests.ps1 +++ b/tests/DevOps.Groups.Tests.ps1 @@ -296,6 +296,38 @@ Describe "Azure.DevOps.Group" { } | Should -Throw } } + + Context " Export-AzDevOpsGroups -PassThru" { + BeforeAll { + Connect-AzDevOps -Organization $env:ADO_ORGANIZATION -PAT $env:ADO_PAT + $groups = Export-AzDevOpsGroups -Project $env:ADO_PROJECT -PassThru + $ruleResult = $groups | Invoke-PSRule -Module @('PSRule.Rules.AzureDevOps') -Culture en + } + + It " Should return a list of groups" { + $groups | Should -Not -BeNullOrEmpty + } + + It " Should return a list of groups with an ObjectType property" { + $groups[0].ObjectType | Should -Not -BeNullOrEmpty + } + + It " Should return a list of groups with an ObjectName property" { + $groups[0].ObjectName | Should -Not -BeNullOrEmpty + } + + It " The output should have results with Invoke-PSRule" { + $ruleResult | Should -Not -BeNullOrEmpty + } + + It " The output should have results with Invoke-PSRule that are of type [PSRule.Rules.RuleRecord]" { + $ruleResult[0] | Should -BeOfType [PSRule.Rules.RuleRecord] + } + + AfterAll { + Disconnect-AzDevOps + } + } } AfterAll { diff --git a/tests/DevOps.Pipelines.Core.Tests.ps1 b/tests/DevOps.Pipelines.Core.Tests.ps1 index 948bcf8..dd89378 100644 --- a/tests/DevOps.Pipelines.Core.Tests.ps1 +++ b/tests/DevOps.Pipelines.Core.Tests.ps1 @@ -268,6 +268,43 @@ Describe "Functions: DevOps.Pipelines.Core.Tests" { Disconnect-AzDevOps } } + + Context " Export-AzDevOpsPipelines -PassThru" { + BeforeAll { + Connect-AzDevOps -Organization $env:ADO_ORGANIZATION -PAT $env:ADO_PAT + $pipelines = Export-AzDevOpsPipelines -Project $env:ADO_PROJECT -PassThru + $ruleResult = $pipelines | Where-Object { $null -ne $_ } | Invoke-PSRule -Module @('PSRule.Rules.AzureDevOps') -Culture en + } + + It " should return a list of pipelines" { + $pipelines | Should -Not -BeNullOrEmpty + } + + It " should return a list of pipelines that are of type PSObject" { + $pipelines[1] | Should -BeOfType [PSCustomObject] + } + + It " should return a list of pipelines that have an ObjectType field with a value of Azure.DevOps.Pipeline" { + $pipelines[1].ObjectType | Should -Be "Azure.DevOps.Pipeline" + } + + It " should return a list of pipelines that have an ObjectName field" { + $pipelines[1].ObjectName | Should -Not -BeNullOrEmpty + } + + It " The output should have results with Invoke-PSRule" { + $ruleResult | Should -Not -BeNullOrEmpty + } + + It " The output should have results with Invoke-PSRule that are of type [PSRule.Rules.RuleRecord]" { + $ruleResult[0] | Should -BeOfType [PSRule.Rules.RuleRecord] + } + + AfterAll { + Disconnect-AzDevOps + } + + } } AfterAll { diff --git a/tests/DevOps.Pipelines.Environments.Tests.ps1 b/tests/DevOps.Pipelines.Environments.Tests.ps1 index a672444..5073fec 100644 --- a/tests/DevOps.Pipelines.Environments.Tests.ps1 +++ b/tests/DevOps.Pipelines.Environments.Tests.ps1 @@ -210,6 +210,43 @@ Describe "Functions: Azure.DevOps.Pipelines.Environments.Tests" { Disconnect-AzDevOps } } + + Context " Export-AzDevOpsEnvironmentChecks -PassThru" { + BeforeAll { + Connect-AzDevOps -Organization $env:ADO_ORGANIZATION -PAT $env:ADO_PAT + $environmentChecks = Export-AzDevOpsEnvironmentChecks -Project $env:ADO_PROJECT -PassThru + $ruleResult = $environmentChecks | Invoke-PSRule -Module PSRule.Rules.AzureDevOps -Culture en + } + + It " should return a list of environment checks" { + $environmentChecks | Should -Not -BeNullOrEmpty + } + + It " should return a list of environment checks that are of type PSObject" { + $environmentChecks[0] | Should -BeOfType [PSCustomObject] + } + + It " should return a list of object with an ObjectType property" { + $environmentChecks[0].ObjectType | Should -Not -BeNullOrEmpty + } + + It " should return a list of object with an ObjectName property" { + $environmentChecks[0].ObjectName | Should -Not -BeNullOrEmpty + } + + It " The output should have results with Invoke-PSRule" { + $ruleResult | Should -Not -BeNullOrEmpty + } + + It " The output should have results with Invoke-PSRule that are of type [PSRule.Rules.RuleRecord]" { + $ruleResult[0] | Should -BeOfType [PSRule.Rules.RuleRecord] + } + + AfterAll { + Disconnect-AzDevOps + } + + } } AfterAll { diff --git a/tests/DevOps.Pipelines.Releases.Tests.ps1 b/tests/DevOps.Pipelines.Releases.Tests.ps1 index 02b82ba..9deb8a8 100644 --- a/tests/DevOps.Pipelines.Releases.Tests.ps1 +++ b/tests/DevOps.Pipelines.Releases.Tests.ps1 @@ -176,6 +176,45 @@ Describe "Functions: DevOps.Pipelines.Releases.Tests" { Disconnect-AzDevOps } } + + Context " Export-AzDevOpsReleaseDefinitions -PassThru" { + BeforeAll { + Connect-AzDevOps -Organization $env:ADO_ORGANIZATION -PAT $env:ADO_PAT + $Project = $env:ADO_PROJECT + $releaseDefinitions = Export-AzDevOpsReleaseDefinitions -Project $Project -PassThru + $ruleResult = $releaseDefinitions | Invoke-PSRule -Module @('PSRule.Rules.AzureDevOps') -Culture en + } + + It " should return a list of release definitions" { + $releaseDefinitions | Should -Not -BeNullOrEmpty + } + + It " should return a list of release definitions that are of type PSObject" { + $releaseDefinitions[0] | Should -BeOfType [PSCustomObject] + } + + It " should return a list of release definitions that have an ObjectType" { + $releaseDefinitions[0].ObjectType | Should -Not -BeNullOrEmpty + $releaseDefinitions[0].ObjectType | Should -BeOfType [string] + } + + It " should return a list of release definitions that have an ObjectName" { + $releaseDefinitions[0].ObjectName | Should -Not -BeNullOrEmpty + $releaseDefinitions[0].ObjectName | Should -BeOfType [string] + } + + It " The output should have results with Invoke-PSRule" { + $ruleResult | Should -Not -BeNullOrEmpty + } + + It " The output should have results with Invoke-PSRule that are of type [PSRule.Rules.RuleRecord]" { + $ruleResult[0] | Should -BeOfType [PSRule.Rules.RuleRecord] + } + + AfterAll { + Disconnect-AzDevOps + } + } } AfterAll { diff --git a/tests/DevOps.Pipelines.Settings.Tests.ps1 b/tests/DevOps.Pipelines.Settings.Tests.ps1 index a37db61..4ab7d92 100644 --- a/tests/DevOps.Pipelines.Settings.Tests.ps1 +++ b/tests/DevOps.Pipelines.Settings.Tests.ps1 @@ -71,6 +71,38 @@ Describe "Functions: DevOps.Pipelines.Settings.Tests" { $json.ObjectType | Should -Be "Azure.DevOps.Pipelines.Settings" } } + + Context " Export-AzDevOpsPipelinesSettings -PassThru" { + BeforeAll { + Connect-AzDevOps -Organization $env:ADO_ORGANIZATION -PAT $env:ADO_PAT + $settings = Export-AzDevOpsPipelinesSettings -Project $env:ADO_PROJECT -PassThru + $ruleResult = $settings | Invoke-PSRule -Module @('PSRule.Rules.AzureDevOps') -Culture en + } + + It " should return project pipeline settings" { + $settings | Should -Not -BeNullOrEmpty + } + + It " should return project pipeline settings that are of type PSObject" { + $settings | Should -BeOfType [PSCustomObject] + } + + It " should return project pipeline settings with an ObjectType of Azure.DevOps.Pipelines.Settings" { + $settings.ObjectType | Should -Be "Azure.DevOps.Pipelines.Settings" + } + + It " should return project pipeline settings with an ObjectName of {Organization}.{Project}.PipelineSettings" { + $settings.ObjectName | Should -Be ("{0}.{1}.PipelineSettings" -f $env:ADO_ORGANIZATION,$env:ADO_PROJECT) + } + + It " The output should have results with Invoke-PSRule" { + $ruleResult | Should -Not -BeNullOrEmpty + } + + It " The output should have results with Invoke-PSRule that are of type [PSRule.Rules.RuleRecord]" { + $ruleResult[0] | Should -BeOfType [PSRule.Rules.RuleRecord] + } + } } AfterAll { diff --git a/tests/DevOps.Repos.Tests.ps1 b/tests/DevOps.Repos.Tests.ps1 index 11027ff..4621934 100644 --- a/tests/DevOps.Repos.Tests.ps1 +++ b/tests/DevOps.Repos.Tests.ps1 @@ -388,6 +388,39 @@ Describe "Functions: DevOps.Repos.Tests" { } } } + + Context " Export-AzDevOpsReposAndBranchPolicies -PassThru" { + BeforeAll { + Connect-AzDevOps -Organization $env:ADO_ORGANIZATION -PAT $env:ADO_PAT + $Project = $env:ADO_PROJECT + $repos = Export-AzDevOpsReposAndBranchPolicies -Project $Project -PassThru + $ruleResult = $repos | Invoke-PSRule -Module @('PSRule.Rules.AzureDevOps') -Culture en + } + + It " should return project repos" { + $repos | Should -Not -BeNullOrEmpty + } + + It " should return project repos that are of type PSObject" { + $repos[0] | Should -BeOfType [PSCustomObject] + } + + It " should return project repos with an ObjectType" { + $repos[0].ObjectType | Should -Not -BeNullOrEmpty + } + + It " should return project repos with an ObjectName" { + $repos[0].ObjectName | Should -Not -BeNullOrEmpty + } + + It " The output should have results with Invoke-PSRule" { + $ruleResult | Should -Not -BeNullOrEmpty + } + + It " The output should have results with Invoke-PSRule that are of type [PSRule.Rules.RuleRecord]" { + $ruleResult[0] | Should -BeOfType [PSRule.Rules.RuleRecord] + } + } } AfterAll { diff --git a/tests/DevOps.RetentionSettings.Tests.ps1 b/tests/DevOps.RetentionSettings.Tests.ps1 index 1b4ac29..6508d10 100644 --- a/tests/DevOps.RetentionSettings.Tests.ps1 +++ b/tests/DevOps.RetentionSettings.Tests.ps1 @@ -134,6 +134,46 @@ Describe 'Azure.DevOps.RetentionSettings' { } | Should -Throw "Failed to get retention settings for project 'wrongProject' from Azure DevOps" } } + + Context ' Export-AzDevOpsRetentionSettings -PassThru' { + BeforeAll { + Connect-AzDevOps -Organization $env:ADO_ORGANIZATION -PAT $env:ADO_PAT + $settings = Export-AzDevOpsRetentionSettings -Project $env:ADO_PROJECT -PassThru + $ruleResult = $settings | Invoke-PSRule -Module @('PSRule.Rules.AzureDevOps') -Culture en + } + + It 'should return a hashtable' { + $settings | Should -BeOfType [hashtable] + } + + It 'should return a hashtable with RetentionSettings property' { + $settings.RetentionSettings | Should -Not -BeNullOrEmpty + } + + It 'should return a hashtable with RetentionPolicy property' { + $settings.RetentionPolicy | Should -Not -BeNullOrEmpty + } + + It 'should return a hashtable with ObjectType property' { + $settings.ObjectType | Should -Not -BeNullOrEmpty + } + + It 'should return a hashtable with ObjectName property' { + $settings.ObjectName | Should -Not -BeNullOrEmpty + } + + It " The output should have results with Invoke-PSRule" { + $ruleResult | Should -Not -BeNullOrEmpty + } + + It " The output should have results with Invoke-PSRule that are of type [PSRule.Rules.RuleRecord]" { + $ruleResult[0] | Should -BeOfType [PSRule.Rules.RuleRecord] + } + + AfterAll { + Disconnect-AzDevOps + } + } } AfterAll { diff --git a/tests/DevOps.ServiceConnections.Tests.ps1 b/tests/DevOps.ServiceConnections.Tests.ps1 index a6a21df..c2356a3 100644 --- a/tests/DevOps.ServiceConnections.Tests.ps1 +++ b/tests/DevOps.ServiceConnections.Tests.ps1 @@ -136,6 +136,41 @@ Describe "Functions: DevOps.ServiceConnections.Tests" { } } } + + Context " Export-AzDevOpsServiceConnections -PassThru" { + BeforeAll { + Connect-AzDevOps -Organization $env:ADO_ORGANIZATION -PAT $env:ADO_PAT + $Project = $env:ADO_PROJECT + $serviceConnections = Export-AzDevOpsServiceConnections -Project $Project -PassThru + $ruleResult = $serviceConnections | Invoke-PSRule -Module @('PSRule.Rules.AzureDevOps') -Culture en + } + + It " should return a list of service connections" { + $serviceConnections | Should -Not -BeNullOrEmpty + } + + It " should return a list of service connections that are of type PSObject" { + $serviceConnections[0] | Should -BeOfType [PSCustomObject] + } + + It " should return a list of service connections that have an ObjectName" { + $serviceConnections[0].ObjectName | Should -Not -BeNullOrEmpty + $serviceConnections[0].ObjectName | Should -BeOfType [string] + } + + It " should return a list of service connections that have an ObjectType" { + $serviceConnections[0].ObjectType | Should -Not -BeNullOrEmpty + $serviceConnections[0].ObjectType | Should -BeOfType [string] + } + + It " The output should have results with Invoke-PSRule" { + $ruleResult | Should -Not -BeNullOrEmpty + } + + It " The output should have results with Invoke-PSRule that are of type [PSRule.Rules.RuleRecord]" { + $ruleResult[0] | Should -BeOfType [PSRule.Rules.RuleRecord] + } + } } AfterAll { diff --git a/tests/DevOps.Tasks.VariableGroups.Tests.ps1 b/tests/DevOps.Tasks.VariableGroups.Tests.ps1 index 3fc0551..e663f47 100644 --- a/tests/DevOps.Tasks.VariableGroups.Tests.ps1 +++ b/tests/DevOps.Tasks.VariableGroups.Tests.ps1 @@ -91,6 +91,41 @@ Describe "Functions: DevOps.Tasks.VariableGroups.Tests" { $json.ObjectType | Should -Be "Azure.DevOps.Tasks.VariableGroup" } } + + Context " Export-AzDevOpsVariableGroups -PassThru" { + BeforeAll { + Connect-AzDevOps -Organization $env:ADO_ORGANIZATION -PAT $env:ADO_PAT + $Project = $env:ADO_PROJECT + $variableGroups = Export-AzDevOpsVariableGroups -Project $Project -PassThru + $ruleResult = $variableGroups | Invoke-PSRule -Module @('PSRule.Rules.AzureDevOps') -Culture en + } + + It ' should return a list of variable groups' { + $variableGroups | Should -Not -BeNullOrEmpty + } + + It ' should return a list of variable groups that are of type PSObject' { + $variableGroups[0] | Should -BeOfType [PSCustomObject] + } + + It ' should return a list of variable groups with an ObjectName' { + $variableGroups[0].ObjectName | Should -Not -BeNullOrEmpty + $variableGroups[0].ObjectName | Should -BeOfType [System.String] + } + + It ' should return a list of variable groups with an ObjectType' { + $variableGroups[0].ObjectType | Should -Not -BeNullOrEmpty + $variableGroups[0].ObjectType | Should -BeOfType [System.String] + } + + It " The output should have results with Invoke-PSRule" { + $ruleResult | Should -Not -BeNullOrEmpty + } + + It " The output should have results with Invoke-PSRule that are of type [PSRule.Rules.RuleRecord]" { + $ruleResult[0] | Should -BeOfType [PSRule.Rules.RuleRecord] + } + } } AfterAll {