153 lines
4.7 KiB
PowerShell
153 lines
4.7 KiB
PowerShell
. $PSScriptRoot\..\..\Load-PesterModules.ps1
|
|
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.tests\.', '.'
|
|
$functionPath = Join-Path -Path $here -ChildPath $sut
|
|
|
|
# Have to do this to use the private function for Set-AppSettingPrivate
|
|
# Write-Host "Overriding SUT: $functionPath"
|
|
# Import-Module $functionPath -Force
|
|
$moduleForMock = "Alkami.PowerShell.Configuration"
|
|
|
|
Describe "Remove-AppSetting" -Tag "Integration" {
|
|
|
|
# Temp file to write content to
|
|
$fakeConfigFile = Join-Path $TestDrive "fake.config"
|
|
|
|
New-Item -ItemType Directory $TestDrive -ErrorAction SilentlyContinue | Out-Null
|
|
Write-Host ("Using temp path: $TestDrive for tests")
|
|
|
|
Context "Removes from both settings blocks two appSettings sections are present" {
|
|
|
|
$appSettingsTestContents = @"
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
<configuration>
|
|
<location path="." inheritInChildApplications="false">
|
|
<appSettings>
|
|
<add key="EnableMobileSite" value="true"/>
|
|
<add key="ForceAlwaysMobile" value="false"/>
|
|
<add key="EnableRegistrationErrorMessage" value="false"/>
|
|
<add key="NewRelic.AppName" value="Alkami Test Web"/>
|
|
<add key="AssetServerHost" value=""/>
|
|
<add key="IgnoreSecureConnectionRequirement" value="false"/>
|
|
<add key="ForceUseOfProductionAssetsInDebug" value="true"/>
|
|
<add key="ShouldDisplayUncaughtExceptions" value="false"/>
|
|
<add key="AlkamiClientMaxConnections" value="50"/>
|
|
<add key="aspnet:MaxJsonDeserializerMembers" value="50000" />
|
|
</appSettings>
|
|
</location>
|
|
<appSettings>
|
|
<add key="EagleEyeURL" value="eagleeye.dev.alkamitech.com" />
|
|
<add key="SubscriptionServiceMachine" value="localhost" />
|
|
<add key="NonDatabaseMicroServiceAccount" value="CORP\dev.micro$" />
|
|
<add key="MetalsmithURL" value="metalsmith.dev.alkamitech.com" />
|
|
<add key="Broadcasters" value="" />
|
|
<add key="DatabaseMicroServiceAccount" value="CORP\dev.dbms$" />
|
|
<add key="aspnet:MaxJsonDeserializerMembers" value="60000" />
|
|
</appSettings>
|
|
</configuration>
|
|
"@
|
|
|
|
$appSettingsTestContents | Out-File $fakeConfigFile -Force
|
|
|
|
Remove-AppSetting -Path $fakeConfigFile -Key "aspnet:MaxJsonDeserializerMembers" -Force
|
|
|
|
$value = (Get-AppSetting -Path $fakeConfigFile -key "aspnet:MaxJsonDeserializerMembers")
|
|
|
|
It "value didn't exist to retrieve, should be `$null" {
|
|
$value | Should -Be $null
|
|
}
|
|
}
|
|
|
|
Context "Does not throw on a bad path" {
|
|
|
|
{Remove-AppSetting -Path "C:\TotallyNotARealPath\TotallyNotARealConfig.config" -Key "Not a real key value"} | Should -Not -Throw
|
|
}
|
|
|
|
Context "Handles more than one value found" {
|
|
|
|
$appSettingsTestContents = @"
|
|
<configuration>
|
|
<appSettings>
|
|
<add key="FakeSetting" value="FakeValueOriginal" />
|
|
<add key="FakeSetting" value="FakeValueDupe" />
|
|
</appSettings>
|
|
</configuration>
|
|
"@
|
|
|
|
$appSettingsTestContents | Out-File $fakeConfigFile -Force
|
|
|
|
Remove-AppSetting -Path $fakeConfigFile -Key "FakeSetting"
|
|
|
|
It "still got deleted" {
|
|
(Get-AppSetting -Path $fakeConfigFile -key "FakeSetting") | Should -Be $null
|
|
}
|
|
}
|
|
|
|
Context "Perfectly happy with no appSettings node" {
|
|
|
|
$appSettingsTestContents = @"
|
|
<configuration>
|
|
<appSettings2>
|
|
<add key="FakeSetting" value="FakeValue" />
|
|
</appSettings2>
|
|
</configuration>
|
|
"@
|
|
|
|
$appSettingsTestContents | Out-File $fakeConfigFile -Force
|
|
|
|
Remove-AppSetting -Path $fakeConfigFile -Key "FakeSetting"
|
|
|
|
It "doesn't do anything if the key doesn't exist" {
|
|
(Get-AppSetting -Path $fakeConfigFile -key "FakeSetting") | Should -Be $null
|
|
}
|
|
}
|
|
|
|
Context "Throws an error if the configuration Node doesn't exist" {
|
|
|
|
$appSettingsTestContents = @"
|
|
"@
|
|
|
|
$appSettingsTestContents | Out-File $fakeConfigFile -Force
|
|
|
|
It "can't work with a malformed file" {
|
|
{Remove-AppSetting -Path $fakeConfigFile -Key "FakeSetting"} | Should -Throw
|
|
}
|
|
}
|
|
|
|
Context "App Setting Key Does Not Exist" {
|
|
|
|
$appSettingsTestContents = @"
|
|
<configuration>
|
|
<appSettings>
|
|
</appSettings>
|
|
</configuration>
|
|
"@
|
|
|
|
$appSettingsTestContents | Out-File $fakeConfigFile -Force
|
|
|
|
Remove-AppSetting -Path $fakeConfigFile -Key "FakeSetting"
|
|
|
|
It "when there is no existing key it doesn't break" {
|
|
Get-AppSetting -Path $fakeConfigFile -key "FakeSetting" | Should -Be $null
|
|
}
|
|
}
|
|
|
|
Context "Does a happy path" {
|
|
|
|
$appSettingsTestContents = @"
|
|
<configuration>
|
|
<appSettings>
|
|
<add key="FakeSetting" value="FakeValue" />
|
|
</appSettings>
|
|
</configuration>
|
|
"@
|
|
$appSettingsTestContents | Out-File $fakeConfigFile -Force
|
|
|
|
Remove-AppSetting -Path $fakeConfigFile -Key "FakeSetting"
|
|
|
|
It "deleted what it should have" {
|
|
(Get-AppSetting -Path $fakeConfigFile -key "FakeSetting") | Should -Be $null
|
|
}
|
|
}
|
|
}
|