tests/assets/FunctionnalYamlTests.ps1

param(
    [Parameter(Mandatory=$true)][string] $project,
    [Parameter(Mandatory=$true)][string] $PAT,
    [Parameter(Mandatory=$true)][string] $account,
    [Parameter(Mandatory=$true)][string[]] $appNames
)
#Setup
import-module "./PSTS.psd1" -Verbose -force
Add-PSTSAccount -account $account -endPoint "dev.azure.com" -personalAccessToken $PAT


#Test Variable group
$kv1 = Get-PSTSVariablesGroup -project $project | where name -eq "kv-total-it-aksmgt"

if($null -ne $kv1) { Write-Output "The variable group have been properly created" }
else { Throw "Variable group not found" }

#Test SecureFile
$configDev1 = Get-PSTSSecureFile -project $project | where name -eq "mysuperconfig.txtdev"
$configDev2 = Get-PSTSSecureFile -project $project | where name -eq "mysuperconfig2.txtdev"
$configQa1 = Get-PSTSSecureFile -project $project | where name -eq "mysuperconfig.txtqa"
$configQa2 = Get-PSTSSecureFile -project $project | where name -eq "mysuperconfig2.txtqa"

if(
    $null -ne $configDev1 `
    -and $null -ne $configDev2 `
    -and $null -ne $configQa1 `
    -and $null -ne $configQa2 `
) { Write-Output "The SecureFiles have been properly created" }
else { Throw "SecureFiles not found" }

foreach($appName in $appNames) {

    #Test Release definition creation
    $releaseDefDev  =  Get-PSTSReleaseDefinition -project $project | where name -eq "$($appName) - dev"
    $releaseDefQa  =  Get-PSTSReleaseDefinition -project $project | where name -eq "$($appName) - qa"

    if($null -ne $releaseDefDev -and $null -ne $releaseDefQa) { Write-Output "$($appName) : The release definition have been properly created" }
    else { Throw "$($appName) : Release definition not found" }

    
    if($appName -eq "tetris1" -and $null -ne $releaseDefDev.variable.helmParams) 
        { Write-Output "$($appName) : The release definition expose is correct" }
    elseif($appName -eq "tetris" -and $null -ne $releaseDefDev.variable.helmParams `
     -or $appName -eq "tetris1" -and $null -eq $releaseDefDev.variable.helmParams) 
        { Throw "$($appName) : Incorrect expose variable" }

    #Test Build definition
    $buildDefDev  =  Get-PSTSBuildDefinition -project $project | where name -eq "Build $($appName) - dev"
    $buildDefQa  =  Get-PSTSBuildDefinition -project $project | where name -eq "Build $($appName) - qa"

    if($null -ne $buildDefDev -and $null -ne $buildDefQa) { Write-Output "$($appName) : The build definition have been properly created" }
    else { Throw "$($appName) : Build definition not found" }

}