private/New-AutRunJob.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<#
.SYNOPSIS
Controller script that start a job on a given executable
Potential to be upgraded to tool
 
.DESCRIPTION
See documentation for more information : https://github.com/Fleid/asa.unittest
 
.PARAMETER solutionPath
Path to the solution (folder) containing both the Azure Stream Analytics folder and the unittest folder
 
.PARAMETER asaProjectName
Name of the Azure Stream Analytics project = name of the project folder = name of the query in that folder (.asaql) = name of the project description file (.asaproj)
 
.PARAMETER unittestFolder
Name of the folder containing the test fixture (folders 1_arrange, 2_act, 3_assert), usually "asaProjectName.Tests"
 
.PARAMETER testId
Timestamp of the test run (yyyyMMddHHmmss), will be used in the folder structure
 
.PARAMETER testCase
Current test to be run (001, 002, 003...)
 
.PARAMETER exePath
Path to sa.exe, usually $exePath = "$solutionPath\$unittestFolder\2_act\Microsoft.Azure.StreamAnalytics.CICD.$asaNugetVersion\tools\sa.exe"
 
.EXAMPLE
New-AutRunJob -solutionPath $solutionPath -asaProjectName $asaProjectName -unittestFolder $unittestFolder -testID $testID -testCase $testCase -exePath $exePath
#>


Function New-AutRunJob{

    [CmdletBinding(
        SupportsShouldProcess=$true,
        ConfirmImpact="Low"
        )]
    param (
        [string]$solutionPath = $(Throw "-solutionPath is required"),
        [string]$asaProjectName = $(Throw "-asaProjectName is required"),
        [string]$unittestFolder = $(Throw "-unittestFolder is required"),
        [string]$testID = $(Throw "-testID is required"),
        [string]$testCase = $(Throw "-testCase is required"),
        [string]$exePath = $(Throw "-exePath is required")
    )

    BEGIN {

        if (-not (Test-Path -Path $exePath -PathType Leaf)) {throw "No file found at $exePath"}

        $testPath = "$solutionPath\$unittestFolder\3_assert\$testID"
        if (-not (Test-Path -Path $testPath)) {throw "$testPath is not a valid path"}

    }

    PROCESS {

        if ($pscmdlet.ShouldProcess("Running $exePath"))
        {
            Start-Job -ArgumentList $exePath,$testPath,$testCase,$asaProjectName -ScriptBlock{
                param($exePath,$testPath,$testCase,$asaProjectName)
                #Can't do that since Start-Job is invoked in a separate scope with no context
                #Invoke-External -l $exePath localrun -Project "$testPath\$testCase\$asaProjectName\$asaProjectName.asaproj" -OutputPath "$testPath\$testCase"
                & $exePath localrun -Project $testPath\$testCase\$asaProjectName\$asaProjectName.asaproj -OutputPath $testPath\$testCase
            }|
            Out-Null
        }
    } #PROCESS
    END {}
}