Skip to content

Commit

Permalink
(temp) Adding a script to try running tests locally
Browse files Browse the repository at this point in the history
  • Loading branch information
corbob committed Jul 5, 2023
1 parent fe5898b commit a9b8b3e
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions Invoke-AuthedTests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#Requires -Module @{ ModuleName = 'pester'; ModuleVersion = '5.3.1' }
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Prepares a system to test as thought 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,

[Parameter(Mandatory)]
[string]
$RemoteRepository,

[Parameter(Mandatory)]
[string]
$ApiKey
)

if (-not (Test-Path "$TestPath/packages") -or -not $SkipPackaging) {
$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"
}
}

# Need to push up packages here
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 = 'Detailed'
}
Filter = @{
ExcludeTag = @(
'Background'
'Licensed'
'CCM'
'WIP'
'NonAdmin'
'Internal'
if (-not $env:VM_RUNNING -and -not $env:TEST_KITCHEN) {
'VMOnly'
}
)
Tag = @(
'InstallCommand'
'InfoCommand'
)
}
Should = @{
ErrorAction = 'Continue'
}
}

Invoke-Pester -Configuration $PesterConfiguration
}
finally {
Pop-Location
}

0 comments on commit a9b8b3e

Please sign in to comment.