Skip to content

Commit e78b2e6

Browse files
committed
Fix tests
1 parent 6f32bf8 commit e78b2e6

9 files changed

+130
-135
lines changed

Resolve-Dependency.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
AllowPrerelease = $false
44
WithYAML = $true
55

6-
#UseModuleFast = $true
6+
UseModuleFast = $true
77
#ModuleFastVersion = '0.1.2'
88
#ModuleFastBleedingEdge = $true
99

10-
UsePSResourceGet = $true
10+
#UsePSResourceGet = $true
1111
#PSResourceGetVersion = '1.0.1'
1212

1313
UsePowerShellGetCompatibilityModule = $true

tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,23 @@ Describe 'Connect-SqlDscDatabaseEngine' -Tag @('Integration_SQL2016', 'Integrati
5454
It 'Should have the default instance SQL Server service started' {
5555
$getServiceResult = Get-Service -Name 'MSSQLSERVER' -ErrorAction 'Stop'
5656

57-
$getServiceResult.Status | Should -Be 'Running'
57+
$getServiceResult.Status | Should-Be 'Running'
5858
}
5959

6060
Context 'When impersonating a Windows user' {
6161
It 'Should return the correct result' {
62-
{
63-
$sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
64-
$sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
62+
$sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
63+
$sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
6564

66-
$connectSqlDscDatabaseEngineParameters = @{
67-
Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword)
68-
Verbose = $true
69-
ErrorAction = 'Stop'
70-
}
65+
$connectSqlDscDatabaseEngineParameters = @{
66+
Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword)
67+
Verbose = $true
68+
ErrorAction = 'Stop'
69+
}
7170

72-
$sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters
71+
$sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters
7372

74-
$sqlServerObject.Status.ToString() | Should -Match '^Online$'
75-
} | Should -Not -Throw
73+
$sqlServerObject.Status.ToString() | Should-MatchString '^Online$'
7674
}
7775
}
7876
}
@@ -91,47 +89,43 @@ Describe 'Connect-SqlDscDatabaseEngine' -Tag @('Integration_SQL2016', 'Integrati
9189
It 'Should have the named instance SQL Server service started' {
9290
$getServiceResult = Get-Service -Name 'MSSQL$DSCSQLTEST' -ErrorAction 'Stop'
9391

94-
$getServiceResult.Status | Should -Be 'Running'
92+
$getServiceResult.Status | Should-Be 'Running'
9593
}
9694

9795
Context 'When impersonating a Windows user' {
9896
It 'Should return the correct result' {
99-
{
100-
$sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
101-
$sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
97+
$sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
98+
$sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
10299

103-
$connectSqlDscDatabaseEngineParameters = @{
104-
InstanceName = 'DSCSQLTEST'
105-
Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword)
106-
Verbose = $true
107-
ErrorAction = 'Stop'
108-
}
100+
$connectSqlDscDatabaseEngineParameters = @{
101+
InstanceName = 'DSCSQLTEST'
102+
Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword)
103+
Verbose = $true
104+
ErrorAction = 'Stop'
105+
}
109106

110-
$sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters
107+
$sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters
111108

112-
$sqlServerObject.Status.ToString() | Should -Match '^Online$'
113-
} | Should -Not -Throw
109+
$sqlServerObject.Status.ToString() | Should-MatchString '^Online$'
114110
}
115111
}
116112

117113
Context 'When using a SQL login' {
118114
It 'Should return the correct result' {
119-
{
120-
$sqlAdministratorUserName = 'sa'
121-
$sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
122-
123-
$connectSqlDscDatabaseEngineParameters = @{
124-
InstanceName = 'DSCSQLTEST' # cSpell: disable-line
125-
LoginType = 'SqlLogin'
126-
Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword)
127-
Verbose = $true
128-
ErrorAction = 'Stop'
129-
}
130-
131-
$sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters
132-
133-
$sqlServerObject.Status.ToString() | Should -Match '^Online$'
134-
} | Should -Not -Throw
115+
$sqlAdministratorUserName = 'sa'
116+
$sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
117+
118+
$connectSqlDscDatabaseEngineParameters = @{
119+
InstanceName = 'DSCSQLTEST' # cSpell: disable-line
120+
LoginType = 'SqlLogin'
121+
Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword)
122+
Verbose = $true
123+
ErrorAction = 'Stop'
124+
}
125+
126+
$sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters
127+
128+
$sqlServerObject.Status.ToString() | Should-MatchString '^Online$'
135129
}
136130
}
137131
}

tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20
3434
Context 'When using Install parameter set' {
3535
Context 'When installing database engine default instance' {
3636
It 'Should run the command without throwing' {
37-
{
37+
$null = & ({
3838
# Set splatting parameters for Install-SqlDscServer
3939
$installSqlDscServerParameters = @{
4040
Install = $true
@@ -141,15 +141,15 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20
141141
# (Get-ComputerName),
142142
# $modulePath
143143
# )
144-
} | Should -Not -Throw
144+
})
145145
}
146146

147147
It 'Should have installed the SQL Server database engine' {
148148
# Validate the SQL Server installation
149149
$sqlServerService = Get-Service -Name 'MSSQLSERVER'
150150

151-
$sqlServerService | Should -Not -BeNullOrEmpty
152-
$sqlServerService.Status | Should -Be 'Running'
151+
$sqlServerService | Should-BeTruthy
152+
$sqlServerService.Status | Should-Be 'Running'
153153
}
154154

155155
It 'Should stop the default instance SQL Server service' {
@@ -165,7 +165,7 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20
165165
#>
166166
$stopServiceResult |
167167
Where-Object -FilterScript { $_.Name -eq 'MSSQLSERVER'}
168-
).Status | Should -Be 'Stopped'
168+
).Status | Should-Be 'Stopped'
169169
}
170170
}
171171

@@ -176,7 +176,7 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20
176176
# }
177177

178178
It 'Should run the command without throwing' {
179-
{
179+
$null = & ({
180180
# Set splatting parameters for Install-SqlDscServer
181181
$installSqlDscServerParameters = @{
182182
Install = $true
@@ -285,15 +285,15 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20
285285
# $modulePath
286286
# )
287287
# } | Should -Not -Throw
288-
} | Should -Not -Throw
288+
})
289289
}
290290

291291
It 'Should have installed the SQL Server database engine' {
292292
# Validate the SQL Server installation
293293
$sqlServerService = Get-Service -Name 'MSSQL$DSCSQLTEST'
294294

295-
$sqlServerService | Should -Not -BeNullOrEmpty
296-
$sqlServerService.Status | Should -Be 'Running'
295+
$sqlServerService | Should-BeTruthy
296+
$sqlServerService.Status | Should-Be 'Running'
297297
}
298298

299299
It 'Should stop the named instance SQL Server service' {
@@ -307,7 +307,7 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20
307307
#>
308308
$stopServiceResult |
309309
Where-Object -FilterScript { $_.Name -eq 'MSSQL$DSCSQLTEST' }
310-
).Status | Should -Be 'Stopped'
310+
).Status | Should-Be 'Stopped'
311311
}
312312
}
313313

tests/Integration/Commands/Prerequisites.Integration.Tests.ps1

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ Describe 'Prerequisites' {
3333
It 'Should create SqlInstall user' {
3434
$user = New-LocalUser -Name 'SqlInstall' -Password $password -FullName 'SQL Install User' -Description 'User for SQL installation.'
3535

36-
$user.Name | Should -Be 'SqlInstall'
37-
(Get-LocalUser -Name 'SqlInstall').Name | Should -Be 'SqlInstall'
36+
$user.Name | Should-Be 'SqlInstall'
37+
(Get-LocalUser -Name 'SqlInstall').Name | Should-Be 'SqlInstall'
3838
}
3939

4040
It 'Should create SqlAdmin user' {
4141
$user = New-LocalUser -Name 'SqlAdmin' -Password $password -FullName 'SQL Admin User' -Description 'User for SQL administration.'
4242

43-
$user.Name | Should -Be 'SqlAdmin'
44-
(Get-LocalUser -Name 'SqlAdmin').Name | Should -Be 'SqlAdmin'
43+
$user.Name | Should-Be 'SqlAdmin'
44+
(Get-LocalUser -Name 'SqlAdmin').Name | Should-Be 'SqlAdmin'
4545
}
4646
}
4747

@@ -53,29 +53,29 @@ Describe 'Prerequisites' {
5353
It 'Should create svc-SqlPrimary user' {
5454
$user = New-LocalUser -Name 'svc-SqlPrimary' -Password $password -FullName 'svc-SqlPrimary' -Description 'Runs the SQL Server service.'
5555

56-
$user.Name | Should -Be 'svc-SqlPrimary'
57-
(Get-LocalUser -Name 'svc-SqlPrimary').Name | Should -Be 'svc-SqlPrimary'
56+
$user.Name | Should-Be 'svc-SqlPrimary'
57+
(Get-LocalUser -Name 'svc-SqlPrimary').Name | Should-Be 'svc-SqlPrimary'
5858
}
5959

6060
It 'Should create svc-SqlAgentPri user' {
6161
$user = New-LocalUser -Name 'svc-SqlAgentPri' -Password $password -FullName 'svc-SqlAgentPri' -Description 'Runs the SQL Server Agent service.'
6262

63-
$user.Name | Should -Be 'svc-SqlAgentPri'
64-
(Get-LocalUser -Name 'svc-SqlAgentPri').Name | Should -Be 'svc-SqlAgentPri'
63+
$user.Name | Should-Be 'svc-SqlAgentPri'
64+
(Get-LocalUser -Name 'svc-SqlAgentPri').Name | Should-Be 'svc-SqlAgentPri'
6565
}
6666

6767
It 'Should create svc-SqlSecondary user' {
6868
$user = New-LocalUser -Name 'svc-SqlSecondary' -Password $password -FullName 'svc-SqlSecondary' -Description 'Runs the SQL Server service.'
6969

70-
$user.Name | Should -Be 'svc-SqlSecondary'
71-
(Get-LocalUser -Name 'svc-SqlSecondary').Name | Should -Be 'svc-SqlSecondary'
70+
$user.Name | Should-Be 'svc-SqlSecondary'
71+
(Get-LocalUser -Name 'svc-SqlSecondary').Name | Should-Be 'svc-SqlSecondary'
7272
}
7373

7474
It 'Should create svc-SqlAgentSec user' {
7575
$user = New-LocalUser -Name 'svc-SqlAgentSec' -Password $password -FullName 'svc-SqlAgentSec' -Description 'Runs the SQL Server Agent service.'
7676

77-
$user.Name | Should -Be 'svc-SqlAgentSec'
78-
(Get-LocalUser -Name 'svc-SqlAgentSec').Name | Should -Be 'svc-SqlAgentSec'
77+
$user.Name | Should-Be 'svc-SqlAgentSec'
78+
(Get-LocalUser -Name 'svc-SqlAgentSec').Name | Should-Be 'svc-SqlAgentSec'
7979
}
8080
}
8181

@@ -87,7 +87,7 @@ Describe 'Prerequisites' {
8787
# Verify if user is part of local administrator group
8888
$adminGroup = Get-LocalGroup -Name 'Administrators'
8989
$adminGroupMembers = Get-LocalGroupMember -Group $adminGroup
90-
$adminGroupMembers.Name | Should -Contain ('{0}\SqlInstall' -f (Get-ComputerName))
90+
$adminGroupMembers.Name | Should-ContainCollection ('{0}\SqlInstall' -f (Get-ComputerName))
9191
}
9292
}
9393

@@ -97,101 +97,101 @@ Describe 'Prerequisites' {
9797

9898
$script:mediaFile = Save-SqlDscSqlServerMediaFile -Url $url -DestinationPath $env:TEMP -Force -Quiet -ErrorAction 'Stop'
9999

100-
$mediaFile.Name | Should -Be 'media.iso'
100+
$mediaFile.Name | Should-Be 'media.iso'
101101
}
102102

103103
It 'Should download SQL Server 2017 media' -Tag @('Integration_SQL2017') {
104104
$url = 'https://download.microsoft.com/download/E/F/2/EF23C21D-7860-4F05-88CE-39AA114B014B/SQLServer2017-x64-ENU.iso'
105105

106106
$script:mediaFile = Save-SqlDscSqlServerMediaFile -Url $url -DestinationPath $env:TEMP -Force -Quiet -ErrorAction 'Stop'
107107

108-
$mediaFile.Name | Should -Be 'media.iso'
108+
$mediaFile.Name | Should-Be 'media.iso'
109109
}
110110

111111
It 'Should download SQL Server 2019 media' -Tag @('Integration_SQL2019') {
112112
$url = 'https://download.microsoft.com/download/d/a/2/da259851-b941-459d-989c-54a18a5d44dd/SQL2019-SSEI-Dev.exe'
113113

114114
$script:mediaFile = Save-SqlDscSqlServerMediaFile -Url $url -DestinationPath $env:TEMP -Force -Quiet -ErrorAction 'Stop'
115115

116-
$mediaFile.Name | Should -Be 'media.iso'
116+
$mediaFile.Name | Should-Be 'media.iso'
117117
}
118118

119119
It 'Should download SQL Server 2022 media' -Tag @('Integration_SQL2022') {
120120
$url = 'https://download.microsoft.com/download/c/c/9/cc9c6797-383c-4b24-8920-dc057c1de9d3/SQL2022-SSEI-Dev.exe'
121121

122122
$script:mediaFile = Save-SqlDscSqlServerMediaFile -Url $url -DestinationPath $env:TEMP -Force -Quiet -ErrorAction 'Stop'
123123

124-
$mediaFile.Name | Should -Be 'media.iso'
124+
$mediaFile.Name | Should-Be 'media.iso'
125125
}
126126
}
127127

128128
Context 'Mount SQL Server media' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
129129
It 'Should mount the media to a drive letter' {
130130
$mountedImage = Mount-DiskImage -ImagePath $script:mediaFile
131-
$mountedImage | Should -BeOfType 'Microsoft.Management.Infrastructure.CimInstance'
131+
$mountedImage | Should-HaveType 'Microsoft.Management.Infrastructure.CimInstance'
132132

133133
$mountedVolume = Get-Volume -DiskImage $mountedImage
134-
$mountedVolume.DriveLetter | Should -Not -BeNullOrEmpty
134+
$mountedVolume.DriveLetter | Should-BeTruthy
135135

136136
$env:IsoDriveLetter = $mountedVolume.DriveLetter
137-
$env:IsoDriveLetter | Should -Not -BeNullOrEmpty
137+
$env:IsoDriveLetter | Should-BeTruthy
138138

139139
$env:IsoDrivePath = (Get-PSDrive -Name $env:IsoDriveLetter).Root
140-
$env:IsoDrivePath | Should -Be ('{0}:\' -f $env:IsoDriveLetter)
140+
$env:IsoDrivePath | Should-Be ('{0}:\' -f $env:IsoDriveLetter)
141141
}
142142

143143
It 'Should have set environment variable for drive letter' {
144-
$env:IsoDriveLetter | Should -Not -BeNullOrEmpty
144+
$env:IsoDriveLetter | Should-BeTruthy
145145
}
146146

147147
It 'Should have set environment variable for drive path' {
148-
$env:IsoDrivePath | Should -Be ('{0}:\' -f $env:IsoDriveLetter)
148+
$env:IsoDrivePath | Should-Be ('{0}:\' -f $env:IsoDriveLetter)
149149
}
150150
}
151151

152152
Context 'Install correct version of module SqlServer' {
153153
It 'Should have the minimum required version of Microsoft.PowerShell.PSResourceGet' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
154154
$module = Get-Module -Name 'Microsoft.PowerShell.PSResourceGet' -ListAvailable
155155

156-
$module | Should -HaveCount 1
157-
$module.Version -ge '1.0.4.1' | Should -BeTrue
156+
$module | Should-BeCollection -Count 1
157+
$module.Version -ge '1.0.4.1' | Should-BeTrue
158158
}
159159

160160
It 'Should have a resource repository PSGallery with correct URI' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
161161
$resourceRepository = Get-PSResourceRepository -Name 'PSGallery'
162162

163-
$resourceRepository | Should -HaveCount 1
164-
$resourceRepository.Uri | Should -Be 'https://www.powershellgallery.com/api/v2'
163+
$resourceRepository | Should-BeCollection -Count 1
164+
$resourceRepository.Uri | Should-Be 'https://www.powershellgallery.com/api/v2'
165165
}
166166

167167
It 'Should install SqlServer module version 21.1.18256' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019') {
168168
#Install-Module -Name 'SqlServer' -RequiredVersion '21.1.18256' -Force -ErrorAction 'Stop'
169169
$module = Install-PSResource -Name 'SqlServer' -Version '21.1.18256' -Scope 'AllUsers' -TrustRepository -ErrorAction 'Stop' -Confirm:$false -PassThru
170170

171-
$module | Should -HaveCount 1
172-
$module.Version -eq '21.1.18256' | Should -BeTrue
171+
$module | Should-BeCollection -Count 1
172+
$module.Version -eq '21.1.18256' | Should-BeTrue
173173
}
174174

175175
It 'Should have SqlServer module version 21.1.18256 available' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019') {
176176
$module = Get-Module -Name 'SqlServer' -ListAvailable
177177

178-
$module | Should -HaveCount 1
179-
$module.Version -eq '21.1.18256' | Should -BeTrue
178+
$module | Should-BeCollection -Count 1
179+
$module.Version -eq '21.1.18256' | Should-BeTrue
180180
}
181181

182182
It 'Should install SqlServer module version 22.2.0' -Tag @('Integration_SQL2022') {
183183
#Install-Module -Name 'SqlServer' -RequiredVersion '22.2.0' -Force -ErrorAction 'Stop'
184184
$module = Install-PSResource -Name 'SqlServer' -Version '22.2.0' -Scope 'AllUsers' -TrustRepository -ErrorAction 'Stop' -Confirm:$false -PassThru
185185

186-
$module | Should -HaveCount 1
187-
$module.Version -eq '22.2.0' | Should -BeTrue
186+
$module | Should-BeCollection -Count 1
187+
$module.Version -eq '22.2.0' | Should-BeTrue
188188
}
189189

190190
It 'Should have SqlServer module version 22.2.0 available' -Tag @('Integration_SQL2022') {
191191
$module = Get-Module -Name 'SqlServer' -ListAvailable
192192

193-
$module | Should -HaveCount 1
194-
$module.Version -eq '22.2.0' | Should -BeTrue
193+
$module | Should-BeCollection -Count 1
194+
$module.Version -eq '22.2.0' | Should-BeTrue
195195
}
196196
}
197197

@@ -201,7 +201,7 @@ Describe 'Prerequisites' {
201201
# TODO: This fails on Appveyor, but works locally when debugging on AppVeyor. Investigate why.
202202
$result = Invoke-Command -ComputerName 'localhost' -ScriptBlock { 1 } -ErrorAction 'Stop'
203203

204-
$result | Should -Be 1
204+
$result | Should-Be 1
205205
}
206206
}
207207
}

0 commit comments

Comments
 (0)