Controllers/TestController.ps1
Set-StrictMode -Version Latest function Test-AzSDK{ Param( [Parameter(Mandatory = $True)] [string] $SubscriptionId = [string]::Empty, [Parameter(Mandatory = $False)] [string] $TestScenariosFileName = "DefaultTestScenarios.json", [Parameter(Mandatory = $False)] [string] $TestScenarioID = [string]::Empty, [Parameter(Mandatory = $False)] [string] $Feature = [string]::Empty, [Parameter(Mandatory = $False)] [string] $ModuleName = [string]::Empty, [Parameter(Mandatory = $False)] [string] $TestCaseID = [string]::Empty, [Parameter(Mandatory = $False)] [string] $Priority = [string]::Empty, [Parameter(Mandatory = $False)] [PSObject] $Settings = $null, [Parameter(Mandatory = $False)] [string] $AzSDKVersion = 'Prod' ) $outputPath = [CommonHelper]::GetOutputPath() $TranscriptPath = $outputPath + "\" + "AzSDKTestLog.txt" Start-Transcript -Path $TranscriptPath -Append -Force [CommonHelper]::Log("Importing the required AzSDK version", [MessageType]::Information) switch ($AzSDKVersion.Trim()){ "Prod"{ Import-Module AzSDK break } "Preview"{ Import-Module AzSDKPreview break } "Staging"{ Import-Module AzSDKStaging break } "Develop"{ Import-Module AzSDK -requiredversion 2.0.0.0 break } Default{ Import-Module AzSDK break } } [CommonHelper]::Log("AzSDK verification starts here", [MessageType]::Header) [CommonHelper]::Log("Collecting Test Scenario(s)/Test Case(s) to be run", [MessageType]::Information) [TestCase[]]$testcases = $null $testcases = [TestHelper]::GetTestCases($TestScenariosFileName,$TestScenarioID, $Feature, $ModuleName, $TestCaseID, $Priority) #If the value of $Settings variable is not null then run testsuite in CICD, else run testsuite in local. if($null -ne $Settings){ #Gets the test settings from $Settings variable. [TestSettings] $testsettings = [TestSettings]::new($SubscriptionId,$Settings) } else{ #Gets the test settings from local 'TestSettings.json' file. [TestSettings] $testsettings = [TestSettings]::new($SubscriptionId) } [TestCaseResult[]] $tcResults = @() if($null -ne $testcases){ if($testcases.Count -gt 0){ foreach ($testcase in $testcases){ if($testcase.Enabled){ if($testcase.AutomationStatus.trim() -ne "Manual") { [TestCaseResult] $tcResult = [TestCaseResult]::new($testcase) [CommonHelper]::Log("Running the test case:" + $testcase.TestCaseID + ":" + $testcase.Description, [MessageType]::Information) $testrunner = [TestRunner]::new($SubscriptionId,$testcase,$testsettings) $tcResult = $testrunner.RunTestCase() } else{ [TestCaseResult] $tcResult = [TestCaseResult]::new($testCase,[TestStatus]::Manual,[string]::Empty) } [TestHelper]::ExportTestCaseResult($tcResult) $tcResults += $tcResult } } [CommonHelper]::Log("Summary", [MessageType]::Header) [TestHelper]::GetTestCaseResultsSummary($testcases,$tcResults) } } else{ [CommonHelper]::Log("Could not find any test case matching your criteria. Please check the input parameters", [MessageType]::Error) } [CommonHelper]::Log("AzSDK verification ends here", [MessageType]::Header) $ResultPath = $outputPath + "\" + "AzSDKTestResult.csv" [TestHelper]::ExportTestResultsToCSV($tcResults, $ResultPath) Stop-Transcript [CommonHelper]::Log("AzSDK Test output and logs can be found at: " + $outputPath, [MessageType]::Information) return $ResultPath } |