diff --git a/source/checks/Instancev5.Tests.ps1 b/source/checks/Instancev5.Tests.ps1 index 59bcfd2b..c87f6fa0 100644 --- a/source/checks/Instancev5.Tests.ps1 +++ b/source/checks/Instancev5.Tests.ps1 @@ -373,7 +373,7 @@ Describe "Network Latency" -Tag NetworkLatency, Connectivity, Medium, Instance - } } -Describe "Linked Servers" -Tags LinkedServerConnection, Connectivity, Medium, Instance -ForEach $InstancesToTest { +Describe "Linked Servers" -Tag LinkedServerConnection, Connectivity, Medium, Instance -ForEach $InstancesToTest { $skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.linkedserverconnection' }).Value Context "Testing Linked Server Connection on <_.Name>" { It "should be able to connect to <_.LinkedServerName> for Linked Server <_.RemoteServer> on <_.InstanceName>" -Skip:$skip -ForEach @($Psitem.LinkedServerResults) { diff --git a/source/functions/Export-DbcConfig.ps1 b/source/functions/Export-DbcConfig.ps1 index 43f3aa6a..8b2c52a2 100644 --- a/source/functions/Export-DbcConfig.ps1 +++ b/source/functions/Export-DbcConfig.ps1 @@ -42,12 +42,11 @@ function Export-DbcConfig { ) Write-PSFMessage "Testing if $Path exists" -Level Verbose - if (Test-Path -Path $file) { + if (Test-Path -Path $Path) { if (-not $Force) { Write-PSFMessage "Uh-Oh - File $Path exists - use the Force parameter to overwrite (even if your name is not Luke!)" -Level Significant Return '' - } - else { + } else { Write-PSFMessage "File $Path exists and will be overwritten " -Level Verbose } } @@ -56,8 +55,7 @@ function Export-DbcConfig { # support for Invoke-Item Get-Item -Path $Path Write-PSFMessage -Message "Wrote file to $Path" -Level Verbose - } - catch { + } catch { Stop-PSFFunction -Message $_ -Target $Path } } diff --git a/tests/Unit/Public/Export-DbcConfig.Tests.ps1 b/tests/Unit/Public/Export-DbcConfig.Tests.ps1 new file mode 100644 index 00000000..938b287a --- /dev/null +++ b/tests/Unit/Public/Export-DbcConfig.Tests.ps1 @@ -0,0 +1,29 @@ + +Describe "Export-DbcConfig Unit Tests" -Tags "IntegrationTests" { + Context "Command executes properly and returns proper info" { + BeforeAll { + $localapp = Get-DbcConfigValue -Name 'app.localapp' + Remove-Item "$localapp\config.json" -ErrorAction SilentlyContinue + Export-DbcConfig -Path 'TestDrive:\config.json' + } + AfterAll { + Remove-Item "$localapp\config.json" -ErrorAction SilentlyContinue + } + It "Should not throw" { + { Export-DbcConfig } | Should -Not -Throw + } + + It "outputs default file without errors" { + (Get-ChildItem "$localapp\config.json" -ErrorAction SilentlyContinue) -ne $null | Should -BeTrue + } + + It "outputs a named file without errors" { + Test-Path 'TestDrive:\config.json' | Should -BeTrue + } + + It "outputs an object" { + $o = Export-DbcConfig -Force + $o | Get-Member -Name Open | Should -Not -BeNullOrEmpty + } + } +} \ No newline at end of file