Skip to content

Commit e59856d

Browse files
committed
Update integration tests
1 parent 2d96015 commit e59856d

3 files changed

Lines changed: 53 additions & 63 deletions

File tree

tests/Integration/DSC_IniSettingsFile.Integration.Tests.ps1

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
22
param ()
33

4-
$script:DSCModuleName = 'FileContentDsc'
5-
$script:DSCResourceName = 'DSC_IniSettingsFile'
4+
$script:dscModuleName = 'FileContentDsc'
5+
$script:dscResourceName = 'DSC_IniSettingsFile'
66

7-
#region HEADER
8-
# Integration Test Template Version: 1.1.1
9-
[System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
10-
11-
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
12-
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
7+
try
138
{
14-
& git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\'))
9+
Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop'
1510
}
11+
catch [System.IO.FileNotFoundException]
12+
{
13+
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.'
14+
}
15+
16+
$script:testEnvironment = Initialize-TestEnvironment `
17+
-DSCModuleName $script:dscModuleName `
18+
-DSCResourceName $script:dscResourceName `
19+
-ResourceType 'Mof' `
20+
-TestType 'Integration'
1621

17-
Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force
18-
Import-Module (Join-Path -Path $script:moduleRoot -ChildPath "$($script:DSCModuleName).psd1") -Force
19-
$TestEnvironment = Initialize-TestEnvironment `
20-
-DSCModuleName $script:DSCModuleName `
21-
-DSCResourceName $script:DSCResourceName `
22-
-TestType Integration
23-
#endregion
22+
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1')
2423

2524
try
2625
{
27-
Describe 'IniSettingsFile Integration Tests' {
26+
Describe "$($script:dscResourceName)_Integration" {
2827
$script:confgurationFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'DSC_IniSettingsFile.config.ps1'
2928
$script:configurationName = 'IniSettingsFile'
3029
$script:testTextFile = Join-Path -Path $TestDrive -ChildPath 'TestFile.ini'
@@ -206,7 +205,5 @@ SettingThree=Value3
206205
}
207206
finally
208207
{
209-
#region FOOTER
210-
Restore-TestEnvironment -TestEnvironment $TestEnvironment
211-
#endregion
208+
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
212209
}

tests/Integration/DSC_KeyValuePairFile.Integration.Tests.ps1

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
22
param ()
33

4-
$script:DSCModuleName = 'FileContentDsc'
5-
$script:DSCResourceName = 'DSC_KeyValuePairFile'
4+
$script:dscModuleName = 'FileContentDsc'
5+
$script:dscResourceName = 'DSC_KeyValuePairFile'
66

7-
#region HEADER
8-
# Integration Test Template Version: 1.1.1
9-
[System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
10-
11-
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
12-
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
7+
try
138
{
14-
& git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\'))
9+
Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop'
1510
}
11+
catch [System.IO.FileNotFoundException]
12+
{
13+
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.'
14+
}
15+
16+
$script:testEnvironment = Initialize-TestEnvironment `
17+
-DSCModuleName $script:dscModuleName `
18+
-DSCResourceName $script:dscResourceName `
19+
-ResourceType 'Mof' `
20+
-TestType 'Integration'
1621

17-
Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force
18-
Import-Module (Join-Path -Path $script:moduleRoot -ChildPath "$($script:DSCModuleName).psd1") -Force
19-
# Helper module import required for the Get-FileEncoding function
20-
Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'Modules\FileContentDsc.Common') -Force
21-
$TestEnvironment = Initialize-TestEnvironment `
22-
-DSCModuleName $script:DSCModuleName `
23-
-DSCResourceName $script:DSCResourceName `
24-
-TestType Integration
25-
#endregion
22+
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1')
2623

2724
try
2825
{
29-
Describe 'KeyValuePairFile Integration Tests' {
26+
Describe "$($script:dscResourceName)_Integration" {
3027
$script:confgurationFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'DSC_KeyValuePairFile.config.ps1'
3128
$script:configurationName = 'KeyValuePairFile'
3229
$script:testTextFile = Join-Path -Path $TestDrive -ChildPath 'TestFile.txt'
@@ -483,7 +480,5 @@ $($script:testName)=$($script:testText)
483480
}
484481
finally
485482
{
486-
#region FOOTER
487-
Restore-TestEnvironment -TestEnvironment $TestEnvironment
488-
#endregion
483+
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
489484
}

tests/Integration/DSC_ReplaceText.Integration.Tests.ps1

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
22
param ()
33

4-
$script:DSCModuleName = 'FileContentDsc'
5-
$script:DSCResourceName = 'DSC_ReplaceText'
4+
$script:dscModuleName = 'FileContentDsc'
5+
$script:dscResourceName = 'DSC_ReplaceText'
66

7-
#region HEADER
8-
# Integration Test Template Version: 1.1.1
9-
[System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
10-
11-
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
12-
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
7+
try
8+
{
9+
Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop'
10+
}
11+
catch [System.IO.FileNotFoundException]
1312
{
14-
& git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\'))
13+
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.'
1514
}
1615

17-
Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force
18-
Import-Module (Join-Path -Path $script:moduleRoot -ChildPath "$($script:DSCModuleName).psd1") -Force
16+
$script:testEnvironment = Initialize-TestEnvironment `
17+
-DSCModuleName $script:dscModuleName `
18+
-DSCResourceName $script:dscResourceName `
19+
-ResourceType 'Mof' `
20+
-TestType 'Integration'
21+
22+
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1')
23+
1924
# Helper module import required for the Get-FileEncoding function
20-
Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'Modules\FileContentDsc.Common') -Force
21-
$TestEnvironment = Initialize-TestEnvironment `
22-
-DSCModuleName $script:DSCModuleName `
23-
-DSCResourceName $script:DSCResourceName `
24-
-TestType Integration
25-
#endregion
25+
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\..\source\Modules\FileContentDsc.Common') -Force
2626

2727
try
2828
{
29-
Describe 'ReplaceText Integration Tests' {
29+
Describe "$($script:dscResourceName)_Integration" {
3030
$script:confgurationFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'DSC_ReplaceText.config.ps1'
3131
$script:configurationName = 'ReplaceText'
3232
$script:testTextFile = Join-Path -Path $TestDrive -ChildPath 'TestFile.txt'
@@ -280,7 +280,5 @@ Setting3.Test=Value4
280280
}
281281
finally
282282
{
283-
#region FOOTER
284-
Restore-TestEnvironment -TestEnvironment $TestEnvironment
285-
#endregion
283+
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
286284
}

0 commit comments

Comments
 (0)