diff --git a/CHANGELOG.md b/CHANGELOG.md index 20f83c798..1480f060f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- SqlScript + - BREAKING CHANGE: The parameter `Id` is now required to allow + reuse of a script with different variables. Set this to a unique value. + The information entered is never used to actually run the script. + ([issue #596](https://github.com/dsccommunity/SqlServerDsc/issues/596)). + - Fix unit test to fully check Set-TargetResource using timeout. +- SqlScriptQuery + - BREAKING CHANGE: The parameter `Id` is now required to allow + reuse of a script with different variables. Set this to a unique value. + The information entered is never used to actually run the script. + ([issue #596](https://github.com/dsccommunity/SqlServerDsc/issues/596)). + - Fix unit test to fully check Set-TargetResource using timeout. + - SqlServerDsc - Replaced inline task `Package_Wiki_Content` with the one now available in the module _DscResource.DocGenerator_. diff --git a/source/DSCResources/DSC_SqlScript/DSC_SqlScript.psm1 b/source/DSCResources/DSC_SqlScript/DSC_SqlScript.psm1 index 2828ec6ab..9e72f9f15 100644 --- a/source/DSCResources/DSC_SqlScript/DSC_SqlScript.psm1 +++ b/source/DSCResources/DSC_SqlScript/DSC_SqlScript.psm1 @@ -10,6 +10,10 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' .SYNOPSIS Returns the current state of what the Get-script returns. + .PARAMETER Id + Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing. + The information entered is never used during the actual process of running the scripts. + .PARAMETER InstanceName Specifies the name of the SQL Server Database Engine instance. For the default instance specify 'MSSQLSERVER'. @@ -67,6 +71,10 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( + [Parameter(Mandatory = $true)] + [System.String] + $Id, + [Parameter(Mandatory = $true)] [System.String] $InstanceName, @@ -138,6 +146,7 @@ function Get-TargetResource $getResult = Out-String -InputObject $result $returnValue = @{ + Id = [System.String] $Id ServerName = [System.String] $ServerName InstanceName = [System.String] $InstanceName SetFilePath = [System.String] $SetFilePath @@ -158,6 +167,10 @@ function Get-TargetResource .SYNOPSIS Executes the Set-script. + .PARAMETER Id + Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing. + The information entered is never used during the actual process of running the scripts. + .PARAMETER InstanceName Specifies the name of the SQL Server Database Engine instance. For the default instance specify 'MSSQLSERVER'. @@ -215,6 +228,10 @@ function Set-TargetResource [CmdletBinding()] param ( + [Parameter(Mandatory = $true)] + [System.String] + $Id, + [Parameter(Mandatory = $true)] [System.String] $InstanceName, @@ -288,6 +305,10 @@ function Set-TargetResource .SYNOPSIS Evaluates the value returned from the Test-script. + .PARAMETER Id + Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing. + The information entered is never used during the actual process of running the scripts. + .PARAMETER InstanceName Specifies the name of the SQL Server Database Engine instance. For the default instance specify 'MSSQLSERVER'. @@ -346,6 +367,10 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( + [Parameter(Mandatory = $true)] + [System.String] + $Id, + [Parameter(Mandatory = $true)] [System.String] $InstanceName, diff --git a/source/DSCResources/DSC_SqlScript/DSC_SqlScript.schema.mof b/source/DSCResources/DSC_SqlScript/DSC_SqlScript.schema.mof index d16678010..d4c35ff1a 100644 --- a/source/DSCResources/DSC_SqlScript/DSC_SqlScript.schema.mof +++ b/source/DSCResources/DSC_SqlScript/DSC_SqlScript.schema.mof @@ -1,6 +1,7 @@ [ClassVersion("1.0.0.0"), FriendlyName("SqlScript")] class DSC_SqlScript : OMI_BaseResource { + [Key, Description("Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing. The information entered is never used during the actual process of running the scripts.")] String Id; [Key, Description("Specifies the name of the _SQL Server Database Engine_ instance. For the default instance specify the value `'MSSQLSERVER'`.")] String InstanceName; [Key, Description("Path to the T-SQL file that will perform _Set_ action.")] String SetFilePath; [Key, Description("Path to the T-SQL file that will perform _Get_ action. Any values returned by the T-SQL queries will also be returned when calling _Get_ (for example by using the cmdlet `Get-DscConfiguration`) through the `'GetResult'` property.")] String GetFilePath; diff --git a/source/DSCResources/DSC_SqlScript/README.md b/source/DSCResources/DSC_SqlScript/README.md index c087086a0..9bb79cbd3 100644 --- a/source/DSCResources/DSC_SqlScript/README.md +++ b/source/DSCResources/DSC_SqlScript/README.md @@ -10,6 +10,10 @@ Get T-SQL script, Set T-SQL script and the Test T-SQL script. * Target machine must be running SQL Server 2012 or later. * Target machine must have access to the SQLPS PowerShell module or the SqlServer PowerShell module. +* Parameter `Id` is a unique identifier for this resource, allowing multiple + resources to be created, with only the Variable parameter changing. + Set this to any unique value - the information entered is never used during + the actual process of running the scripts. * Parameter `Encrypt` controls whether the connection used by `Invoke-SqlCmd` should enforce encryption. This parameter can only be used together with the module _SqlServer_ v22.x (minimum v22.0.49-preview). The parameter will be diff --git a/source/DSCResources/DSC_SqlScriptQuery/DSC_SqlScriptQuery.psm1 b/source/DSCResources/DSC_SqlScriptQuery/DSC_SqlScriptQuery.psm1 index 0222b005c..d2d4c3c6d 100644 --- a/source/DSCResources/DSC_SqlScriptQuery/DSC_SqlScriptQuery.psm1 +++ b/source/DSCResources/DSC_SqlScriptQuery/DSC_SqlScriptQuery.psm1 @@ -10,6 +10,10 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' .SYNOPSIS Returns the current state of what the Get-query returns. + .PARAMETER Id + Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing. + The information entered is never used during the actual process of running the scripts. + .PARAMETER InstanceName Specifies the name of the SQL Server Database Engine instance. For the default instance specify 'MSSQLSERVER'. @@ -67,6 +71,10 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( + [Parameter(Mandatory = $true)] + [System.String] + $Id, + [Parameter(Mandatory = $true)] [System.String] $InstanceName, @@ -138,6 +146,7 @@ function Get-TargetResource $getResult = Out-String -InputObject $result $returnValue = @{ + Id = [System.String] $Id ServerName = [System.String] $ServerName InstanceName = [System.String] $InstanceName GetQuery = [System.String] $GetQuery @@ -158,6 +167,10 @@ function Get-TargetResource .SYNOPSIS Executes the Set-query. + .PARAMETER Id + Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing. + The information entered is never used during the actual process of running the scripts. + .PARAMETER InstanceName Specifies the name of the SQL Server Database Engine instance. For the default instance specify 'MSSQLSERVER'. @@ -215,6 +228,10 @@ function Set-TargetResource [CmdletBinding()] param ( + [Parameter(Mandatory = $true)] + [System.String] + $Id, + [Parameter(Mandatory = $true)] [System.String] $InstanceName, @@ -288,6 +305,10 @@ function Set-TargetResource .SYNOPSIS Evaluates the value returned from the Test-query. + .PARAMETER Id + Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing. + The information entered is never used during the actual process of running the scripts. + .PARAMETER InstanceName Specifies the name of the SQL Server Database Engine instance. For the default instance specify 'MSSQLSERVER'. @@ -346,6 +367,10 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( + [Parameter(Mandatory = $true)] + [System.String] + $Id, + [Parameter(Mandatory = $true)] [System.String] $InstanceName, diff --git a/source/DSCResources/DSC_SqlScriptQuery/DSC_SqlScriptQuery.schema.mof b/source/DSCResources/DSC_SqlScriptQuery/DSC_SqlScriptQuery.schema.mof index eae2252f9..8f4014913 100644 --- a/source/DSCResources/DSC_SqlScriptQuery/DSC_SqlScriptQuery.schema.mof +++ b/source/DSCResources/DSC_SqlScriptQuery/DSC_SqlScriptQuery.schema.mof @@ -1,6 +1,7 @@ [ClassVersion("1.0.0.0"), FriendlyName("SqlScriptQuery")] class DSC_SqlScriptQuery : OMI_BaseResource { + [Key, Description("Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing. The information entered is never used during the actual process of running the scripts.")] String Id; [Key, Description("Specifies the name of the _SQL Server Database Engine_ instance. For the default instance specify the value `'MSSQLSERVER'`.")] String InstanceName; [Key, Description("Full T-SQL query that will perform _Get_ action. Any values returned by the T-SQL queries will also be returned when calling _Get_ (for example by using the cmdlet `Get-DscConfiguration`) through the `'GetResult'` property.")] String GetQuery; [Key, Description("Full T-SQL query that will perform _Test_ action. Any script that does not throw an error or returns `NULL` is evaluated to `$true`. The cmdlet `Invoke-SqlCmd` treats T-SQL `PRINT` statements as verbose text, and will not cause the test to return `$false`.")] String TestQuery; diff --git a/source/DSCResources/DSC_SqlScriptQuery/README.md b/source/DSCResources/DSC_SqlScriptQuery/README.md index 87c76ebfc..bd301c6bb 100644 --- a/source/DSCResources/DSC_SqlScriptQuery/README.md +++ b/source/DSCResources/DSC_SqlScriptQuery/README.md @@ -10,6 +10,10 @@ T-SQL script, Set T-SQL script and the Test T-SQL script. * Target machine must be running SQL Server 2012 or later. * Target machine must have access to the SQLPS PowerShell module or the SqlServer PowerShell module. +* Parameter `Id` is a unique identifier for this resource, allowing multiple + resources to be created, with only the Variable parameter changing. + Set this to any unique value - the information entered is never used during + the actual process of running the scripts. * Parameter `Encrypt` controls whether the connection used by `Invoke-SqlCmd` should enforce encryption. This parameter can only be used together with the module _SqlServer_ v22.x (minimum v22.0.49-preview). The parameter will be diff --git a/source/Examples/Resources/SqlScript/1-RunScriptUsingSQLAuthentication.ps1 b/source/Examples/Resources/SqlScript/1-RunScriptUsingSQLAuthentication.ps1 index 4c183a133..ea7d45cb6 100644 --- a/source/Examples/Resources/SqlScript/1-RunScriptUsingSQLAuthentication.ps1 +++ b/source/Examples/Resources/SqlScript/1-RunScriptUsingSQLAuthentication.ps1 @@ -18,6 +18,7 @@ Configuration Example { SqlScript 'RunAsSqlCredential' { + Id = 'RunAsSqlCredential' ServerName = 'localhost' InstanceName = 'SQL2016' Credential = $SqlCredential diff --git a/source/Examples/Resources/SqlScript/2-RunScriptUsingWindowsAuthentication.ps1 b/source/Examples/Resources/SqlScript/2-RunScriptUsingWindowsAuthentication.ps1 index 70f00f0b1..1df5cadcb 100644 --- a/source/Examples/Resources/SqlScript/2-RunScriptUsingWindowsAuthentication.ps1 +++ b/source/Examples/Resources/SqlScript/2-RunScriptUsingWindowsAuthentication.ps1 @@ -20,6 +20,7 @@ Configuration Example { SqlScript 'RunAsSYSTEM' { + Id = 'RunAsSYSTEM' ServerName = 'localhost' InstanceName = 'SQL2016' @@ -31,6 +32,7 @@ Configuration Example SqlScript 'RunAsUser' { + Id = 'RunAsUser' ServerName = 'localhost' InstanceName = 'SQL2016' @@ -44,6 +46,7 @@ Configuration Example SqlScript 'RunAsUser-With30SecondTimeout' { + Id = 'RunAsUser-With30SecondTimeout' ServerName = 'localhost' InstanceName = 'SQL2016' diff --git a/source/Examples/Resources/SqlScript/3-RunScriptCompleteExample.ps1 b/source/Examples/Resources/SqlScript/3-RunScriptCompleteExample.ps1 index 5ef7f271e..0558a1160 100644 --- a/source/Examples/Resources/SqlScript/3-RunScriptCompleteExample.ps1 +++ b/source/Examples/Resources/SqlScript/3-RunScriptCompleteExample.ps1 @@ -144,6 +144,7 @@ Configuration Example SqlScript 'Integration_Test' { + Id = 'Integration_Test' ServerName = $Node.ServerName InstanceName = $Node.InstanceName diff --git a/source/Examples/Resources/SqlScript/4-RunScriptUsingDisabledVariables.ps1 b/source/Examples/Resources/SqlScript/4-RunScriptUsingDisabledVariables.ps1 index 9e672c731..806af2219 100644 --- a/source/Examples/Resources/SqlScript/4-RunScriptUsingDisabledVariables.ps1 +++ b/source/Examples/Resources/SqlScript/4-RunScriptUsingDisabledVariables.ps1 @@ -18,6 +18,7 @@ Configuration Example { SqlScript 'RunWithDisabledVariables' { + Id = 'RunWithDisabledVariables' ServerName = 'localhost' InstanceName = 'SQL2016' Credential = $SqlCredential diff --git a/source/Examples/Resources/SqlScriptQuery/1-RunScriptUsingSQLAuthentication.ps1 b/source/Examples/Resources/SqlScriptQuery/1-RunScriptUsingSQLAuthentication.ps1 index cb073084d..482f23509 100644 --- a/source/Examples/Resources/SqlScriptQuery/1-RunScriptUsingSQLAuthentication.ps1 +++ b/source/Examples/Resources/SqlScriptQuery/1-RunScriptUsingSQLAuthentication.ps1 @@ -18,6 +18,7 @@ Configuration Example { SqlScriptQuery 'RunAsSqlCredential' { + Id = 'RunAsSqlCredential' ServerName = 'localhost' InstanceName = 'SQL2016' diff --git a/source/Examples/Resources/SqlScriptQuery/2-RunScriptUsingWindowsAuthentication.ps1 b/source/Examples/Resources/SqlScriptQuery/2-RunScriptUsingWindowsAuthentication.ps1 index 823728349..3628d08be 100644 --- a/source/Examples/Resources/SqlScriptQuery/2-RunScriptUsingWindowsAuthentication.ps1 +++ b/source/Examples/Resources/SqlScriptQuery/2-RunScriptUsingWindowsAuthentication.ps1 @@ -20,6 +20,7 @@ Configuration Example { SqlScriptQuery 'RunAsSYSTEM' { + Id = 'RunAsSYSTEM' ServerName = 'localhost' InstanceName = 'SQL2016' @@ -31,6 +32,7 @@ Configuration Example SqlScriptQuery 'RunAsUser' { + Id = 'RunAsUser' ServerName = 'localhost' InstanceName = 'SQL2016' @@ -44,6 +46,7 @@ Configuration Example SqlScriptQuery 'RunAsUser-With30SecondTimeout' { + Id = 'RunAsUser-With30SecondTimeout' ServerName = 'localhost' InstanceName = 'SQL2016' diff --git a/source/Examples/Resources/SqlScriptQuery/3-RunScriptCompleteExample.ps1 b/source/Examples/Resources/SqlScriptQuery/3-RunScriptCompleteExample.ps1 index 3653f817d..35f246940 100644 --- a/source/Examples/Resources/SqlScriptQuery/3-RunScriptCompleteExample.ps1 +++ b/source/Examples/Resources/SqlScriptQuery/3-RunScriptCompleteExample.ps1 @@ -19,6 +19,7 @@ Configuration Example { SqlScriptQuery 'CreateDatabase_ScriptDatabase1' { + Id = 'CreateDatabase_ScriptDatabase1' ServerName = $env:COMPUTERNAME InstanceName = 'DSCTEST' diff --git a/source/Examples/Resources/SqlScriptQuery/4-RunScriptUsingDisabledVariables.ps1 b/source/Examples/Resources/SqlScriptQuery/4-RunScriptUsingDisabledVariables.ps1 index 535248d62..3005bd14f 100644 --- a/source/Examples/Resources/SqlScriptQuery/4-RunScriptUsingDisabledVariables.ps1 +++ b/source/Examples/Resources/SqlScriptQuery/4-RunScriptUsingDisabledVariables.ps1 @@ -18,6 +18,7 @@ Configuration Example { SqlScriptQuery 'RunWithDisabledVariables' { + Id = 'RunWithDisabledVariables' ServerName = 'localhost' InstanceName = 'SQL2016' Credential = $SqlCredential diff --git a/tests/Integration/Resources/DSC_SqlDatabaseObjectPermission.config.ps1 b/tests/Integration/Resources/DSC_SqlDatabaseObjectPermission.config.ps1 index 5c1865483..97c36e3cc 100644 --- a/tests/Integration/Resources/DSC_SqlDatabaseObjectPermission.config.ps1 +++ b/tests/Integration/Resources/DSC_SqlDatabaseObjectPermission.config.ps1 @@ -110,6 +110,7 @@ Configuration DSC_SqlDatabaseObjectPermission_Prerequisites_Table1_Config { SqlScriptQuery 'CreateTable' { + Id = 'CreateTable' ServerName = $Node.ServerName InstanceName = $Node.InstanceName @@ -146,6 +147,7 @@ Configuration DSC_SqlDatabaseObjectPermission_Prerequisites_Procedure1_Config { SqlScriptQuery 'CreateProcedure1' { + Id = 'CreateProcedure1' ServerName = $Node.ServerName InstanceName = $Node.InstanceName @@ -182,6 +184,7 @@ Configuration DSC_SqlDatabaseObjectPermission_Prerequisites_Procedure2_Config { SqlScriptQuery 'CreateProcedure2' { + Id = 'CreateProcedure2' ServerName = $Node.ServerName InstanceName = $Node.InstanceName diff --git a/tests/Integration/Resources/DSC_SqlDatabaseUser.config.ps1 b/tests/Integration/Resources/DSC_SqlDatabaseUser.config.ps1 index 1ce2de24f..e5d210d1c 100644 --- a/tests/Integration/Resources/DSC_SqlDatabaseUser.config.ps1 +++ b/tests/Integration/Resources/DSC_SqlDatabaseUser.config.ps1 @@ -228,6 +228,7 @@ Configuration DSC_SqlDatabaseUser_AddDatabaseUser5_Config { SqlScriptQuery 'CreateDatabaseCertificate' { + Id = 'CreateDatabaseCertificate' ServerName = $Node.ServerName InstanceName = $Node.InstanceName @@ -294,6 +295,7 @@ Configuration DSC_SqlDatabaseUser_AddDatabaseUser6_Config { SqlScriptQuery 'CreateDatabaseAsymmetricKey' { + Id = 'CreateDatabaseAsymmetricKey' ServerName = $Node.ServerName InstanceName = $Node.InstanceName diff --git a/tests/Integration/Resources/DSC_SqlScript.config.ps1 b/tests/Integration/Resources/DSC_SqlScript.config.ps1 index 2ae000aa5..4feb8c035 100644 --- a/tests/Integration/Resources/DSC_SqlScript.config.ps1 +++ b/tests/Integration/Resources/DSC_SqlScript.config.ps1 @@ -209,6 +209,7 @@ Configuration DSC_SqlScript_RunSqlScriptAsWindowsUser_Config { SqlScript 'Integration_Test' { + Id = 'Integration_Test' ServerName = $Node.ServerName InstanceName = $Node.InstanceName @@ -240,6 +241,7 @@ Configuration DSC_SqlScript_RunSqlScriptAsSqlUser_Config { SqlScript 'Integration_Test' { + Id = 'Integration_Test' ServerName = $Node.ServerName InstanceName = $Node.InstanceName @@ -275,6 +277,7 @@ Configuration DSC_SqlScript_RunSqlScriptWithVariablesDisabled_Config { SqlScript 'Integration_Test' { + Id = 'Integration_Test' ServerName = $Node.ServerName InstanceName = $Node.InstanceName diff --git a/tests/Integration/Resources/DSC_SqlScriptQuery.config.ps1 b/tests/Integration/Resources/DSC_SqlScriptQuery.config.ps1 index 8cd9dbdab..c0b20703f 100644 --- a/tests/Integration/Resources/DSC_SqlScriptQuery.config.ps1 +++ b/tests/Integration/Resources/DSC_SqlScriptQuery.config.ps1 @@ -66,6 +66,7 @@ Configuration DSC_SqlScriptQuery_RunSqlScriptQueryAsWindowsUser_Config { SqlScriptQuery 'Integration_Test' { + Id = 'Integration_Test' ServerName = $Node.ServerName InstanceName = $Node.InstanceName @@ -97,6 +98,7 @@ Configuration DSC_SqlScriptQuery_RunSqlScriptQueryAsSqlUser_Config { SqlScriptQuery 'Integration_Test' { + Id = 'Integration_Test' ServerName = $Node.ServerName InstanceName = $Node.InstanceName @@ -137,6 +139,7 @@ Configuration DSC_SqlScriptQuery_RunSqlScriptQueryWithVariablesDisabled_Config { SqlScriptQuery 'Integration_Test' { + Id = 'Integration_Test' ServerName = $Node.ServerName InstanceName = $Node.InstanceName diff --git a/tests/Unit/DSC_SqlScript.Tests.ps1 b/tests/Unit/DSC_SqlScript.Tests.ps1 index 68217aa3e..27bdabf1f 100644 --- a/tests/Unit/DSC_SqlScript.Tests.ps1 +++ b/tests/Unit/DSC_SqlScript.Tests.ps1 @@ -78,6 +78,7 @@ Describe 'SqlScript\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { # Default parameters that are used for the It-blocks. $script:mockDefaultParameters = @{ + Id = 'Unit_Test' InstanceName = 'MSSQLSERVER' ServerName = 'localhost' SetFilePath = 'set.sql' @@ -108,6 +109,7 @@ Describe 'SqlScript\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters $result | Should -BeOfType [System.Collections.Hashtable] + $result.Id | Should -Be $mockGetTargetResourceParameters.Id $result.ServerInstance | Should -Be $mockGetTargetResourceParameters.ServerInstance $result.SetFilePath | Should -Be $mockGetTargetResourceParameters.SetFilePath $result.GetFilePath | Should -Be $mockGetTargetResourceParameters.GetFilePath @@ -127,22 +129,16 @@ Describe 'SqlScript\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - $mockTestParametersTimeout = @{ - ServerName = 'localhost' - InstanceName = 'MSSQLSERVER' - SetFilePath = 'set-timeout.sql' - GetFilePath = 'get-timeout.sql' - TestFilePath = 'test-timeout.sql' - QueryTimeout = 30 - } + $mockGetTargetResourceParameters.QueryTimeout = 30 - $result = Get-TargetResource @mockTestParametersTimeout + $result = Get-TargetResource @mockGetTargetResourceParameters $result | Should -BeOfType [System.Collections.Hashtable] - $result.ServerInstance | Should -Be $mockTestParametersTimeout.ServerInstance - $result.SetFilePath | Should -Be $mockTestParametersTimeout.SetFilePath - $result.GetFilePath | Should -Be $mockTestParametersTimeout.GetFilePath - $result.TestFilePath | Should -Be $mockTestParametersTimeout.TestFilePath + $result.Id | Should -Be $mockGetTargetResourceParameters.Id + $result.ServerInstance | Should -Be $mockGetTargetResourceParameters.ServerInstance + $result.SetFilePath | Should -Be $mockGetTargetResourceParameters.SetFilePath + $result.GetFilePath | Should -Be $mockGetTargetResourceParameters.GetFilePath + $result.TestFilePath | Should -Be $mockGetTargetResourceParameters.TestFilePath } } } @@ -171,6 +167,7 @@ Describe 'SqlScript\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { # Default parameters that are used for the It-blocks. $script:mockDefaultParameters = @{ + Id = 'Unit_Test' InstanceName = 'MSSQLSERVER' ServerName = 'localhost' SetFilePath = 'set.sql' @@ -214,6 +211,8 @@ Describe 'SqlScript\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 + $mockSetTargetResourceParameters.QueryTimeout = 30 + { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw } } @@ -244,6 +243,7 @@ Describe 'SqlScript\Test-TargetResource' { InModuleScope -ScriptBlock { # Default parameters that are used for the It-blocks. $script:mockDefaultParameters = @{ + Id = 'Unit_Test' InstanceName = 'MSSQLSERVER' ServerName = 'localhost' SetFilePath = 'set.sql' @@ -286,16 +286,9 @@ Describe 'SqlScript\Test-TargetResource' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - $mockTestParametersTimeout = @{ - ServerName = 'localhost' - InstanceName = 'MSSQLSERVER' - SetFilePath = 'set-timeout.sql' - GetFilePath = 'get-timeout.sql' - TestFilePath = 'test-timeout.sql' - QueryTimeout = 30 - } + $mockTestTargetResourceParameters.QueryTimeout = 30 - $result = Test-TargetResource @mockTestParametersTimeout + $result = Test-TargetResource @mockTestTargetResourceParameters $result | Should -BeTrue } @@ -315,16 +308,9 @@ Describe 'SqlScript\Test-TargetResource' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - $mockTestParametersTimeout = @{ - ServerName = 'localhost' - InstanceName = 'MSSQLSERVER' - SetFilePath = 'set-timeout.sql' - GetFilePath = 'get-timeout.sql' - TestFilePath = 'test-timeout.sql' - QueryTimeout = 30 - } + $mockTestTargetResourceParameters.QueryTimeout = 30 - $result = Test-TargetResource @mockTestParametersTimeout + $result = Test-TargetResource @mockTestTargetResourceParameters $result | Should -BeFalse } diff --git a/tests/Unit/DSC_SqlScriptQuery.Tests.ps1 b/tests/Unit/DSC_SqlScriptQuery.Tests.ps1 index 3a079e127..641608482 100644 --- a/tests/Unit/DSC_SqlScriptQuery.Tests.ps1 +++ b/tests/Unit/DSC_SqlScriptQuery.Tests.ps1 @@ -78,6 +78,7 @@ Describe 'SqlScriptQuery\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { # Default parameters that are used for the It-blocks. $script:mockDefaultParameters = @{ + Id = 'Unit_Test' InstanceName = 'MSSQLSERVER' ServerName = 'localhost' GetQuery = "GetQuery;" @@ -108,6 +109,7 @@ Describe 'SqlScriptQuery\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters $result | Should -BeOfType [System.Collections.Hashtable] + $result.Id | Should -Be $mockGetTargetResourceParameters.Id $result.ServerInstance | Should -Be $mockGetTargetResourceParameters.ServerInstance $result.GetQuery | Should -Be $mockGetTargetResourceParameters.GetQuery $result.SetQuery | Should -Be $mockGetTargetResourceParameters.SetQuery @@ -127,22 +129,16 @@ Describe 'SqlScriptQuery\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - $mockTestParametersTimeout = @{ - ServerName = 'localhost' - InstanceName = 'MSSQLSERVER' - GetQuery = "GetQuery;" - TestQuery = "TestQuery;" - SetQuery = "SetQuery;" - QueryTimeout = 30 - } + $mockGetTargetResourceParameters.QueryTimeout = 30 - $result = Get-TargetResource @mockTestParametersTimeout + $result = Get-TargetResource @mockGetTargetResourceParameters $result | Should -BeOfType [System.Collections.Hashtable] - $result.ServerInstance | Should -Be $mockTestParametersTimeout.ServerInstance - $result.GetQuery | Should -Be $mockTestParametersTimeout.GetQuery - $result.SetQuery | Should -Be $mockTestParametersTimeout.SetQuery - $result.TestQuery | Should -Be $mockTestParametersTimeout.TestQuery + $result.Id | Should -Be $mockGetTargetResourceParameters.Id + $result.ServerInstance | Should -Be $mockGetTargetResourceParameters.ServerInstance + $result.GetQuery | Should -Be $mockGetTargetResourceParameters.GetQuery + $result.SetQuery | Should -Be $mockGetTargetResourceParameters.SetQuery + $result.TestQuery | Should -Be $mockGetTargetResourceParameters.TestQuery } } } @@ -171,6 +167,7 @@ Describe 'SqlScriptQuery\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { # Default parameters that are used for the It-blocks. $script:mockDefaultParameters = @{ + Id = 'Unit_Test' InstanceName = 'MSSQLSERVER' ServerName = 'localhost' GetQuery = "GetQuery;" @@ -214,6 +211,8 @@ Describe 'SqlScriptQuery\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 + $mockSetTargetResourceParameters.QueryTimeout = 30 + { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw } } @@ -244,6 +243,7 @@ Describe 'SqlScriptQuery\Test-TargetResource' { InModuleScope -ScriptBlock { # Default parameters that are used for the It-blocks. $script:mockDefaultParameters = @{ + Id = 'Unit_Test' InstanceName = 'MSSQLSERVER' ServerName = 'localhost' GetQuery = "GetQuery;" @@ -286,16 +286,9 @@ Describe 'SqlScriptQuery\Test-TargetResource' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - $mockTestParametersTimeout = @{ - ServerName = 'localhost' - InstanceName = 'MSSQLSERVER' - GetQuery = "GetQuery;" - TestQuery = "TestQuery;" - SetQuery = "SetQuery;" - QueryTimeout = 30 - } + $mockTestTargetResourceParameters.QueryTimeout = 30 - $result = Test-TargetResource @mockTestParametersTimeout + $result = Test-TargetResource @mockTestTargetResourceParameters $result | Should -BeTrue } @@ -315,16 +308,9 @@ Describe 'SqlScriptQuery\Test-TargetResource' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - $mockTestParametersTimeout = @{ - ServerName = 'localhost' - InstanceName = 'MSSQLSERVER' - GetQuery = "GetQuery;" - TestQuery = "TestQuery;" - SetQuery = "SetQuery;" - QueryTimeout = 30 - } + $mockTestTargetResourceParameters.QueryTimeout = 30 - $result = Test-TargetResource @mockTestParametersTimeout + $result = Test-TargetResource @mockTestTargetResourceParameters $result | Should -BeFalse }