Skip to content

Commit

Permalink
chore: add function Test-RunningInCIorTestEnvironment to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
JuReMq authored and xxthunder committed Jul 1, 2024
1 parent 6617fdc commit 0dc0f7c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
25 changes: 18 additions & 7 deletions tests/utils.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ BeforeAll {
Set-Alias Main out-null
. ".\$sut"
Remove-Item Alias:Main

class ComparableHashTable : Hashtable {
ComparableHashTable($obj) : base($obj) {}
[string] ToString() {
return ($this | ConvertTo-Json)
}
}
}

Describe "Invoke-CommandLine" {
Expand Down Expand Up @@ -77,3 +70,21 @@ Describe "Invoke-CommandLine" {
Should -Invoke -CommandName Write-Error -Exactly 0
}
}

Describe "Test-RunningInCIorTestEnvironment" {
It "shall return true when running in a CI or test environment" {
$Env:PYTEST_CURRENT_TEST="1"
$Env:GITHUB_ACTIONS=""
$Env:JENKINS_URL=""

Test-RunningInCIorTestEnvironment | Should -Be $true
}

It "shall return false when not running in a CI or test environment" {
$Env:PYTEST_CURRENT_TEST=""
$Env:GITHUB_ACTIONS=""
$Env:JENKINS_URL=""

Test-RunningInCIorTestEnvironment | Should -Be $false
}
}
4 changes: 4 additions & 0 deletions utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,7 @@ function CloneOrPullGitRepo {
Pop-Location
}
}

function Test-RunningInCIorTestEnvironment {
return [Boolean]($Env:JENKINS_URL -or $Env:PYTEST_CURRENT_TEST -or $Env:GITHUB_ACTIONS)
}

0 comments on commit 0dc0f7c

Please sign in to comment.