Skip to content

Commit

Permalink
general bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee committed Mar 30, 2018
1 parent aa8999e commit 6687b5e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ before_test:

# Setting up the local SQL Server environments
- ps: .\Tests\appveyor.sqlserver.ps1
- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
#- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))


test_script:
Expand Down
13 changes: 9 additions & 4 deletions functions/Export-DbaAvailabilityGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,15 @@ function Export-DbaAvailabilityGroup {
# $ag | Select-Object -Property * | Out-File -FilePath $outFile -Encoding ASCII -Append

"*/" | Out-File -FilePath $outFile -Encoding ASCII -Append

# Script the AG
$ag.Script() | Out-File -FilePath $outFile -Encoding ASCII -Append
Get-ChildItem $outFile
try {
$ag.Script() | Out-File -FilePath $outFile -Encoding ASCII -Append
Get-ChildItem $outFile
}
catch {
Stop-Function -ErrorRecord $_ -Message "Error scripting out the availability groups. This is likely due to a bug in SMO." -Continue
}
}
}
}
Expand All @@ -174,4 +179,4 @@ function Export-DbaAvailabilityGroup {
}
}
}
}
}
41 changes: 41 additions & 0 deletions tests/Export-DbaAvailabilityGroup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,47 @@ Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
$dbname = "dbatoolsci_agroupdb"
if (-not $env:appveyor) {
BeforeAll {
# $script:instance2 - to make it appear in the proper place on appveyor
Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue
$server = Connect-DbaInstance -SqlInstance $script:instance3
$computername = $server.NetName
$servicename = $server.ServiceName
if ($servicename -eq 'MSSQLSERVER') {
$instancename = "$computername"
}
else {
$instancename = "$computername\$servicename"
}
$server.Query("create database $dbname")
$backup = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase
$server.Query("IF NOT EXISTS (select * from sys.symmetric_keys where name like '%DatabaseMasterKey%') CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<StrongPassword>'")
$server.Query("IF EXISTS ( SELECT * FROM sys.tcp_endpoints WHERE name = 'End_Mirroring') DROP ENDPOINT endpoint_mirroring")
$server.Query("CREATE CERTIFICATE dbatoolsci_AGCert WITH SUBJECT = 'AG Certificate'")
$server.Query("CREATE ENDPOINT dbatoolsci_AGEndpoint
STATE = STARTED
AS TCP (LISTENER_PORT = 5022,LISTENER_IP = ALL)
FOR DATABASE_MIRRORING (AUTHENTICATION = CERTIFICATE dbatoolsci_AGCert,ROLE = ALL)")
$server.Query("CREATE AVAILABILITY GROUP dbatoolsci_agroup
WITH (DB_FAILOVER = OFF, DTC_SUPPORT = NONE, CLUSTER_TYPE = NONE)
FOR DATABASE $dbname REPLICA ON N'$instancename'
WITH (ENDPOINT_URL = N'TCP://$computername`:5022', FAILOVER_MODE = MANUAL, AVAILABILITY_MODE = SYNCHRONOUS_COMMIT)")
}
AfterAll {
try {
if ($backup.BackupPath) { Remove-Item -Path $backup.BackupPath -ErrorAction SilentlyContinue }
$server.Query("DROP AVAILABILITY GROUP dbatoolsci_agroup")
Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Remove-DbaDatabase -Confirm:$false
$server.Query("DROP ENDPOINT dbatoolsci_AGEndpoint")
$server.Query("DROP CERTIFICATE dbatoolsci_AGCert")
}
catch {
# dont care
}
}
}
Context "exports ags" {
$results = Export-DbaAvailabilityGroup -SqlInstance $script:instance3
It "returns file objects and one should be the name of the availability group" {
Expand Down
1 change: 1 addition & 0 deletions tests/Get-DbaAvailabilityGroup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' {
}

Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
$dbname = "dbatoolsci_agroupdb"
if (-not $env:appveyor) {
BeforeAll {
# $script:instance2 - to make it appear in the proper place on appveyor
Expand Down
5 changes: 4 additions & 1 deletion tests/pester.groups.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ $TestsRunGroups = @{
'Disable-DbaAgHadr'
)
# do not run on appveyor
"appveyor_disabled" = @()
# a bug in SMO prevents availability group scripting :(
"appveyor_disabled" = @(
'Export-DbaAvailabilityGroup'
)
# do not run everywhere
"disabled" = @()
}

0 comments on commit 6687b5e

Please sign in to comment.