From ff9e32d89f3e354dc0c2b84badac69ae1062a287 Mon Sep 17 00:00:00 2001 From: Indhu Sivaramakrishnan Date: Wed, 4 Oct 2017 14:36:29 -0700 Subject: [PATCH 01/10] Add tests for Dsc configuration compilation on Windows --- .../MOF-Compilation.Tests.ps1 | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 index dd9ac9ab6e4..a5e6be5eec3 100644 --- a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 +++ b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 @@ -165,4 +165,54 @@ Describe "DSC MOF Compilation" -tags "CI" { Remove-Item -Force -Recurse -Path WordPressServer } + It "Should be able to compile a MOF from a basic configuration on Windows" -Skip:($IsMacOS -or $IsLinux) { + [Scriptblock]::Create(@" + configuration DSCTestConfig + { + Import-DscResource -ModuleName PSDesiredStateConfiguration + Node "localhost" { + File f1 + { + DestinationPath = "$env:SystemDrive\\Test.txt"; + Ensure = "Present" + } + } + } + + DSCTestConfig +"@).Invoke() + + Remove-Item -Force -Recurse -Path DSCTestConfig + } + + It "Should be able to compile a MOF from a configuration with multiple resources on Windows" -Skip:($IsMacOS -or $IsLinux) { + [Scriptblock]::Create(@" + configuration DSCTestConfig + { + Import-DscResource -ModuleName PSDesiredStateConfiguration + Node "localhost" { + File f1 + { + DestinationPath = "$env:SystemDrive\\Test.txt"; + Ensure = "Present" + } + Script s1 + { + GetScript = {return @{}} + SetScript = "Write-Verbose Hello" + TestScript = {return $false} + } + Log l1 + { + Message = "This is a log message" + } + } + } + + DSCTestConfig +"@).Invoke() + + Remove-Item -Force -Recurse -Path DSCTestConfig + } + } From 73687efe81c1cd1bcbe5efe99b245d8c8eaaea18 Mon Sep 17 00:00:00 2001 From: Indhu Sivaramakrishnan Date: Mon, 9 Oct 2017 11:41:36 -0700 Subject: [PATCH 02/10] Fix Indendation --- .../MOF-Compilation.Tests.ps1 | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 index a5e6be5eec3..a9bbeaffb1d 100644 --- a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 +++ b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 @@ -173,8 +173,8 @@ Describe "DSC MOF Compilation" -tags "CI" { Node "localhost" { File f1 { - DestinationPath = "$env:SystemDrive\\Test.txt"; - Ensure = "Present" + DestinationPath = "$env:SystemDrive\\Test.txt"; + Ensure = "Present" } } } @@ -193,19 +193,19 @@ Describe "DSC MOF Compilation" -tags "CI" { Node "localhost" { File f1 { - DestinationPath = "$env:SystemDrive\\Test.txt"; - Ensure = "Present" + DestinationPath = "$env:SystemDrive\\Test.txt"; + Ensure = "Present" } - Script s1 - { - GetScript = {return @{}} - SetScript = "Write-Verbose Hello" - TestScript = {return $false} - } - Log l1 - { - Message = "This is a log message" - } + Script s1 + { + GetScript = {return @{}} + SetScript = "Write-Verbose Hello" + TestScript = {return $false} + } + Log l1 + { + Message = "This is a log message" + } } } From 714b127f35e3c4c5744eb9b21526c06eeaa74097 Mon Sep 17 00:00:00 2001 From: Indhu Sivaramakrishnan Date: Mon, 9 Oct 2017 15:16:09 -0700 Subject: [PATCH 03/10] Update test to assert that scriptblock invocation does not throw --- .../MOF-Compilation.Tests.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 index a9bbeaffb1d..29a1cd38ce2 100644 --- a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 +++ b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 @@ -24,7 +24,7 @@ Describe "DSC MOF Compilation" -tags "CI" { } DSCTestConfig -"@).Invoke() +"@).Invoke() | Should Not Throw; Remove-Item -Force -Recurse -Path DSCTestConfig } @@ -46,7 +46,7 @@ Describe "DSC MOF Compilation" -tags "CI" { } DSCTestConfig -"@).Invoke() +"@).Invoke() | Should Not Throw; Remove-Item -Force -Recurse -Path DSCTestConfig } @@ -160,7 +160,7 @@ Describe "DSC MOF Compilation" -tags "CI" { } WordPressServer -"@).Invoke() +"@).Invoke() | Should Not Throw; Remove-Item -Force -Recurse -Path WordPressServer } @@ -180,7 +180,7 @@ Describe "DSC MOF Compilation" -tags "CI" { } DSCTestConfig -"@).Invoke() +"@).Invoke() | Should Not Throw; Remove-Item -Force -Recurse -Path DSCTestConfig } @@ -210,7 +210,7 @@ Describe "DSC MOF Compilation" -tags "CI" { } DSCTestConfig -"@).Invoke() +"@).Invoke() | Should Not Throw; Remove-Item -Force -Recurse -Path DSCTestConfig } From 2964f4b7d5291513a001fa135da0411235dee474 Mon Sep 17 00:00:00 2001 From: Indhu Sivaramakrishnan Date: Mon, 9 Oct 2017 15:18:26 -0700 Subject: [PATCH 04/10] Update tests to fix indentation --- .../MOF-Compilation.Tests.ps1 | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 index 29a1cd38ce2..6106d387d19 100644 --- a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 +++ b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 @@ -173,8 +173,8 @@ Describe "DSC MOF Compilation" -tags "CI" { Node "localhost" { File f1 { - DestinationPath = "$env:SystemDrive\\Test.txt"; - Ensure = "Present" + DestinationPath = "$env:SystemDrive\\Test.txt"; + Ensure = "Present" } } } @@ -193,19 +193,19 @@ Describe "DSC MOF Compilation" -tags "CI" { Node "localhost" { File f1 { - DestinationPath = "$env:SystemDrive\\Test.txt"; - Ensure = "Present" + DestinationPath = "$env:SystemDrive\\Test.txt"; + Ensure = "Present" } - Script s1 - { - GetScript = {return @{}} - SetScript = "Write-Verbose Hello" - TestScript = {return $false} - } - Log l1 - { - Message = "This is a log message" - } + Script s1 + { + GetScript = {return @{}} + SetScript = "Write-Verbose Hello" + TestScript = {return $false} + } + Log l1 + { + Message = "This is a log message" + } } } From 84e52a4e4fe96f838471da9e3104a162e6ec9e3f Mon Sep 17 00:00:00 2001 From: Indhu Sivaramakrishnan Date: Mon, 9 Oct 2017 15:28:06 -0700 Subject: [PATCH 05/10] Update test to ensure that MOF is produced after compilation --- .../MOF-Compilation.Tests.ps1 | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 index 6106d387d19..ef263b708d9 100644 --- a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 +++ b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 @@ -24,7 +24,9 @@ Describe "DSC MOF Compilation" -tags "CI" { } DSCTestConfig -"@).Invoke() | Should Not Throw; +"@).Invoke() + + Test-Path -Path .\DSCTestConfig\localhost.mof | Should Be $True Remove-Item -Force -Recurse -Path DSCTestConfig } @@ -46,7 +48,9 @@ Describe "DSC MOF Compilation" -tags "CI" { } DSCTestConfig -"@).Invoke() | Should Not Throw; +"@).Invoke() + + Test-Path -Path .\DSCTestConfig\localhost.mof | Should Be $True Remove-Item -Force -Recurse -Path DSCTestConfig } @@ -160,7 +164,9 @@ Describe "DSC MOF Compilation" -tags "CI" { } WordPressServer -"@).Invoke() | Should Not Throw; +"@).Invoke() + + Test-Path -Path .\WordPressServer\localhost.mof | Should Be $True Remove-Item -Force -Recurse -Path WordPressServer } @@ -180,7 +186,9 @@ Describe "DSC MOF Compilation" -tags "CI" { } DSCTestConfig -"@).Invoke() | Should Not Throw; +"@).Invoke() + + Test-Path -Path .\DSCTestConfig\localhost.mof | Should Be $True Remove-Item -Force -Recurse -Path DSCTestConfig } @@ -210,7 +218,9 @@ Describe "DSC MOF Compilation" -tags "CI" { } DSCTestConfig -"@).Invoke() | Should Not Throw; +"@).Invoke() + + Test-Path -Path .\DSCTestConfig\localhost.mof | Should Be $True Remove-Item -Force -Recurse -Path DSCTestConfig } From 8d1ac8cfca1b422bbfb01e1a521378991ee670fd Mon Sep 17 00:00:00 2001 From: Indhu Sivaramakrishnan Date: Mon, 9 Oct 2017 17:02:43 -0700 Subject: [PATCH 06/10] Update indentation --- .../MOF-Compilation.Tests.ps1 | 248 +++++++++--------- 1 file changed, 124 insertions(+), 124 deletions(-) diff --git a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 index ef263b708d9..5b2c022ef16 100644 --- a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 +++ b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 @@ -26,7 +26,7 @@ Describe "DSC MOF Compilation" -tags "CI" { DSCTestConfig "@).Invoke() - Test-Path -Path .\DSCTestConfig\localhost.mof | Should Be $True + Test-Path -Path .\DSCTestConfig\localhost.mof | Should Be $True Remove-Item -Force -Recurse -Path DSCTestConfig } @@ -50,128 +50,128 @@ Describe "DSC MOF Compilation" -tags "CI" { DSCTestConfig "@).Invoke() - Test-Path -Path .\DSCTestConfig\localhost.mof | Should Be $True + Test-Path -Path .\DSCTestConfig\localhost.mof | Should Be $True Remove-Item -Force -Recurse -Path DSCTestConfig } It "Should be able to compile a MOF from a complex configuration" -Skip:($IsMacOS -or $IsWindows) { [Scriptblock]::Create(@" - Configuration WordPressServer{ + Configuration WordPressServer{ Import-DscResource -ModuleName PSDesiredStateConfiguration - Node CentOS{ - - #Ensure Apache packages are installed - nxPackage httpd { - Ensure = "Present" - Name = "httpd" - PackageManager = "yum" - } - - #Include vhostdir - nxFile vHostDir{ - DestinationPath = "/etc/httpd/conf.d/vhosts.conf" - Ensure = "Present" - Contents = "IncludeOptional /etc/httpd/sites-enabled/*.conf`n" - Type = "File" - } - - nxFile vHostDirectory{ - DestinationPath = "/etc/httpd/sites-enabled" - Type = "Directory" - Ensure = "Present" - } - - - #Ensure directory for Wordpress site - nxFile wpHttpDir{ - DestinationPath = "/var/www/wordpress" - Type = "Directory" - Ensure = "Present" - Mode = "755" - } - - #Ensure share directory - nxFile share{ - DestinationPath = "/mnt/share" - Type = "Directory" - Ensure = "Present" - Mode = "755" - } - - #Bind httpd to port 8080 - nxFile HttpdPort{ - DestinationPath = "/etc/httpd/conf.d/listen.conf" - Ensure = "Present" - Contents = "Listen 8080`n" - Type = "File" - } - - #nfs mounts - nxScript nfsMount{ - TestScript= "#!/bin/bash" - GetScript="#!/bin/bash" - SetScript="#!/bin/bash" - - } - - #Retrieve latest wordpress - nxFile WordPressTar{ - SourcePath = "/mnt/share/latest.zip" - DestinationPath = "/tmp/wordpress.zip" - Checksum = "md5" - Type = "file" - DependsOn = "[nxScript]nfsMount" - } - - #Extract wordpress if changed - nxArchive ExtractSite{ - SourcePath = "/tmp/wordpress.zip" - DestinationPath = "/var/www/wordpress" - Ensure = "Present" - DependsOn = "[nxFile]WordpressTar" - } - - #Set wp-config - - - #Fixup SE Linux context - #nxScript SELinuxContext{ - #TestScript= "#!/bin/bash" - #GetScript = "#!/bin/bash" - #SetScript = "#!/bin/bash" - #} - - #Disable SELinux - nxFileLine SELinux { - Filepath = "/etc/selinux/config" - DoesNotContainPattern = "SELINUX=enforcing" - ContainsLine = "SELINUX=disabled" - } - - - nxScript SELinuxHTTPNet{ - GetScript = "#!/bin/bash`ngetsebool httpd_can_network_connect" - setScript = "#!/bin/bash`nsetsebool -P httpd_can_network_connect=1" - TestScript = "#!/bin/bash`n exit 1" - } - - - - } - - } + Node CentOS{ + + #Ensure Apache packages are installed + nxPackage httpd { + Ensure = "Present" + Name = "httpd" + PackageManager = "yum" + } + + #Include vhostdir + nxFile vHostDir{ + DestinationPath = "/etc/httpd/conf.d/vhosts.conf" + Ensure = "Present" + Contents = "IncludeOptional /etc/httpd/sites-enabled/*.conf`n" + Type = "File" + } + + nxFile vHostDirectory{ + DestinationPath = "/etc/httpd/sites-enabled" + Type = "Directory" + Ensure = "Present" + } + + + #Ensure directory for Wordpress site + nxFile wpHttpDir{ + DestinationPath = "/var/www/wordpress" + Type = "Directory" + Ensure = "Present" + Mode = "755" + } + + #Ensure share directory + nxFile share{ + DestinationPath = "/mnt/share" + Type = "Directory" + Ensure = "Present" + Mode = "755" + } + + #Bind httpd to port 8080 + nxFile HttpdPort{ + DestinationPath = "/etc/httpd/conf.d/listen.conf" + Ensure = "Present" + Contents = "Listen 8080`n" + Type = "File" + } + + #nfs mounts + nxScript nfsMount{ + TestScript= "#!/bin/bash" + GetScript="#!/bin/bash" + SetScript="#!/bin/bash" + + } + + #Retrieve latest wordpress + nxFile WordPressTar{ + SourcePath = "/mnt/share/latest.zip" + DestinationPath = "/tmp/wordpress.zip" + Checksum = "md5" + Type = "file" + DependsOn = "[nxScript]nfsMount" + } + + #Extract wordpress if changed + nxArchive ExtractSite{ + SourcePath = "/tmp/wordpress.zip" + DestinationPath = "/var/www/wordpress" + Ensure = "Present" + DependsOn = "[nxFile]WordpressTar" + } + + #Set wp-config + + + #Fixup SE Linux context + #nxScript SELinuxContext{ + #TestScript= "#!/bin/bash" + #GetScript = "#!/bin/bash" + #SetScript = "#!/bin/bash" + #} + + #Disable SELinux + nxFileLine SELinux { + Filepath = "/etc/selinux/config" + DoesNotContainPattern = "SELINUX=enforcing" + ContainsLine = "SELINUX=disabled" + } + + + nxScript SELinuxHTTPNet{ + GetScript = "#!/bin/bash`ngetsebool httpd_can_network_connect" + setScript = "#!/bin/bash`nsetsebool -P httpd_can_network_connect=1" + TestScript = "#!/bin/bash`n exit 1" + } + + + + } + + } WordPressServer "@).Invoke() - Test-Path -Path .\WordPressServer\localhost.mof | Should Be $True + Test-Path -Path .\WordPressServer\localhost.mof | Should Be $True Remove-Item -Force -Recurse -Path WordPressServer } - It "Should be able to compile a MOF from a basic configuration on Windows" -Skip:($IsMacOS -or $IsLinux) { + It "Should be able to compile a MOF from a basic configuration on Windows" -Skip:($IsMacOS -or $IsLinux) { [Scriptblock]::Create(@" configuration DSCTestConfig { @@ -179,8 +179,8 @@ Describe "DSC MOF Compilation" -tags "CI" { Node "localhost" { File f1 { - DestinationPath = "$env:SystemDrive\\Test.txt"; - Ensure = "Present" + DestinationPath = "$env:SystemDrive\\Test.txt"; + Ensure = "Present" } } } @@ -188,12 +188,12 @@ Describe "DSC MOF Compilation" -tags "CI" { DSCTestConfig "@).Invoke() - Test-Path -Path .\DSCTestConfig\localhost.mof | Should Be $True + Test-Path -Path .\DSCTestConfig\localhost.mof | Should Be $True Remove-Item -Force -Recurse -Path DSCTestConfig } - It "Should be able to compile a MOF from a configuration with multiple resources on Windows" -Skip:($IsMacOS -or $IsLinux) { + It "Should be able to compile a MOF from a configuration with multiple resources on Windows" -Skip:($IsMacOS -or $IsLinux) { [Scriptblock]::Create(@" configuration DSCTestConfig { @@ -201,26 +201,26 @@ Describe "DSC MOF Compilation" -tags "CI" { Node "localhost" { File f1 { - DestinationPath = "$env:SystemDrive\\Test.txt"; - Ensure = "Present" + DestinationPath = "$env:SystemDrive\\Test.txt"; + Ensure = "Present" + } + Script s1 + { + GetScript = {return @{}} + SetScript = "Write-Verbose Hello" + TestScript = {return $false} + } + Log l1 + { + Message = "This is a log message" } - Script s1 - { - GetScript = {return @{}} - SetScript = "Write-Verbose Hello" - TestScript = {return $false} - } - Log l1 - { - Message = "This is a log message" - } } } DSCTestConfig "@).Invoke() - Test-Path -Path .\DSCTestConfig\localhost.mof | Should Be $True + Test-Path -Path .\DSCTestConfig\localhost.mof | Should Be $True Remove-Item -Force -Recurse -Path DSCTestConfig } From 5a13c3f341c30244a4468330289dc7708f5fedb6 Mon Sep 17 00:00:00 2001 From: Indhu Sivaramakrishnan Date: Tue, 10 Oct 2017 12:21:25 -0700 Subject: [PATCH 07/10] Update file exist check from Test-Path to Should Exist per code review feedback --- .../MOF-Compilation.Tests.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 index 5b2c022ef16..76972646715 100644 --- a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 +++ b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 @@ -26,7 +26,7 @@ Describe "DSC MOF Compilation" -tags "CI" { DSCTestConfig "@).Invoke() - Test-Path -Path .\DSCTestConfig\localhost.mof | Should Be $True + ".\DSCTestConfig\localhost.mof" | Should Exist Remove-Item -Force -Recurse -Path DSCTestConfig } @@ -50,7 +50,7 @@ Describe "DSC MOF Compilation" -tags "CI" { DSCTestConfig "@).Invoke() - Test-Path -Path .\DSCTestConfig\localhost.mof | Should Be $True + ".\DSCTestConfig\localhost.mof" | Should Exist Remove-Item -Force -Recurse -Path DSCTestConfig } @@ -166,7 +166,7 @@ Describe "DSC MOF Compilation" -tags "CI" { WordPressServer "@).Invoke() - Test-Path -Path .\WordPressServer\localhost.mof | Should Be $True + ".\WordPressServer\localhost.mof" | Should Exist Remove-Item -Force -Recurse -Path WordPressServer } @@ -188,7 +188,7 @@ Describe "DSC MOF Compilation" -tags "CI" { DSCTestConfig "@).Invoke() - Test-Path -Path .\DSCTestConfig\localhost.mof | Should Be $True + ".\DSCTestConfig\localhost.mof" | Should Exist Remove-Item -Force -Recurse -Path DSCTestConfig } @@ -220,7 +220,7 @@ Describe "DSC MOF Compilation" -tags "CI" { DSCTestConfig "@).Invoke() - Test-Path -Path .\DSCTestConfig\localhost.mof | Should Be $True + ".\DSCTestConfig\localhost.mof" | Should Exist Remove-Item -Force -Recurse -Path DSCTestConfig } From 99a04007fbdde6f5312b85ec6d5ff33d8b8d4b21 Mon Sep 17 00:00:00 2001 From: Indhu Sivaramakrishnan Date: Tue, 10 Oct 2017 13:07:40 -0700 Subject: [PATCH 08/10] Update name of MOF file for Wordpress configuration --- .../PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 index 76972646715..c8665bfabd5 100644 --- a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 +++ b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 @@ -166,7 +166,7 @@ Describe "DSC MOF Compilation" -tags "CI" { WordPressServer "@).Invoke() - ".\WordPressServer\localhost.mof" | Should Exist + ".\WordPressServer\CentOS.mof" | Should Exist Remove-Item -Force -Recurse -Path WordPressServer } From ef7400b6068ca200d017c4b9d676a877764a45a2 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 10 Oct 2017 13:51:32 -0700 Subject: [PATCH 09/10] update tests to use should not throw --- .../MOF-Compilation.Tests.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 index c8665bfabd5..615cfc88f81 100644 --- a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 +++ b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 @@ -24,7 +24,7 @@ Describe "DSC MOF Compilation" -tags "CI" { } DSCTestConfig -"@).Invoke() +"@) | should not throw ".\DSCTestConfig\localhost.mof" | Should Exist @@ -48,7 +48,7 @@ Describe "DSC MOF Compilation" -tags "CI" { } DSCTestConfig -"@).Invoke() +"@) | should not throw ".\DSCTestConfig\localhost.mof" | Should Exist @@ -164,7 +164,7 @@ Describe "DSC MOF Compilation" -tags "CI" { } WordPressServer -"@).Invoke() +"@) | should not throw ".\WordPressServer\CentOS.mof" | Should Exist @@ -186,7 +186,7 @@ Describe "DSC MOF Compilation" -tags "CI" { } DSCTestConfig -"@).Invoke() +"@) | should not throw ".\DSCTestConfig\localhost.mof" | Should Exist @@ -218,7 +218,7 @@ Describe "DSC MOF Compilation" -tags "CI" { } DSCTestConfig -"@).Invoke() +"@) | should not throw ".\DSCTestConfig\localhost.mof" | Should Exist From 24c1c87678f116cca0d4cd8d24168cddabbd5043 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 10 Oct 2017 14:45:19 -0700 Subject: [PATCH 10/10] convert test to use testdrive for automatic cleanup --- .../MOF-Compilation.Tests.ps1 | 32 +++++++------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 index 615cfc88f81..25492465adb 100644 --- a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 +++ b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 @@ -3,6 +3,7 @@ Describe "DSC MOF Compilation" -tags "CI" { AfterAll { $env:PSModulePath = $_modulePath } + BeforeAll { $env:DSC_HOME = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath dsc $_modulePath = $env:PSModulePath @@ -23,12 +24,10 @@ Describe "DSC MOF Compilation" -tags "CI" { } } - DSCTestConfig + DSCTestConfig -OutputPath TestDrive:\DscTestConfig1 "@) | should not throw - ".\DSCTestConfig\localhost.mof" | Should Exist - - Remove-Item -Force -Recurse -Path DSCTestConfig + "TestDrive:\DscTestConfig1\localhost.mof" | Should Exist } It "Should be able to compile a MOF from another basic configuration" -Skip:($IsMacOS -or $IsWindows) { @@ -47,12 +46,10 @@ Describe "DSC MOF Compilation" -tags "CI" { } } - DSCTestConfig + DSCTestConfig -OutputPath TestDrive:\DscTestConfig2 "@) | should not throw - ".\DSCTestConfig\localhost.mof" | Should Exist - - Remove-Item -Force -Recurse -Path DSCTestConfig + "TestDrive:\DscTestConfig2\localhost.mof" | Should Exist } It "Should be able to compile a MOF from a complex configuration" -Skip:($IsMacOS -or $IsWindows) { @@ -163,12 +160,10 @@ Describe "DSC MOF Compilation" -tags "CI" { } } - WordPressServer + WordPressServer -OutputPath TestDrive:\DscTestConfig3 "@) | should not throw - ".\WordPressServer\CentOS.mof" | Should Exist - - Remove-Item -Force -Recurse -Path WordPressServer + "TestDrive:\DscTestConfig3\CentOS.mof" | Should Exist } It "Should be able to compile a MOF from a basic configuration on Windows" -Skip:($IsMacOS -or $IsLinux) { @@ -185,12 +180,10 @@ Describe "DSC MOF Compilation" -tags "CI" { } } - DSCTestConfig + DSCTestConfig -OutputPath TestDrive:\DscTestConfig4 "@) | should not throw - ".\DSCTestConfig\localhost.mof" | Should Exist - - Remove-Item -Force -Recurse -Path DSCTestConfig + "TestDrive:\DscTestConfig4\localhost.mof" | Should Exist } It "Should be able to compile a MOF from a configuration with multiple resources on Windows" -Skip:($IsMacOS -or $IsLinux) { @@ -217,12 +210,9 @@ Describe "DSC MOF Compilation" -tags "CI" { } } - DSCTestConfig + DSCTestConfig -OutputPath TestDrive:\DscTestConfig5 "@) | should not throw - ".\DSCTestConfig\localhost.mof" | Should Exist - - Remove-Item -Force -Recurse -Path DSCTestConfig + "TestDrive:\DscTestConfig5\localhost.mof" | Should Exist } - }