Skip to content

Commit

Permalink
Test suite list
Browse files Browse the repository at this point in the history
  • Loading branch information
mdejulia authored and mdejulia committed Aug 14, 2020
1 parent 75cee7f commit 3f764f5
Show file tree
Hide file tree
Showing 2 changed files with 226 additions and 0 deletions.
8 changes: 8 additions & 0 deletions AzurePipelinesPS/Private/Get-APApiEndpoint.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,14 @@ function Get-APApiEndpoint
{
Return '_apis/testplan/plans'
}
'test-testPlanId'
{
Return '_apis/testplan/plans/{0}'
}
'test-suites'
{
Return '_apis/test/plans/{0}/suites'
}
default
{
Write-Error "[$($MyInvocation.MyCommand.Name)]: [$ApiType] is not supported" -ErrorAction Stop
Expand Down
218 changes: 218 additions & 0 deletions AzurePipelinesPS/Public/Get-APTestSuiteList.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
function Get-APTestSuiteList
{
<#
.SYNOPSIS
Returns a list of Azure Pipeline test cases for a suite.
.DESCRIPTION
Returns a list of Azure Pipeline test cases for a suite based on the plan id.
The plan id can be returned with Get-APTestPlanList.
.PARAMETER Instance
The Team Services account or TFS server.
.PARAMETER Collection
For Azure DevOps the value for collection should be the name of your orginization.
For both Team Services and TFS The value should be DefaultCollection unless another collection has been created.
.PARAMETER Project
Project ID or project name.
.PARAMETER ApiVersion
Version of the api to use.
.PARAMETER PersonalAccessToken
Personal access token used to authenticate that has been converted to a secure string.
It is recomended to uses an Azure Pipelines PS session to pass the personal access token parameter among funcitons, See New-APSession.
https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts
.PARAMETER Credential
Specifies a user account that has permission to send the request.
.PARAMETER Proxy
Use a proxy server for the request, rather than connecting directly to the Internet resource. Enter the URI of a network proxy server.
.PARAMETER ProxyCredential
Specifie a user account that has permission to use the proxy server that is specified by the -Proxy parameter. The default is the current user.
.PARAMETER Session
Azure DevOps PS session, created by New-APSession.
.PARAMETER PlanId
Id of the test plan for which suites are requested
.PARAMETER Skip
Number of test suites to skip.
.PARAMETER Top
The maximum number of test suites to return.
.PARAMETER Expand
Include the children suites and testers details.
.INPUTS
None, does not support pipeline.
.OUTPUTS
PSObject, Azure Pipelines test suite(s)
.EXAMPLE
Returns AP test suite list for 'myFirstProject' for run with the id of '7'
Get-APTestSuiteList -Instance 'https://dev.azure.com' -Collection 'myCollection' -Project 'myFirstProject' -PlanId 7
.LINK
https://docs.microsoft.com/en-us/rest/api/azure/devops/test/test%20%20suites/get%20test%20suites%20for%20plan?view=azure-devops-server-rest-5.0
#>
[CmdletBinding(DefaultParameterSetName = 'ByPersonalAccessToken')]
Param
(
[Parameter(Mandatory,
ParameterSetName = 'ByPersonalAccessToken')]
[Parameter(Mandatory,
ParameterSetName = 'ByCredential')]
[uri]
$Instance,

[Parameter(Mandatory,
ParameterSetName = 'ByPersonalAccessToken')]
[Parameter(Mandatory,
ParameterSetName = 'ByCredential')]
[string]
$Collection,

[Parameter(Mandatory,
ParameterSetName = 'ByPersonalAccessToken')]
[Parameter(Mandatory,
ParameterSetName = 'ByCredential')]
[string]
$Project,

[Parameter(Mandatory,
ParameterSetName = 'ByPersonalAccessToken')]
[Parameter(Mandatory,
ParameterSetName = 'ByCredential')]
[string]
$ApiVersion,

[Parameter(ParameterSetName = 'ByPersonalAccessToken')]
[Security.SecureString]
$PersonalAccessToken,

[Parameter(ParameterSetName = 'ByCredential')]
[pscredential]
$Credential,

[Parameter(ParameterSetName = 'ByPersonalAccessToken')]
[Parameter(ParameterSetName = 'ByCredential')]
[string]
$Proxy,

[Parameter(ParameterSetName = 'ByPersonalAccessToken')]
[Parameter(ParameterSetName = 'ByCredential')]
[pscredential]
$ProxyCredential,

[Parameter(Mandatory,
ParameterSetName = 'BySession')]
[object]
$Session,

[Parameter(Mandatory)]
[int]
$PlanId,

[Parameter()]
[int]
$Skip,

[Parameter()]
[int]
$Top,

[Parameter()]
[int]
$Expand
)

begin
{
If ($PSCmdlet.ParameterSetName -eq 'BySession')
{
$currentSession = $Session | Get-APSession
If ($currentSession)
{
$Instance = $currentSession.Instance
$Collection = $currentSession.Collection
$Project = $currentSession.Project
$PersonalAccessToken = $currentSession.PersonalAccessToken
$Credential = $currentSession.Credential
$Proxy = $currentSession.Proxy
$ProxyCredential = $currentSession.ProxyCredential
If ($currentSession.Version)
{
$ApiVersion = (Get-APApiVersion -Version $currentSession.Version)
}
else
{
$ApiVersion = $currentSession.ApiVersion
}
}
}
}

process
{
$apiEndpoint = (Get-APApiEndpoint -ApiType 'test-suites') -f $PlanId
$queryParameters = Set-APQueryParameters -InputObject $PSBoundParameters
$setAPUriSplat = @{
Collection = $Collection
Instance = $Instance
Project = $Project
ApiVersion = $ApiVersion
ApiEndpoint = $apiEndpoint
Query = $queryParameters
}
[uri] $uri = Set-APUri @setAPUriSplat
$invokeAPRestMethodSplat = @{
Method = 'GET'
Uri = $uri
Credential = $Credential
PersonalAccessToken = $PersonalAccessToken
Proxy = $Proxy
ProxyCredential = $ProxyCredential
}
$results = Invoke-APRestMethod @invokeAPRestMethodSplat
If ($results.value)
{
return $results.value
}
else
{
return $results
}
}

end
{
}
}

0 comments on commit 3f764f5

Please sign in to comment.