Skip to content

Commit

Permalink
Merge pull request #929 from dataplat/fixes-912
Browse files Browse the repository at this point in the history
unit tests and correct variable - fixes #912
  • Loading branch information
SQLDBAWithABeard authored Mar 28, 2023
2 parents 277886e + d6f5ef6 commit cd8b491
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion source/checks/Instancev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 3 additions & 5 deletions source/functions/Export-DbcConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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
}
}
29 changes: 29 additions & 0 deletions tests/Unit/Public/Export-DbcConfig.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit cd8b491

Please sign in to comment.