forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added integration test (issue dsccommunity#753).
- Loading branch information
Showing
3 changed files
with
224 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
93 changes: 93 additions & 0 deletions
93
Tests/Integration/MSFT_xSQLServerRSConfig.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,93 @@ | ||
$script:DSCModuleName = 'xSQLServer' | ||
$script:DSCResourceFriendlyName = 'xSQLServerRSConfig' | ||
$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 | ||
|
||
$mockSqlInstallAccountPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force | ||
$mockSqlInstallAccountUserName = "$env:COMPUTERNAME\SqlInstall" | ||
$mockSqlInstallCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $mockSqlInstallAccountUserName, $mockSqlInstallAccountPassword | ||
|
||
$mockSqlAdminAccountPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force | ||
$mockSqlAdminAccountUserName = "$env:COMPUTERNAME\SqlAdmin" | ||
$mockSqlAdminCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $mockSqlAdminAccountUserName, $mockSqlAdminAccountPassword | ||
|
||
$mockReportingServicesServiceAccountPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force | ||
$mockReportingServicesServiceAccountUserName = "$env:COMPUTERNAME\svc-Reporting" | ||
$mockReportingServicesServiceCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $mockSqlServiceAccountUserName, $mockSqlServiceAccountPassword | ||
|
||
try | ||
{ | ||
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1" | ||
. $configFile | ||
|
||
Describe "$($script:DSCResourceName)_Integration" { | ||
BeforeAll { | ||
$resourceId = "[$($script:DSCResourceFriendlyName)]Integration_Test" | ||
} | ||
|
||
$configurationName = "$($script:DSCResourceName)_InstallReportingServices_Config" | ||
|
||
Context ('When using configuration {0}' -f $configurationName) { | ||
It 'Should compile and apply the MOF without throwing' { | ||
{ | ||
# The variable $ConfigurationData was dot-sourced above. | ||
& $configurationName ` | ||
-SqlInstallCredential $mockSqlInstallCredential ` | ||
-ReportingServicesServiceCredential $mockReportingServicesServiceCredential ` | ||
-SqlAdministratorCredential $mockSqlAdminCredential ` | ||
-OutputPath $TestDrive ` | ||
-ConfigurationData $ConfigurationData | ||
|
||
Start-DscConfiguration -Path $TestDrive ` | ||
-ComputerName localhost -Wait -Verbose -Force | ||
} | 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.IsHadrEnabled | Should Be $true | ||
# } | ||
} | ||
} | ||
} | ||
finally | ||
{ | ||
#region FOOTER | ||
|
||
Restore-TestEnvironment -TestEnvironment $TestEnvironment | ||
|
||
#endregion | ||
} |
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,130 @@ | ||
# This is used to make sure the integration test run in the correct order. | ||
[Microsoft.DscResourceKit.IntegrationTest(OrderNumber = 2)] | ||
param() | ||
|
||
# Get a spare drive letter | ||
$mockLastDrive = ((Get-Volume).DriveLetter | Sort-Object | Select-Object -Last 1) | ||
$mockIsoMediaDriveLetter = [char](([int][char]$mockLastDrive) + 1) | ||
|
||
$ConfigurationData = @{ | ||
AllNodes = @( | ||
@{ | ||
NodeName = 'localhost' | ||
|
||
InstanceName = 'DSCRS2016' | ||
Features = 'RS' | ||
InstallSharedDir = 'C:\Program Files\Microsoft SQL Server' | ||
InstallSharedWOWDir = 'C:\Program Files (x86)\Microsoft SQL Server' | ||
UpdateEnabled = 'False' | ||
SuppressReboot = $true # Make sure we don't reboot during testing. | ||
ForceReboot = $false | ||
|
||
ImagePath = "$env:TEMP\SQL2016.iso" | ||
DriveLetter = $mockIsoMediaDriveLetter | ||
|
||
ReportDatabaseInstanceName = 'DSCSQL2016' | ||
|
||
PSDscAllowPlainTextPassword = $true | ||
} | ||
) | ||
} | ||
|
||
Configuration MSFT_xSQLServerRSConfig_InstallReportingServices_Config | ||
{ | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.Management.Automation.PSCredential] | ||
$SqlInstallCredential, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.Management.Automation.PSCredential] | ||
$ReportingServicesServiceCredential, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.Management.Automation.PSCredential] | ||
$SqlAdministratorCredential | ||
) | ||
|
||
Import-DscResource -ModuleName 'PSDscResources' | ||
Import-DscResource -ModuleName 'xStorage' | ||
Import-DscResource -ModuleName 'xSQLServer' | ||
|
||
node localhost { | ||
xMountImage 'MountIsoMedia' | ||
{ | ||
ImagePath = $Node.ImagePath | ||
DriveLetter = $Node.DriveLetter | ||
Ensure = 'Present' | ||
} | ||
|
||
xWaitForVolume 'WaitForMountOfIsoMedia' | ||
{ | ||
DriveLetter = $Node.DriveLetter | ||
RetryIntervalSec = 5 | ||
RetryCount = 10 | ||
} | ||
|
||
User 'CreateReportingServicesServiceAccount' | ||
{ | ||
Ensure = 'Present' | ||
UserName = Split-Path -Path $ReportingServicesServiceCredential.UserName -Leaf | ||
Password = $ReportingServicesServiceCredential | ||
} | ||
|
||
WindowsFeature 'NetFramework45' | ||
{ | ||
Name = 'NET-Framework-45-Core' | ||
Ensure = 'Present' | ||
} | ||
|
||
xSQLServerSetup 'InstallReportingServicesInstance' | ||
{ | ||
InstanceName = $Node.InstanceName | ||
Features = $Node.Features | ||
SourcePath = "$($Node.DriveLetter):\" | ||
BrowserSvcStartupType = 'Automatic' | ||
RSSvcAccount = $ReportingServicesServiceCredential | ||
InstallSharedDir = $Node.InstallSharedDir | ||
InstallSharedWOWDir = $Node.InstallSharedWOWDir | ||
UpdateEnabled = $Node.UpdateEnabled | ||
SuppressReboot = $Node.SuppressReboot | ||
ForceReboot = $Node.ForceReboot | ||
|
||
# This must be set if using SYSTEM account to install. | ||
SQLSysAdminAccounts = @( | ||
$SqlAdministratorCredential.UserName | ||
) | ||
|
||
DependsOn = @( | ||
'[xMountImage]MountIsoMedia' | ||
'[User]CreateReportingServicesServiceAccount' | ||
'[WindowsFeature]NetFramework45' | ||
) | ||
|
||
PsDscRunAsCredential = $SqlInstallCredential | ||
} | ||
|
||
xSQLServerRSConfig 'Integration_Test' | ||
{ | ||
# Instance name for the Reporting Services. | ||
InstanceName = $Node.InstanceName | ||
|
||
<# | ||
Instance for Reporting Services databases. | ||
Note: This instance is created in a prior integration test. | ||
#> | ||
RSSQLServer = $Node.NodeName | ||
RSSQLInstanceName = $Node.ReportDatabaseInstanceName | ||
|
||
PsDscRunAsCredential = $SqlAdministratorCredential | ||
|
||
DependsOn = @( | ||
'[xSQLServerSetup]InstallReportingServicesInstance' | ||
) | ||
} | ||
} | ||
} |