-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRun-Tests.ps1
70 lines (61 loc) · 1.37 KB
/
Run-Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env pwsh
param(
[System.Collections.ArrayList]
$modulesPath,
$testsFolderName = 'tests'
)
Set-StrictMode -Version 3
$ErrorActionPreference = "Stop"
if ($null -eq $modulesPath)
{
return
}
Import-Module Pester -Force
function Use-DockerDesktopK8s
{
$context = kubectl config current-context
if ($context -ne 'docker-desktop')
{
Write-Host 'WARNING: Switching to docker-desktop automatically to run tests'
kubectl config use-context docker-desktop
}
}
function Remove-TestFiles
{
if (Test-Path '.tmp')
{
Remove-Item -Recurse -Force '.tmp'
}
}
function Remove-PublishedTestSecrets
{
$testSecretNamePattern = 'test-*'
$testSecretNames = ((kubectl get secrets -o json) | ConvertFrom-Json).items |
ForEach-Object { $_.metadata.name } |
Where-Object { $_ -like $testSecretNamePattern }
$testSecretNames | ForEach-Object {
kubectl delete secrets $_
}
}
function Cleanup()
{
Remove-TestFiles
Remove-PublishedTestSecrets
}
Use-DockerDesktopK8s
$modules = $modulesPath | ForEach-Object {
$path = $_
$module = Get-Item $path
@{
Path = $path
TestsPath = Join-Path $module.Directory.FullName $testsFolderName
Name = $module.Name.Replace($module.Extension, '')
FileName = $module.Name
}
}
$modules | % {
$module = $_
Import-Module $module.Path -Force
Invoke-Pester -Path $module.TestsPath
}
Cleanup