forked from wangbo/easyai
38 lines
1.2 KiB
PowerShell
38 lines
1.2 KiB
PowerShell
$ErrorActionPreference = 'Stop'
|
|
. (Join-Path $PSScriptRoot 'Assert-RedisPersistence.ps1')
|
|
|
|
$projectRoot = Split-Path $PSScriptRoot -Parent
|
|
$expected = [System.IO.Path]::GetFullPath((Join-Path $projectRoot 'data/redis'))
|
|
$script:state = 'absent'
|
|
function docker {
|
|
$global:LASTEXITCODE = 0
|
|
switch ($args[0]) {
|
|
'info' {
|
|
if ($script:state -eq 'unavailable') { $global:LASTEXITCODE = 1 }
|
|
return
|
|
}
|
|
'container' {
|
|
if ($script:state -eq 'absent') { $global:LASTEXITCODE = 1 }
|
|
return
|
|
}
|
|
'inspect' {
|
|
switch ($script:state) {
|
|
'mounted' { return "bind|$expected" }
|
|
'wrong_mount' { return 'bind|/other/redis' }
|
|
default { return '' }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Assert-RedisPersistence -ProjectRoot $projectRoot
|
|
$script:state = 'mounted'
|
|
Assert-RedisPersistence -ProjectRoot $projectRoot
|
|
foreach ($unsafe in @('unavailable', 'no_mount', 'wrong_mount')) {
|
|
$script:state = $unsafe
|
|
$rejected = $false
|
|
try { Assert-RedisPersistence -ProjectRoot $projectRoot } catch { $rejected = $true }
|
|
if (-not $rejected) { throw "Unsafe Redis state accepted: $unsafe" }
|
|
}
|
|
Write-Host 'Redis persistence PowerShell tests passed'
|