Skip to content

Commit

Permalink
[EngSys] Test proxy (#15101)
Browse files Browse the repository at this point in the history
  • Loading branch information
seankane-msft authored Aug 12, 2021
1 parent 4723b6d commit 4aa5a96
Show file tree
Hide file tree
Showing 204 changed files with 10,927 additions and 13,358 deletions.
24 changes: 12 additions & 12 deletions eng/pipelines/templates/steps/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,34 @@ steps:
env:
GO111MODULE: 'on'
- 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'
- template: configure-proxy.yml
parameters:
ServiceDirectory: ${{ parameters.ServiceDirectory }}

- 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 $td | go-junit-report -set-exit-code > report.xml"
go test -run "^Test" -v -coverprofile coverage.txt . | go-junit-report -set-exit-code > report.xml
go test -run "^Test" -v -coverprofile coverage.txt . > temp.txt
cat temp.txt
cat temp.txt | go-junit-report -set-exit-code > 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
}
$(Build.SourcesDirectory)/eng/scripts/start-server.ps1 stop
}
displayName: 'Run Tests'
workingDirectory: '${{parameters.GoWorkspace}}'
env:
GO111MODULE: 'on'
AZURE_RECORD_MODE: 'playback'
- pwsh: |
$coverageFiles = [Collections.Generic.List[String]]@()
Expand Down
22 changes: 22 additions & 0 deletions eng/pipelines/templates/steps/configure-proxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
parameters:
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(
[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
}
}
}
Loading

0 comments on commit 4aa5a96

Please sign in to comment.