@@ -22,54 +22,58 @@ Describe $CommandName -Tag UnitTests {
2222
2323Describe $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