Skip to content

Commit

Permalink
Fixed unit tests to call Invoke-TestSetup outside try-block (#1457)
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju authored Jan 3, 2020
1 parent 30f5e14 commit ea2f8f0
Show file tree
Hide file tree
Showing 35 changed files with 72 additions and 70 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md)

### Fixed

- SqlServerDsc
- Fixed unit tests to call the function `Invoke-TestSetup` outside the
try-block.
- SqlAlwaysOnService
- When failing to enable AlwaysOn the resource should now fail with an
error ([issue #1190](https://github.com/dsccommunity/SqlServerDsc/issues/1190)).
5 changes: 2 additions & 3 deletions tests/Unit/MSFT_SqlAG.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ if (-not (Test-BuildCategory -Type 'Unit'))
$script:dscModuleName = 'SqlServerDsc'
$script:dscResourceName = 'MSFT_SqlAG'

$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
function Invoke-TestSetup
{
try
Expand Down Expand Up @@ -48,10 +47,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
# This is relative to the path of the resource module script, not test test script.
$script:moduleRoot = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlAGDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {

#region Parameter Mocks
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlAGListener.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {

$mockKnownAvailabilityGroup = 'AG01'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlAGReplica.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {

#region parameter mocks
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlAgentAlert.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockServerName = 'localhost'
$mockInstanceName = 'MSSQLSERVER'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlAgentFailsafe.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockServerName = 'localhost'
$mockInstanceName = 'MSSQLSERVER'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlAgentOperator.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockServerName = 'localhost'
$mockInstanceName = 'MSSQLSERVER'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlAlias.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$registryPath = 'HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo'
$registryPathWow6432Node = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo'
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/MSFT_SqlDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ function Invoke-TestSetup

function Invoke-TestCleanup
{
#Restore-TestEnvironment -TestEnvironment $script:testEnvironment
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockServerName = 'localhost'
$mockInstanceName = 'MSSQLSERVER'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlDatabaseDefaultLocation.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockServerName = 'localhost'
$mockInstanceName = 'MSSQLSERVER'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlDatabaseOwner.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockServerName = 'localhost'
$mockInstanceName = 'MSSQLSERVER'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlDatabasePermission.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockServerName = 'localhost'
$mockInstanceName = 'MSSQLSERVER'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlDatabaseRecoveryModel.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockServerName = 'localhost'
$mockInstanceName = 'MSSQLSERVER'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlDatabaseRole.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockServerName = 'localhost'
$mockInstanceName = 'MSSQLSERVER'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlDatabaseUser.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockName = 'DatabaseUser1'
$mockServerName = 'localhost'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlRS.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockNamedInstanceName = 'INSTANCE'
$mockDefaultInstanceName = 'MSSQLSERVER'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlRSSetup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
<#
.SYNOPSIS
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlScript.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
Describe 'MSFT_SqlScript\Get-TargetResource' {
BeforeAll {
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlScriptQuery.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
Describe 'MSFT_SqlScriptQuery\Get-TargetResource' {
BeforeAll {
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlServerDatabaseMail.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockServerName = 'localhost'
$mockInstanceName = 'MSSQLSERVER'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockServerName = 'localhost'
$mockInstanceName = 'INSTANCE1'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlServerEndpointPermission.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockNodeName = 'localhost'
$mockInstanceName = 'SQL2016'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlServerEndpointState.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockNodeName = 'localhost'
$mockInstanceName = 'INSTANCE1'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlServerLogin.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
# Create PSCredential object for SQL Logins
$mockSqlLoginUser = 'dba'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlServerMaxDop.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockServerName = 'localhost'
$mockInstanceName = 'MSSQLSERVER'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlServerMemory.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockServerName = 'localhost'
$mockInstanceName = 'MSSQLSERVER'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlServerNetwork.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockInstanceName = 'TEST'
$mockTcpProtocolName = 'Tcp'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlServerPermission.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockServerName = 'localhost'
$mockInstanceName = 'DEFAULT'
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MSFT_SqlServerRole.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ function Invoke-TestCleanup
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}

Invoke-TestSetup

try
{
Invoke-TestSetup

InModuleScope $script:dscResourceName {
$mockServerName = 'localhost'
$mockInstanceName = 'MSSQLSERVER'
Expand Down
Loading

0 comments on commit ea2f8f0

Please sign in to comment.