Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

use Convert-ToDockerHostPath for docker tests #117

Merged
merged 10 commits into from
Dec 17, 2020
24 changes: 24 additions & 0 deletions Source/Private/Convert-ToDockerHostPath.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function Convert-ToDockerHostPath {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[String]
$Path
)

$pathOnDockerHost = $Path
if ( (Invoke-DockerCommand 'ps').StdOut | Select-String $(hostname) ) {
viktor-kaydalov marked this conversation as resolved.
Show resolved Hide resolved
# executed inside docker container $(hostname)
$dockerCommand = "inspect -f ""{{ range .Mounts }}{{ .Source }}:{{ .Destination }}{{ println }} {{ end }}"" $(hostname)"
$mounts = (Invoke-DockerCommand $dockerCommand ).StdOut.trim() | Where-Object { $_ -NotMatch "/var/lib/docker" -and $_ -NotMatch "docker.sock" -and $_ -ne '' }
viktor-kaydalov marked this conversation as resolved.
Show resolved Hide resolved
if ($mounts) {
$mounts | ForEach-Object {
if ($_.split(':')[0] -ne $_.split(':')[1]) {
# Replace $($_.split(':')[1]) with $($_.split(':')[0])
$pathOnDockerHost = $pathOnDockerHost.Replace($_.split(':')[1],$_.split(':')[0])
}
}
}
}
return $pathOnDockerHost
}
6 changes: 4 additions & 2 deletions Source/Public/Invoke-DockerTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ function Invoke-DockerTests {
}

$here = Format-AsAbsolutePath (Get-Location)
$hereOnDockerHost = Convert-ToDockerHostPath $here
$absoluteTestReportDir = Format-AsAbsolutePath ($TestReportDir)
if (!(Test-Path $absoluteTestReportDir -PathType Container)) {
New-Item $absoluteTestReportDir -ItemType Directory -Force | Out-Null
}
$absoluteTestReportDirOnDockerHost = Convert-ToDockerHostPath $absoluteTestReportDir
$osType = Find-DockerOSType
$dockerSocket = Find-DockerSocket -OsType $osType
if ($osType -ieq 'windows') {
Expand All @@ -45,8 +47,8 @@ function Invoke-DockerTests {
$report = '/report'
}
$structureCommand = "run -i" + `
" -v `"${here}:${configs}`"" + `
" -v `"${absoluteTestReportDir}:${report}`"" + `
" -v `"${hereOnDockerHost}:${configs}`"" + `
" -v `"${absoluteTestReportDirOnDockerHost}:${report}`"" + `
" -v `"${dockerSocket}:${dockerSocket}`"" + `
" 3shape/containerized-structure-test:latest test -i ${ImageName} --test-report ${report}/${TestReportName}"

Expand Down