76 lines
2.9 KiB
PowerShell
76 lines
2.9 KiB
PowerShell
# Get-GiteaConfiguration.Tests.ps1
|
|
|
|
# Import the module under test
|
|
$modulePath = Join-Path -Path $PSScriptRoot -ChildPath '..\PS-GiteaUtilities.psm1'
|
|
Import-Module -Name $modulePath -Force
|
|
|
|
Describe 'Get-GiteaConfiguration' {
|
|
|
|
Context 'When configuration file exists' {
|
|
BeforeEach {
|
|
# Mock filesystem and import
|
|
Mock -CommandName Test-Path -ModuleName PS-GiteaUtilities -MockWith { $true }
|
|
Mock -CommandName Import-Clixml -ModuleName PS-GiteaUtilities -MockWith {
|
|
return @{
|
|
giteaURL = 'https://gitea.example.com'
|
|
token = 'ABC123'
|
|
}
|
|
}
|
|
}
|
|
|
|
It 'Should import configuration and return it' {
|
|
$result = Get-GiteaConfiguration
|
|
|
|
$result | Should -Not -BeNullOrEmpty
|
|
$result.giteaURL | Should -Be 'https://gitea.example.com'
|
|
$result.token | Should -Be 'ABC123'
|
|
}
|
|
|
|
It 'Should create global variables when LoadVariables is used' {
|
|
# Remove any existing variables first
|
|
Remove-Variable -Name giteaURL, token -Scope Global -ErrorAction SilentlyContinue
|
|
|
|
Get-GiteaConfiguration -LoadVariables
|
|
|
|
(Get-Variable -Name giteaURL -Scope Global).Value | Should -Be 'https://gitea.example.com'
|
|
(Get-Variable -Name token -Scope Global).Value | Should -Be 'ABC123'
|
|
}
|
|
|
|
It 'Should overwrite existing variables when Force is used' {
|
|
# Set initial variables
|
|
Set-Variable -Name giteaURL -Value 'OldURL' -Scope Global
|
|
Set-Variable -Name token -Value 'OldToken' -Scope Global
|
|
|
|
Get-GiteaConfiguration -LoadVariables -Force
|
|
|
|
(Get-Variable -Name giteaURL -Scope Global).Value | Should -Be 'https://gitea.example.com'
|
|
(Get-Variable -Name token -Scope Global).Value | Should -Be 'ABC123'
|
|
}
|
|
|
|
It 'Should not overwrite existing variables without Force' {
|
|
# Set initial variables
|
|
Set-Variable -Name giteaURL -Value 'OldURL' -Scope Global
|
|
Set-Variable -Name token -Value 'OldToken' -Scope Global
|
|
|
|
Get-GiteaConfiguration -LoadVariables
|
|
|
|
(Get-Variable -Name giteaURL -Scope Global).Value | Should -Be 'OldURL'
|
|
(Get-Variable -Name token -Scope Global).Value | Should -Be 'OldToken'
|
|
}
|
|
}
|
|
|
|
Context 'When configuration file does not exist' {
|
|
BeforeEach {
|
|
Mock -CommandName Test-Path -ModuleName PS-GiteaUtilities -MockWith { $false }
|
|
Mock -CommandName Write-Warning -ModuleName PS-GiteaUtilities -MockWith { }
|
|
}
|
|
|
|
It 'Should return null and warn the user' {
|
|
$result = Get-GiteaConfiguration
|
|
|
|
$result | Should -BeNullOrEmpty
|
|
Assert-MockCalled -CommandName Write-Warning -ModuleName PS-GiteaUtilities -Times 1
|
|
}
|
|
}
|
|
}
|