-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvoke-PSDifyPester.ps1
121 lines (114 loc) · 3.72 KB
/
Invoke-PSDifyPester.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
param (
[String[]] $Env = @(),
[Int[]] $Ps = @(),
[String[]] $Tag = @()
)
# load environment variables
. (Join-Path -Path (Split-Path -Path $PSScriptRoot) -ChildPath "Tests/.env.ps1")
# define test environments
$Environments = @(
@{
Id = "cloud-prod"
Mode = "cloud"
Server = $env:PSDIFY_TEST_CLOUD_PROD_SERVER
ApiServer = $env:PSDIFY_TEST_CLOUD_PROD_API_SERVER
Email = $env:PSDIFY_TEST_CLOUD_PROD_EMAIL
},
@{
Id = "community-release"
Mode = "community"
Version = "1.0.0"
Env = "env_release.env"
},
@{
Id = "community-main"
Mode = "community"
Version = "main"
Override = "compose_main.yaml"
Env = "env_main.env"
}
)
# define powershell executables
$Executables = @(
@{
Version = 5
Executable = "powershell.exe"
}
@{
Version = 7
Executable = "pwsh.exe"
}
)
# define available tags in tests
$AvailableTags = @("init", "auth", "member", "plugin", "model", "systemmodel", "knowledge", "document", "app", "chat")
# apply filters
if ($Env) {
if ($Env | Where-Object { $Environments.Id -notcontains $_ }) {
throw "Invalid environment ids: $($Env -join ', ')"
}
$Environments = $Environments | Where-Object { $Env -contains $_.Id }
}
if ($Ps) {
if ($Ps | Where-Object { $Executables.Version -notcontains $_ }) {
throw "Invalid powershell versions: $($Ps -join ', ')"
}
$Executables = $Executables | Where-Object { $Ps -contains $_.Version }
}
if ($Tag) {
if ($Tag | Where-Object { $AvailableTags -notcontains $_ }) {
throw "Invalid tags: $($Tag -join ', ')"
}
$JoinedTags = $Tag -join ", "
}
# list test patters
Write-Host "Test patterns:" -ForegroundColor Green
foreach ($Environment in $Environments) {
foreach ($Executable in $Executables) {
if ($Tag) {
$TagString = $JoinedTags
}
else {
$TagString = "all tags"
}
Write-Host " - $($Environment.Id) on v$($Executable.Version) ($($TagString))" -ForegroundColor Cyan
}
}
# invoke tests
foreach ($Environment in $Environments) {
try {
$env:PSDIFY_TEST_OVERRIDE_MODE = $Environment.Mode
$env:PSDIFY_TEST_OVERRIDE_VERSION = $Environment.Version
$env:PSDIFY_TEST_OVERRIDE_SERVER = $Environment.Server
$env:PSDIFY_TEST_OVERRIDE_API_SERVER = $Environment.ApiServer
$env:PSDIFY_TEST_OVERRIDE_EMAIL = $Environment.Email
if ($Environment.Override) {
$env:PSDIFY_TEST_OVERRIDE_OVERRIDE_FILE = $Environment.Override
}
else {
$env:PSDIFY_TEST_OVERRIDE_OVERRIDE_FILE = "none"
}
if ($Environment.Env) {
$env:PSDIFY_TEST_OVERRIDE_ENV_FILE = $Environment.Env
}
else {
$env:PSDIFY_TEST_OVERRIDE_ENV_FILE = "none"
}
foreach ($Executable in $Executables) {
& $Executable.Executable -NoProfile -ExecutionPolicy Bypass -Command {
param(
[String] $Tag = ""
)
$Tags = $Tag -split "," | ForEach-Object { $_.Trim() }
Invoke-Pester -Output Detailed -Tag $Tags
} -args $JoinedTags
}
}
finally {
$env:PSDIFY_TEST_OVERRIDE_MODE = $null
$env:PSDIFY_TEST_OVERRIDE_VERSION = $null
$env:PSDIFY_TEST_OVERRIDE_SERVER = $null
$env:PSDIFY_TEST_OVERRIDE_API_SERVER = $null
$env:PSDIFY_TEST_OVERRIDE_EMAIL = $null
$env:PSDIFY_TEST_OVERRIDE_ENV_FILE = $null
}
}