Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Internal] Add methods for configuring tests to work with test proxy #15259

Merged
merged 50 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
43e875b
moving into a separate PR to merge with main
seankane-msft Aug 9, 2021
ce8dfa6
adding yml and script to start server
seankane-msft Aug 10, 2021
8b716cd
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-go into…
seankane-msft Aug 10, 2021
2d34f68
renaming examples for go vet
seankane-msft Aug 10, 2021
858f929
fixing stop command
seankane-msft Aug 10, 2021
0e78180
merge conflicts
seankane-msft Aug 10, 2021
abfd495
skipping problematic tests
seankane-msft Aug 10, 2021
ae991cc
bens feedback
seankane-msft Aug 10, 2021
ab34658
testproxy changes from track2-tables
seankane-msft Aug 12, 2021
464bb90
simplification
seankane-msft Aug 12, 2021
5170886
fix
seankane-msft Aug 12, 2021
1bb884d
updating to work with common
seankane-msft Aug 19, 2021
6355a03
getting main build-test.yml files
seankane-msft Aug 19, 2021
ccf37a8
whitespace
seankane-msft Aug 19, 2021
29bed05
adding tests for test proxy infra
seankane-msft Aug 19, 2021
f33a232
setting azure_record_mode to playback
seankane-msft Aug 19, 2021
0ea12a0
setting proxy cert variable
seankane-msft Aug 19, 2021
def4c27
prepend ./ to testId, use testId to determine full path from repo root
seankane-msft Aug 19, 2021
42e667a
workaround for magically dissappearing files
seankane-msft Aug 19, 2021
0455394
more tests
seankane-msft Aug 19, 2021
0f87900
dropping coverage
seankane-msft Aug 19, 2021
2921e52
removing azcore dependent code
seankane-msft Aug 23, 2021
66158cb
undoing changes to eng files
seankane-msft Aug 23, 2021
3de4936
unexporting a couple things
seankane-msft Aug 23, 2021
5feef38
fixed issue with deleting recordings
seankane-msft Aug 24, 2021
e752a6f
adding additional tests
seankane-msft Aug 24, 2021
8ec2e2a
dropping code coverage
seankane-msft Aug 24, 2021
32c6570
cleanup
seankane-msft Aug 24, 2021
297b899
richards comments
seankane-msft Aug 24, 2021
ecc9563
improving coverage
seankane-msft Aug 25, 2021
7867ab1
fixing recording options test
seankane-msft Aug 25, 2021
1453a3d
inching closer
seankane-msft Aug 25, 2021
2cee416
a
seankane-msft Aug 25, 2021
b3f7949
dropping coverage 1%, have every inch of new code tested
seankane-msft Aug 26, 2021
bd98736
adding test case for backwards slash path
seankane-msft Aug 26, 2021
9ca55c8
no newline
seankane-msft Aug 26, 2021
9421675
fixing test
seankane-msft Aug 26, 2021
e2b0ded
allowing parallel tests
seankane-msft Aug 26, 2021
6c3d638
removing snippet
seankane-msft Aug 26, 2021
b62e797
undoing change to config
seankane-msft Aug 26, 2021
f40b00d
Merge branch 'main' into test-proxy-main
seankane-msft Aug 26, 2021
a009528
fixing armcore link
seankane-msft Aug 31, 2021
2c8e939
Merge branch 'test-proxy-main' of https://github.com/seankane-msft/az…
seankane-msft Aug 31, 2021
cdca98a
Merge branch 'main' into test-proxy-main
seankane-msft Aug 31, 2021
2d96846
undoing changes to migration guide
seankane-msft Aug 31, 2021
1fd955b
merge conflict
seankane-msft Aug 31, 2021
d3719af
Update sdk/internal/recording/recordings/TestUriSanitizer.json
seankane-msft Sep 1, 2021
0a56f19
Update sdk/internal/recording/recordings/TestStartStop.json
seankane-msft Sep 1, 2021
6aba571
richards comments
seankane-msft Sep 2, 2021
a20591d
Merge branch 'test-proxy-main' of https://github.com/seankane-msft/az…
seankane-msft Sep 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 74 additions & 47 deletions eng/pipelines/templates/steps/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,94 @@ parameters:
Scope: 'sdk/...'
Image: ''
GoVersion: ''
RunTests: false

steps:

- pwsh: ./eng/scripts/build.ps1
- pwsh: |
go get github.com/jstemmer/go-junit-report
go get github.com/axw/gocov/gocov
go get github.com/AlekSi/gocov-xml
go get github.com/matm/gocov-html
go get -u github.com/wadey/gocovmerge
displayName: "Install Coverage and Junit Dependencies"
workingDirectory: '${{parameters.GoWorkspace}}'

- pwsh: |
$modDirs = (./eng/scripts/get_module_dirs.ps1 -serviceDir $(SCOPE))
foreach ($md in $modDirs) {
pushd $md
Write-Host "##[command]Executing go build -v ./... in $md"
go build -v ./...
}
displayName: 'Build'
workingDirectory: '${{parameters.GoWorkspace}}'
env:
GO111MODULE: 'on'

- pwsh: ./eng/scripts/build.ps1 -vet -skipBuild
- pwsh: |
$modDirs = (./eng/scripts/get_module_dirs.ps1 -serviceDir $(SCOPE))
foreach ($md in $modDirs) {
pushd $md
Write-Host "##[command]Executing go vet ./... in $md"
go vet ./...
}
displayName: 'Vet'
workingDirectory: '${{parameters.GoWorkspace}}'
env:
GO111MODULE: 'on'

- ${{ if eq(parameters.RunTests, 'true') }}:
- pwsh: |
go get github.com/jstemmer/go-junit-report
go get github.com/axw/gocov/gocov
go get github.com/AlekSi/gocov-xml
go get github.com/matm/gocov-html
go get -u github.com/wadey/gocovmerge
displayName: "Install Coverage and Junit Dependencies"
workingDirectory: '${{parameters.GoWorkspace}}'
- template: configure-proxy.yml
parameters:
ServiceDirectory: ${{ parameters.ServiceDirectory }}

- pwsh: |
$testDirs = (./eng/scripts/get_test_dirs.ps1 -serviceDir $(SCOPE))
foreach ($td in $testDirs) {
pushd $td
Write-Host "##[command]Executing 'go test -run "^Test" -v -coverprofile coverage.txt .' in $td"
go test -run "^Test" -v -coverprofile coverage.txt . | Tee-Object -FilePath outfile.txt
if ($LASTEXITCODE) { exit $LASTEXITCODE }
cat outfile.txt | go-junit-report > report.xml
# if no tests were actually run (e.g. examples) delete the coverage file so it's omitted from the coverage report
if (Select-String -path ./report.xml -pattern '<testsuites></testsuites>' -simplematch -quiet) {
Write-Host "##[command]Deleting empty coverage file"
rm coverage.txt
}
- pwsh: |
$testDirs = (./eng/scripts/get_test_dirs.ps1 -serviceDir $(SCOPE))
foreach ($td in $testDirs) {
pushd $td
$(Build.SourcesDirectory)/eng/scripts/start-server.ps1 start
Write-Host "##[command]Executing 'go test -run "^Test" -v -coverprofile coverage.txt .' in $td"
go test -run "^Test" -v -coverprofile coverage.txt . | Tee-Object -FilePath outfile.txt
if ($LASTEXITCODE) { exit $LASTEXITCODE }
cat outfile.txt | go-junit-report > report.xml
# if no tests were actually run (e.g. examples) delete the coverage file so it's omitted from the coverage report
if (Select-String -path ./report.xml -pattern '<testsuites></testsuites>' -simplematch -quiet) {
Write-Host "##[command]Deleting empty coverage file"
rm coverage.txt
}
displayName: 'Run Tests'
workingDirectory: '${{parameters.GoWorkspace}}'
env:
GO111MODULE: 'on'

- pwsh: ../eng/scripts/create_coverage.ps1 ${{parameters.ServiceDirectory}}
displayName: 'Generate Coverage XML'
workingDirectory: '${{parameters.GoWorkspace}}sdk'
}
$(Build.SourcesDirectory)/eng/scripts/start-server.ps1 stop
displayName: 'Run Tests'
workingDirectory: '${{parameters.GoWorkspace}}'
env:
GO111MODULE: 'on'
AZURE_RECORD_MODE: 'playback'
seankane-msft marked this conversation as resolved.
Show resolved Hide resolved

- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testRunner: JUnit
testResultsFiles: '${{parameters.GoWorkspace}}sdk/**/report.xml'
testRunTitle: 'Go ${{ parameters.GoVersion }} on ${{ parameters.Image }}'
failTaskOnFailedTests: true
- pwsh: |
$coverageFiles = [Collections.Generic.List[String]]@()
Get-Childitem -recurse -path $(SCOPE) -filter coverage.txt | foreach-object {
seankane-msft marked this conversation as resolved.
Show resolved Hide resolved
$covFile = $_.FullName
Write-Host "Adding $covFile to the list of code coverage files"
$coverageFiles.Add($covFile)
}
gocovmerge $coverageFiles > mergedCoverage.txt
gocov convert ./mergedCoverage.txt > ./coverage.json
# gocov converts rely on standard input
Get-Content ./coverage.json | gocov-xml > ./coverage.xml
Get-Content ./coverage.json | gocov-html > ./coverage.html
displayName: 'Generate Coverage XML'
workingDirectory: '${{parameters.GoWorkspace}}sdk'
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testRunner: JUnit
testResultsFiles: '${{parameters.GoWorkspace}}sdk/**/report.xml'
testRunTitle: 'Go ${{ parameters.GoVersion }} on ${{ parameters.Image }}'
failTaskOnFailedTests: true

- task: PublishCodeCoverageResults@1
condition: succeededOrFailed()
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '${{parameters.GoWorkspace}}sdk/coverage.xml'
additionalCodeCoverageFiles: '${{parameters.GoWorkspace}}sdk/coverage.html'
failIfCoverageEmpty: true
- task: PublishCodeCoverageResults@1
condition: succeededOrFailed()
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '${{parameters.GoWorkspace}}sdk/coverage.xml'
additionalCodeCoverageFiles: '${{parameters.GoWorkspace}}sdk/coverage.html'
failIfCoverageEmpty: true
18 changes: 18 additions & 0 deletions eng/pipelines/templates/steps/configure-proxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
parameters:
seankane-msft marked this conversation as resolved.
Show resolved Hide resolved
ServiceDirectory: ''

steps:
- pwsh: |
$certUriPfx = "https://github.com/Azure/azure-sdk-tools/raw/main/tools/test-proxy/docker/dev_certificate/dotnet-devcert.pfx"
$certUriCrt = "https://github.com/Azure/azure-sdk-tools/raw/main/tools/test-proxy/docker/dev_certificate/dotnet-devcert.crt"
$certLocationPfx = "$(Build.SourcesDirectory)/dotnet-devcert.pfx"
$certLocationCrt = "$(Build.SourcesDirectory)/dotnet-devcert.crt"
Invoke-WebRequest `
-Uri $certUriPfx `
-OutFile $certLocationPfx -UseBasicParsing
Invoke-WebRequest `
-Uri $certUriCrt `
-OutFile $certLocationCrt -UseBasicParsing
dotnet dev-certs https --clean --import $certLocationPfx -p "password"
Write-Host "##vso[task.setvariable variable=PROXY_CERT]$certLocationCrt"
displayName: 'Download and Trust Certificate'
66 changes: 66 additions & 0 deletions eng/scripts/start-server.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
param(
seankane-msft marked this conversation as resolved.
Show resolved Hide resolved
[ValidateSet("start", "stop")]
[String]
$mode,
[String]
$targetFolder = "."
)

try {
docker --version | Out-Null
}
catch {
Write-Error "A invocation of docker --version failed. This indicates that docker is not properly installed or running."
Write-Error "Please check your docker invocation and try running the script again."
}

$repoRoot = (Resolve-Path $targetFolder).Path.Replace("`\", "/")
Write-Host $repoRoot

$CONTAINER_NAME = "ambitious_azsdk_test_proxy"
$IMAGE_SOURCE = "azsdkengsys.azurecr.io/engsys/testproxy-lin:1037115"
$Initial = ""

if ($IsWindows -and $env:TF_BUILD){
$IMAGE_SOURCE = "azsdkengsys.azurecr.io/engsys/testproxy-win:1037115"
$Initial = "C:"
}

function Get-Proxy-Container(){
return (docker container ls -a --format "{{ json . }}" --filter "name=$CONTAINER_NAME" `
| ConvertFrom-Json `
| Select-Object -First 1)
}

if ($mode -eq "start"){
$proxyContainer = Get-Proxy-Container

# if we already have one, we just need to check the state
if($proxyContainer){
if ($proxyContainer.State -eq "running")
{
Write-Host "Discovered an already running instance of the test-proxy!. Exiting"
exit(0)
}
}
# else we need to create it
else {
Write-Host "Attempting creation of Docker host $CONTAINER_NAME"
Write-Host "docker container create -v `"${repoRoot}:${Initial}/etc/testproxy`" -p 5001:5001 -p 5000:5000 --name $CONTAINER_NAME $IMAGE_SOURCE"
docker container create -v "${repoRoot}:${Initial}/etc/testproxy" -p 5001:5001 -p 5000:5000 --name $CONTAINER_NAME $IMAGE_SOURCE
}

Write-Host "Attempting start of Docker host $CONTAINER_NAME"
docker container start $CONTAINER_NAME
}

if ($mode -eq "stop"){
$proxyContainer = Get-Proxy-Container

if($proxyContainer){
if($proxyContainer.State -eq "running"){
Write-Host "Found a running instance of $CONTAINER_NAME, shutting it down."
docker container stop $CONTAINER_NAME
}
}
}
4 changes: 2 additions & 2 deletions sdk/azcore/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func ExampleRequest_SetBody() {
}

// false positive by linter
func ExampleLogger_SetClassifications() { //nolint:govet
func ExampleSetClassifications() { //nolint:govet
// only log HTTP requests and responses
azcore.SetClassifications(azcore.LogRequest, azcore.LogResponse)
}

// false positive by linter
func ExampleLogger_SetListener() { //nolint:govet
func ExampleSetListener() { //nolint:govet
// a simple logger that writes to stdout
azcore.SetListener(func(cls azcore.LogClassification, msg string) {
fmt.Printf("%s: %s\n", cls, msg)
Expand Down
Loading