Skip to content

Commit 4603c89

Browse files
Improve tests to be more flexible (#10096)
1 parent 4371b8d commit 4603c89

3 files changed

Lines changed: 23 additions & 17 deletions

File tree

tests/Test-DbaConnection.Tests.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ Describe $CommandName -Tag UnitTests {
2525
Describe $CommandName -Tag IntegrationTests {
2626
Context "Testing if command works" {
2727
It "returns the correct results" {
28-
$results = Test-DbaConnection -SqlInstance $TestConfig.instance1
28+
$port = (Get-DbaTcpPort -SqlInstance $TestConfig.InstanceSingle).Port
2929
$whoami = whoami
3030

31-
$results.TcpPort | Should -Be 1433
31+
$results = Test-DbaConnection -SqlInstance $TestConfig.InstanceSingle
32+
33+
$results.TcpPort | Should -Be $port
3234
$results.AuthType | Should -Be 'Windows Authentication'
3335
$results.ConnectingAsUser | Should -Be $whoami
3436
}

tests/Test-DbaDiskAlignment.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ Describe $CommandName -Tag UnitTests {
2424
Describe $CommandName -Tag IntegrationTests {
2525
Context "Command actually works" {
2626
It "Should return a result" {
27-
$results = Test-DbaDiskAlignment -ComputerName $TestConfig.DbaToolsCi_Computer
27+
$results = Test-DbaDiskAlignment -ComputerName $TestConfig.InstanceSingle
2828
$results | Should -Not -Be $null
2929
}
3030

3131
It "Should return a result not using sql" {
32-
$results = Test-DbaDiskAlignment -NoSqlCheck -ComputerName $TestConfig.DbaToolsCi_Computer
32+
$results = Test-DbaDiskAlignment -NoSqlCheck -ComputerName $TestConfig.InstanceSingle
3333
$results | Should -Not -Be $null
3434
}
3535
}

tests/Test-DbaLinkedServerConnection.Tests.ps1

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,54 +22,58 @@ Describe $CommandName -Tag UnitTests {
2222

2323
Describe $CommandName -Tag IntegrationTests {
2424
BeforeAll {
25-
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance1
25+
$target = $TestConfig.InstanceSingle
26+
27+
$server = Connect-DbaInstance -SqlInstance $TestConfig.InstanceSingle
2628
if ($server.VersionMajor -ge 17) {
2729
# Starting with SQL Server 2025 (17.x), MSOLEDBSQL uses Microsoft OLE DB Driver version 19, which adds support for TDS 8.0. However, this driver introduces a breaking change. You must now specify the encrypt parameter.
28-
$server.Query("EXEC master.dbo.sp_addlinkedserver @server=N'localhost', @srvproduct=N'', @provider=N'MSOLEDBSQL', @provstr = N'encrypt=optional;TrustServerCertificate=yes'")
29-
} elseif ($server.VersionMajor -eq 16) {
30-
# Starting with SQL Server 2022 (16.x), you must specify a provider name. MSOLEDBSQL is recommended. If you omit @provider, you can experience unexpected behavior.
31-
$server.Query("EXEC master.dbo.sp_addlinkedserver @server=N'localhost', @srvproduct=N'', @provider=N'MSOLEDBSQL'")
30+
$server.Query("EXEC master.dbo.sp_addlinkedserver @server=N'$target', @srvproduct=N'', @provider=N'MSOLEDBSQL', @provstr = N'encrypt=optional;TrustServerCertificate=yes'")
31+
} elseif (-not $env:AppVeyor) {
32+
$server.Query("EXEC master.dbo.sp_addlinkedserver @server=N'$target', @srvproduct=N'', @provider=N'MSOLEDBSQL'")
3233
} else {
33-
$server.Query("EXEC master.dbo.sp_addlinkedserver @server=N'localhost', @srvproduct=N'SQL Server'")
34+
# AppVeyor images do not have the MSOLEDBSQL provider installed, so we use SQLNCLI11 instead
35+
$server.Query("EXEC master.dbo.sp_addlinkedserver @server=N'$target', @srvproduct=N'SQL Server'")
3436
}
3537
}
3638

3739
AfterAll {
38-
$server.Query("EXEC master.dbo.sp_dropserver @server=N'localhost'")
40+
$server.Query("EXEC master.dbo.sp_dropserver @server=N'$target'")
3941
}
4042

4143
Context "Function works" {
4244
BeforeAll {
43-
$results = Test-DbaLinkedServerConnection -SqlInstance $TestConfig.instance1 | Where-Object LinkedServerName -eq "localhost"
45+
$results = Test-DbaLinkedServerConnection -SqlInstance $TestConfig.InstanceSingle | Where-Object LinkedServerName -eq $target
4446
}
4547

4648
It "function returns results" {
4749
$results | Should -Not -BeNullOrEmpty
4850
}
4951

50-
It "linked server name is localhost" {
51-
$results.LinkedServerName | Should -Be "localhost"
52+
It "linked server name is correct" {
53+
$results.LinkedServerName | Should -Be $target
5254
}
5355

5456
It "connectivity is true" {
57+
$results.Result | Should -Be 'Success'
5558
$results.Connectivity | Should -BeTrue
5659
}
5760
}
5861

5962
Context "Piping to function works" {
6063
BeforeAll {
61-
$pipeResults = Get-DbaLinkedServer -SqlInstance $TestConfig.instance1 | Test-DbaLinkedServerConnection
64+
$pipeResults = Get-DbaLinkedServer -SqlInstance $TestConfig.InstanceSingle | Test-DbaLinkedServerConnection
6265
}
6366

6467
It "piping from Get-DbaLinkedServerConnection returns results" {
6568
$pipeResults | Should -Not -BeNullOrEmpty
6669
}
6770

68-
It "linked server name is localhost" {
69-
$pipeResults.LinkedServerName | Should -Be "localhost"
71+
It "linked server name is correct" {
72+
$pipeResults.LinkedServerName | Should -Be $target
7073
}
7174

7275
It "connectivity is true" {
76+
$pipeResults.Result | Should -Be 'Success'
7377
$pipeResults.Connectivity | Should -BeTrue
7478
}
7579
}

0 commit comments

Comments
 (0)