-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include end-to-end test code coverage (#2293)
Merge code coverage from both unit and end-to-end integration tests to obtain a complete picture of correct code coverage. Also, merge code coverage from multiple platforms now that the new tool `go tool covdata` supports this. Since the end-to-end tests executes the standalone CLI binary, run `go build` with `-cover` for the go compiler to insert coverage profile statements in the compiled output. `GOCOVERDIR` is set when invoking the CLI to output coverage data to the specified directory (see [here](https://go.dev/testing/coverage/)). Thus, the CLI is compiled once with `-cover` added for running tests, then recompiled without `-cover` for release. Fixes #1996
- Loading branch information
1 parent
9c03285
commit e6ece84
Showing
8 changed files
with
171 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,7 @@ funcapp | |
functestapp | ||
functionapp | ||
GOARCH | ||
GOCOVERDIR | ||
godotenv | ||
golangci | ||
hotspot | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,60 @@ | ||
param( | ||
[string] $Timeout = '90m', | ||
[string] $CoverageFileOut = 'cover.out', | ||
[string] $Package = './...', | ||
[switch] $ShortMode | ||
[switch] $ShortMode, | ||
[string] $UnitTestCoverageDir = 'cover-unit', | ||
[string] $IntegrationTestTimeout = '90m', | ||
[string] $IntegrationTestCoverageDir = 'cover-int' | ||
) | ||
|
||
$goTest = "$(go env GOPATH)/bin/gotestsum -- -timeout $Timeout -v -coverprofile='$CoverageFileOut' $Package" | ||
$ErrorActionPreference = 'Stop' | ||
|
||
$gopath = go env GOPATH | ||
if ($LASTEXITCODE) { | ||
throw "go env GOPATH failed with exit code: $LASTEXITCODE, stdout: $gopath" | ||
} | ||
|
||
$gotestsumBinary = "gotestsum" | ||
if ($IsWindows) { | ||
$gotestsumBinary += ".exe" | ||
} | ||
|
||
$gotestsum = Join-Path $gopath "bin" $gotestsumBinary | ||
if (-not (Test-Path $gotestsum)) { | ||
throw "gotestsum is not installed at $gotestsum" | ||
} | ||
|
||
function New-EmptyDirectory { | ||
param([string]$Path) | ||
if (Test-Path $Path) { | ||
Remove-Item -Force -Recurse $Path | Out-Null | ||
} | ||
|
||
New-Item -ItemType Directory -Force -Path $Path | ||
} | ||
$unitCoverDir = New-EmptyDirectory -Path $UnitTestCoverageDir | ||
Write-Host "Running unit tests..." | ||
|
||
# --test.gocoverdir is currently a "under-the-cover" way to pass the coverage directory to a test binary | ||
# See https://github.com/golang/go/issues/51430#issuecomment-1344711300 | ||
# | ||
# This may be improved in go1.21 with an official 'go test' flag. | ||
& $gotestsum -- ./... -short -v -cover -args --test.gocoverdir="$($unitCoverDir.FullName)" | ||
if ($LASTEXITCODE) { | ||
exit $LASTEXITCODE | ||
} | ||
|
||
if ($ShortMode) { | ||
$goTest = $goTest + " -short" | ||
Write-Host "Short mode, skipping integration tests" | ||
exit 0 | ||
} | ||
|
||
Invoke-Expression $goTest | ||
Write-Host "Running integration tests..." | ||
$intCoverDir = New-EmptyDirectory -Path $IntegrationTestCoverageDir | ||
|
||
# GOCOVERDIR enables any binaries (in this case, azd.exe) built with '-cover', | ||
# to write out coverage output to the specific directory. | ||
$env:GOCOVERDIR = $intCoverDir.FullName | ||
|
||
& $gotestsum -- ./test/... -v -timeout $IntegrationTestTimeout | ||
if ($LASTEXITCODE) { | ||
exit $LASTEXITCODE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
parameters: | ||
- name: Artifacts | ||
type: object | ||
|
||
steps: | ||
- ${{ each artifact in parameters.Artifacts }}: | ||
- task: DownloadPipelineArtifact@2 | ||
inputs: | ||
artifact: ${{ artifact }} | ||
path: ${{ artifact }} |