-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SqlServerLogin: Added integration tests (#998)
- Changes to xSqlServerLogin - Added integration tests (issue #748).
- Loading branch information
Showing
4 changed files
with
669 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
379 changes: 379 additions & 0 deletions
379
Tests/Integration/MSFT_SqlServerLogin.Integration.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,379 @@ | ||
$script:DSCModuleName = 'SqlServerDsc' | ||
$script:DSCResourceFriendlyName = 'SqlServerLogin' | ||
$script:DSCResourceName = "MSFT_$($script:DSCResourceFriendlyName)" | ||
|
||
if (-not $env:APPVEYOR -eq $true) | ||
{ | ||
Write-Warning -Message ('Integration test for {0} will be skipped unless $env:APPVEYOR equals $true' -f $script:DSCResourceName) | ||
return | ||
} | ||
|
||
#region HEADER | ||
# Integration Test Template Version: 1.1.2 | ||
[String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) | ||
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` | ||
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) | ||
{ | ||
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests')) | ||
} | ||
|
||
Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force | ||
$TestEnvironment = Initialize-TestEnvironment ` | ||
-DSCModuleName $script:DSCModuleName ` | ||
-DSCResourceName $script:DSCResourceName ` | ||
-TestType Integration | ||
|
||
#endregion | ||
|
||
$mockSqlAdminAccountPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force | ||
$mockSqlAdminAccountUserName = "$env:COMPUTERNAME\SqlAdmin" | ||
$mockSqlAdminCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $mockSqlAdminAccountUserName, $mockSqlAdminAccountPassword | ||
|
||
$mockUserAccountPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force | ||
$mockUserCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'OnlyPasswordIsUsed', $mockUserAccountPassword | ||
|
||
try | ||
{ | ||
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1" | ||
. $configFile | ||
|
||
$mockDscUser1Name = $ConfigurationData.AllNodes.DscUser1Name | ||
$mockDscUser1Type = $ConfigurationData.AllNodes.DscUser1Type | ||
$mockDscUser2Name = $ConfigurationData.AllNodes.DscUser2Name | ||
$mockDscUser2Type = $ConfigurationData.AllNodes.DscUser2Type | ||
$mockDscUser3Name = $ConfigurationData.AllNodes.DscUser3Name | ||
$mockDscUser3Type = $ConfigurationData.AllNodes.DscUser3Type | ||
$mockDscUser4Name = $ConfigurationData.AllNodes.DscUser4Name | ||
$mockDscUser4Type = $ConfigurationData.AllNodes.DscUser4Type | ||
$mockDscSqlUsers1Name = $ConfigurationData.AllNodes.DscSqlUsers1Name | ||
$mockDscSqlUsers1Type = $ConfigurationData.AllNodes.DscSqlUsers1Type | ||
|
||
Describe "$($script:DSCResourceName)_Integration" { | ||
BeforeAll { | ||
$resourceId = "[$($script:DSCResourceFriendlyName)]Integration_Test" | ||
} | ||
|
||
$configurationName = "$($script:DSCResourceName)_CreateDependencies_Config" | ||
|
||
<# | ||
This will install dependencies using other resource modules, and is | ||
done without running extra tests on the result. | ||
This is done to speed up testing. | ||
#> | ||
Context ('When using configuration {0}' -f $configurationName) { | ||
It 'Should compile and apply the MOF without throwing' { | ||
{ | ||
$configurationParameters = @{ | ||
UserCredential = $mockUserCredential | ||
OutputPath = $TestDrive | ||
# The variable $ConfigurationData was dot-sourced above. | ||
ConfigurationData = $ConfigurationData | ||
} | ||
|
||
& $configurationName @configurationParameters | ||
|
||
$startDscConfigurationParameters = @{ | ||
Path = $TestDrive | ||
ComputerName = 'localhost' | ||
Wait = $true | ||
Verbose = $true | ||
Force = $true | ||
ErrorAction = 'Stop' | ||
} | ||
|
||
Start-DscConfiguration @startDscConfigurationParameters | ||
} | Should -Not -Throw | ||
} | ||
} | ||
|
||
$configurationName = "$($script:DSCResourceName)_AddLoginDscUser1_Config" | ||
|
||
Context ('When using configuration {0}' -f $configurationName) { | ||
It 'Should compile and apply the MOF without throwing' { | ||
{ | ||
$configurationParameters = @{ | ||
SqlAdministratorCredential = $mockSqlAdminCredential | ||
OutputPath = $TestDrive | ||
# The variable $ConfigurationData was dot-sourced above. | ||
ConfigurationData = $ConfigurationData | ||
} | ||
|
||
& $configurationName @configurationParameters | ||
|
||
$startDscConfigurationParameters = @{ | ||
Path = $TestDrive | ||
ComputerName = 'localhost' | ||
Wait = $true | ||
Verbose = $true | ||
Force = $true | ||
ErrorAction = 'Stop' | ||
} | ||
|
||
Start-DscConfiguration @startDscConfigurationParameters | ||
} | Should -Not -Throw | ||
} | ||
|
||
It 'Should be able to call Get-DscConfiguration without throwing' { | ||
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw | ||
} | ||
|
||
It 'Should have set the resource and all the parameters should match' { | ||
$currentConfiguration = Get-DscConfiguration | ||
|
||
$resourceCurrentState = $currentConfiguration | Where-Object -FilterScript { | ||
$_.ConfigurationName -eq $configurationName | ||
} | Where-Object -FilterScript { | ||
$_.ResourceId -eq $resourceId | ||
} | ||
|
||
$resourceCurrentState.Ensure | Should -Be 'Present' | ||
$resourceCurrentState.Name | Should -Be $mockDscUser1Name | ||
$resourceCurrentState.LoginType | Should -Be $mockDscUser1Type | ||
$resourceCurrentState.Disabled | Should -Be $false | ||
} | ||
} | ||
|
||
$configurationName = "$($script:DSCResourceName)_AddLoginDscUser2_Config" | ||
|
||
Context ('When using configuration {0}' -f $configurationName) { | ||
It 'Should compile and apply the MOF without throwing' { | ||
{ | ||
$configurationParameters = @{ | ||
SqlAdministratorCredential = $mockSqlAdminCredential | ||
OutputPath = $TestDrive | ||
# The variable $ConfigurationData was dot-sourced above. | ||
ConfigurationData = $ConfigurationData | ||
} | ||
|
||
& $configurationName @configurationParameters | ||
|
||
$startDscConfigurationParameters = @{ | ||
Path = $TestDrive | ||
ComputerName = 'localhost' | ||
Wait = $true | ||
Verbose = $true | ||
Force = $true | ||
ErrorAction = 'Stop' | ||
} | ||
|
||
Start-DscConfiguration @startDscConfigurationParameters | ||
} | Should -Not -Throw | ||
} | ||
|
||
It 'Should be able to call Get-DscConfiguration without throwing' { | ||
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw | ||
} | ||
|
||
It 'Should have set the resource and all the parameters should match' { | ||
$currentConfiguration = Get-DscConfiguration | ||
|
||
$resourceCurrentState = $currentConfiguration | Where-Object -FilterScript { | ||
$_.ConfigurationName -eq $configurationName | ||
} | Where-Object -FilterScript { | ||
$_.ResourceId -eq $resourceId | ||
} | ||
|
||
$resourceCurrentState.Ensure | Should -Be 'Present' | ||
$resourceCurrentState.Name | Should -Be $mockDscUser2Name | ||
$resourceCurrentState.LoginType | Should -Be $mockDscUser2Type | ||
$resourceCurrentState.Disabled | Should -Be $false | ||
} | ||
} | ||
|
||
$configurationName = "$($script:DSCResourceName)_AddLoginDscUser3_Disabled_Config" | ||
|
||
Context ('When using configuration {0}' -f $configurationName) { | ||
It 'Should compile and apply the MOF without throwing' { | ||
{ | ||
$configurationParameters = @{ | ||
SqlAdministratorCredential = $mockSqlAdminCredential | ||
OutputPath = $TestDrive | ||
# The variable $ConfigurationData was dot-sourced above. | ||
ConfigurationData = $ConfigurationData | ||
} | ||
|
||
& $configurationName @configurationParameters | ||
|
||
$startDscConfigurationParameters = @{ | ||
Path = $TestDrive | ||
ComputerName = 'localhost' | ||
Wait = $true | ||
Verbose = $true | ||
Force = $true | ||
ErrorAction = 'Stop' | ||
} | ||
|
||
Start-DscConfiguration @startDscConfigurationParameters | ||
} | Should -Not -Throw | ||
} | ||
|
||
It 'Should be able to call Get-DscConfiguration without throwing' { | ||
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw | ||
} | ||
|
||
It 'Should have set the resource and all the parameters should match' { | ||
$currentConfiguration = Get-DscConfiguration | ||
|
||
$resourceCurrentState = $currentConfiguration | Where-Object -FilterScript { | ||
$_.ConfigurationName -eq $configurationName | ||
} | Where-Object -FilterScript { | ||
$_.ResourceId -eq $resourceId | ||
} | ||
|
||
$resourceCurrentState.Ensure | Should -Be 'Present' | ||
$resourceCurrentState.Name | Should -Be $mockDscUser3Name | ||
$resourceCurrentState.LoginType | Should -Be $mockDscUser3Type | ||
$resourceCurrentState.Disabled | Should -Be $true | ||
} | ||
} | ||
|
||
$configurationName = "$($script:DSCResourceName)_AddLoginDscUser4_Config" | ||
|
||
Context ('When using configuration {0}' -f $configurationName) { | ||
It 'Should compile and apply the MOF without throwing' { | ||
{ | ||
$configurationParameters = @{ | ||
SqlAdministratorCredential = $mockSqlAdminCredential | ||
UserCredential = $mockUserCredential | ||
OutputPath = $TestDrive | ||
# The variable $ConfigurationData was dot-sourced above. | ||
ConfigurationData = $ConfigurationData | ||
} | ||
|
||
& $configurationName @configurationParameters | ||
|
||
$startDscConfigurationParameters = @{ | ||
Path = $TestDrive | ||
ComputerName = 'localhost' | ||
Wait = $true | ||
Verbose = $true | ||
Force = $true | ||
ErrorAction = 'Stop' | ||
} | ||
|
||
Start-DscConfiguration @startDscConfigurationParameters | ||
} | Should -Not -Throw | ||
} | ||
|
||
It 'Should be able to call Get-DscConfiguration without throwing' { | ||
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw | ||
} | ||
|
||
It 'Should have set the resource and all the parameters should match' { | ||
$currentConfiguration = Get-DscConfiguration | ||
|
||
$resourceCurrentState = $currentConfiguration | Where-Object -FilterScript { | ||
$_.ConfigurationName -eq $configurationName | ||
} | Where-Object -FilterScript { | ||
$_.ResourceId -eq $resourceId | ||
} | ||
|
||
$resourceCurrentState.Ensure | Should -Be 'Present' | ||
$resourceCurrentState.Name | Should -Be $mockDscUser4Name | ||
$resourceCurrentState.LoginType | Should -Be $mockDscUser4Type | ||
$resourceCurrentState.Disabled | Should -Be $false | ||
} | ||
} | ||
|
||
$configurationName = "$($script:DSCResourceName)_AddLoginDscSqlUsers1_Config" | ||
|
||
Context ('When using configuration {0}' -f $configurationName) { | ||
It 'Should compile and apply the MOF without throwing' { | ||
{ | ||
$configurationParameters = @{ | ||
SqlAdministratorCredential = $mockSqlAdminCredential | ||
OutputPath = $TestDrive | ||
# The variable $ConfigurationData was dot-sourced above. | ||
ConfigurationData = $ConfigurationData | ||
} | ||
|
||
& $configurationName @configurationParameters | ||
|
||
$startDscConfigurationParameters = @{ | ||
Path = $TestDrive | ||
ComputerName = 'localhost' | ||
Wait = $true | ||
Verbose = $true | ||
Force = $true | ||
ErrorAction = 'Stop' | ||
} | ||
|
||
Start-DscConfiguration @startDscConfigurationParameters | ||
} | Should -Not -Throw | ||
} | ||
|
||
It 'Should be able to call Get-DscConfiguration without throwing' { | ||
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw | ||
} | ||
|
||
It 'Should have set the resource and all the parameters should match' { | ||
$currentConfiguration = Get-DscConfiguration | ||
|
||
$resourceCurrentState = $currentConfiguration | Where-Object -FilterScript { | ||
$_.ConfigurationName -eq $configurationName | ||
} | Where-Object -FilterScript { | ||
$_.ResourceId -eq $resourceId | ||
} | ||
|
||
$resourceCurrentState.Ensure | Should -Be 'Present' | ||
$resourceCurrentState.Name | Should -Be $mockDscSqlUsers1Name | ||
$resourceCurrentState.LoginType | Should -Be $mockDscSqlUsers1Type | ||
$resourceCurrentState.Disabled | Should -Be $false | ||
} | ||
} | ||
|
||
$configurationName = "$($script:DSCResourceName)_RemoveLoginDscUser3_Config" | ||
|
||
Context ('When using configuration {0}' -f $configurationName) { | ||
It 'Should compile and apply the MOF without throwing' { | ||
{ | ||
$configurationParameters = @{ | ||
SqlAdministratorCredential = $mockSqlAdminCredential | ||
OutputPath = $TestDrive | ||
# The variable $ConfigurationData was dot-sourced above. | ||
ConfigurationData = $ConfigurationData | ||
} | ||
|
||
& $configurationName @configurationParameters | ||
|
||
$startDscConfigurationParameters = @{ | ||
Path = $TestDrive | ||
ComputerName = 'localhost' | ||
Wait = $true | ||
Verbose = $true | ||
Force = $true | ||
ErrorAction = 'Stop' | ||
} | ||
|
||
Start-DscConfiguration @startDscConfigurationParameters | ||
} | Should -Not -Throw | ||
} | ||
|
||
It 'Should be able to call Get-DscConfiguration without throwing' { | ||
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw | ||
} | ||
|
||
It 'Should have set the resource and all the parameters should match' { | ||
$currentConfiguration = Get-DscConfiguration | ||
|
||
$resourceCurrentState = $currentConfiguration | Where-Object -FilterScript { | ||
$_.ConfigurationName -eq $configurationName | ||
} | Where-Object -FilterScript { | ||
$_.ResourceId -eq $resourceId | ||
} | ||
|
||
$resourceCurrentState.Ensure | Should -Be 'Absent' | ||
$resourceCurrentState.Name | Should -Be $mockDscUser3Name | ||
$resourceCurrentState.LoginType | Should -BeNullOrEmpty | ||
} | ||
} | ||
} | ||
} | ||
finally | ||
{ | ||
#region FOOTER | ||
|
||
Restore-TestEnvironment -TestEnvironment $TestEnvironment | ||
|
||
#endregion | ||
} |
Oops, something went wrong.