From 2a9cd7211fbcaee170eedab572ed88645aee0bd8 Mon Sep 17 00:00:00 2001 From: Indhu Sivaramakrishnan Date: Wed, 11 Oct 2017 10:49:35 -0700 Subject: [PATCH] Add tests for Dsc configuration compilation on Windows (#5011) --- .../MOF-Compilation.Tests.ps1 | 232 +++++++++++------- 1 file changed, 141 insertions(+), 91 deletions(-) diff --git a/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 b/test/powershell/Modules/PSDesiredStateConfiguration/MOF-Compilation.Tests.ps1 index dd9ac9ab6..25492465a 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,10 +24,10 @@ Describe "DSC MOF Compilation" -tags "CI" { } } - DSCTestConfig -"@).Invoke() + DSCTestConfig -OutputPath TestDrive:\DscTestConfig1 +"@) | should not throw - 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) { @@ -45,124 +46,173 @@ Describe "DSC MOF Compilation" -tags "CI" { } } - DSCTestConfig -"@).Invoke() + DSCTestConfig -OutputPath TestDrive:\DscTestConfig2 +"@) | should not throw - 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) { [Scriptblock]::Create(@" - Configuration WordPressServer{ + Configuration WordPressServer{ Import-DscResource -ModuleName PSDesiredStateConfiguration - Node CentOS{ + Node CentOS{ - #Ensure Apache packages are installed - nxPackage httpd { - Ensure = "Present" - Name = "httpd" - PackageManager = "yum" - } + #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" - } + #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" - } + 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 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" - } + #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" - } + #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" + #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" - } + #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" - } + #Extract wordpress if changed + nxArchive ExtractSite{ + SourcePath = "/tmp/wordpress.zip" + DestinationPath = "/var/www/wordpress" + Ensure = "Present" + DependsOn = "[nxFile]WordpressTar" + } - #Set wp-config + #Set wp-config - #Fixup SE Linux context - #nxScript SELinuxContext{ - #TestScript= "#!/bin/bash" - #GetScript = "#!/bin/bash" - #SetScript = "#!/bin/bash" - #} + #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" - } + #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" - } + 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() + } + WordPressServer -OutputPath TestDrive:\DscTestConfig3 +"@) | should not throw - 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) { + [Scriptblock]::Create(@" + configuration DSCTestConfig + { + Import-DscResource -ModuleName PSDesiredStateConfiguration + Node "localhost" { + File f1 + { + DestinationPath = "$env:SystemDrive\\Test.txt"; + Ensure = "Present" + } + } + } + + DSCTestConfig -OutputPath TestDrive:\DscTestConfig4 +"@) | should not throw + + "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) { + [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 -OutputPath TestDrive:\DscTestConfig5 +"@) | should not throw + + "TestDrive:\DscTestConfig5\localhost.mof" | Should Exist + } }