File: Invoke-MockTest.ps1

package info (click to toggle)
golang-github-azure-azure-sdk-for-go 68.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 556,256 kB
  • sloc: javascript: 196; sh: 96; makefile: 7
file content (50 lines) | stat: -rw-r--r-- 1,774 bytes parent folder | download | duplicates (3)
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
#Requires -Version 7.0
param(
    [string]$inputJsonFile,
    [string]$outputJsonFile
)

. (Join-Path $PSScriptRoot .. MgmtTestLib.ps1)
Write-output "inputfile:$inputJsonFile, outfile:$outputJsonFile"
$inputstring = Get-Content $inputJsonFile | Out-String
Write-Output "input parameter: $inputstring"
$inputJson = Get-Content $inputJsonFile | Out-String | ConvertFrom-Json
$packageFolder = $inputJson.packageFolder
$packageFolder = $packageFolder -replace "\\", "/"

$runLocalMockServer = $false
if ([string]::IsNullOrEmpty($inputJson.mockServerHost)) {
    $runLocalMockServer = $true
}
Write-Host "##[command]Generate example and Mock Test " $packageFolder
Set-Location $packageFolder
Invoke-MgmtTestgen -sdkDirectory $packageFolder -autorestPath $packageFolder/autorest.md -generateMockTest -tidy -format -vet

if ($runLocalMockServer -eq $true) {
    Write-Host "Prepare Mock Server"
    PrepareMockServer
    Write-Host "Try Stop mock server"
    StopMockServer
}

Set-Location $packageFolder

Write-output "Run Mock Test"
$sdk = Get-GoModuleProperties $packageFolder
ExecuteSingleTest $sdk $runLocalMockServer

TestAndGenerateReport $packageFolder
$testoutputFile = Join-Path $packageFolder outfile.txt
$all = (Select-String -Path $testoutputFile -Pattern "=== RUN").Matches.length
$pass = (Select-String -Path $testoutputFile -Pattern "--- PASS").Matches.length
$fail = (Select-String -Path $testoutputFile -Pattern "--- FAIL").Matches.length
$coverage = (Select-String -Path $testoutputFile -Pattern "coverage: (?<coverage>.*)% of statements").Matches[0].Groups["coverage"].Value

$outputJson = [PSCustomObject]@{
    total = $all
    success = $pass
    fail = $fail
    apiCoverage = $coverage
}

$outputJson | ConvertTo-Json -depth 100 | Out-File $outputJsonFile