-
Notifications
You must be signed in to change notification settings - Fork 903
/
Invoke-AuthedTests.ps1
83 lines (74 loc) · 2.69 KB
/
Invoke-AuthedTests.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
#Requires -Module @{ ModuleName = 'pester'; ModuleVersion = '5.3.1' }
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Prepares a system to test as though it was Test Kitchen.
#>
param(
# Path to place Chocolatey test related artifacts.
[string]
$TestPath = "$env:TEMP/chocolateyTests",
# Indicate to skip packaging all of the tests packages. Useful for running tests after you've performed the tests previously.
[switch]
$SkipPackaging,
# The remote repository to push packages to and to use during tests.
[string]
$RemoteRepository,
# API Key used by the remote repository for pushing packages.
[string]
$ApiKey
)
if (-not (Test-Path "$TestPath/packages") -or -not $SkipPackaging) {
if (($null -ne $RemoteRepository) -and ($null -ne $ApiKey))
$null = New-Item -Path "$TestPath/packages" -ItemType Directory -Force
# Get and pack packages
$nuspecs = Get-ChildItem -Path $PSScriptRoot/src/chocolatey.tests.integration, $PSScriptRoot/tests/packages -Recurse -Include *.nuspec
Get-ChildItem -Path $PSScriptRoot/tests/packages -Recurse -Include *.nupkg | Copy-Item -Destination "$TestPath/packages"
foreach ($file in $nuspecs) {
Write-Host "Packaging $file"
$null = choco pack $file.FullName --out "$TestPath/packages"
}
Get-ChildItem -Path $TestPath/packages | ForEach-Object {
choco push $_.FullName -s $RemoteRepository -k $ApiKey --force --allow-unofficial
}
}
try {
Push-Location $PSScriptRoot/tests
$env:PSModulePath = "$PSScriptRoot/tests;$env:PSModulePath"
Import-Module $PSScriptRoot\tests\helpers\common-helpers.psm1 -Force
$null = Invoke-Choco source add --name hermes --source $RemoteRepository
Enable-ChocolateyFeature -Name allowGlobalConfirmation
$PesterConfiguration = [PesterConfiguration]@{
Run = @{
PassThru = $true
Path = "$PSScriptRoot/tests/chocolatey-tests"
}
TestResult = @{
Enabled = $true
TestSuiteName = "Pester - Chocolatey"
}
Output = @{
Verbosity = 'Minimal'
}
Filter = @{
ExcludeTag = @(
'Background'
'Licensed'
'CCM'
'WIP'
'NonAdmin'
'Internal'
if (-not $env:VM_RUNNING -and -not $env:TEST_KITCHEN) {
'VMOnly'
}
)
}
Should = @{
ErrorAction = 'Continue'
}
}
Invoke-Pester -Configuration $PesterConfiguration
}
finally {
Pop-Location
}