Add tests for Dsc configuration compilation on Windows (#5011)

This commit is contained in:
Indhu Sivaramakrishnan 2017-10-11 10:49:35 -07:00 committed by Travis Plunk
parent f6864c3def
commit 2a9cd7211f

View file

@ -3,6 +3,7 @@ Describe "DSC MOF Compilation" -tags "CI" {
AfterAll { AfterAll {
$env:PSModulePath = $_modulePath $env:PSModulePath = $_modulePath
} }
BeforeAll { BeforeAll {
$env:DSC_HOME = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath dsc $env:DSC_HOME = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath dsc
$_modulePath = $env:PSModulePath $_modulePath = $env:PSModulePath
@ -23,10 +24,10 @@ Describe "DSC MOF Compilation" -tags "CI" {
} }
} }
DSCTestConfig DSCTestConfig -OutputPath TestDrive:\DscTestConfig1
"@).Invoke() "@) | 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) { 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 DSCTestConfig -OutputPath TestDrive:\DscTestConfig2
"@).Invoke() "@) | 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) { It "Should be able to compile a MOF from a complex configuration" -Skip:($IsMacOS -or $IsWindows) {
[Scriptblock]::Create(@" [Scriptblock]::Create(@"
Configuration WordPressServer{ Configuration WordPressServer{
Import-DscResource -ModuleName PSDesiredStateConfiguration Import-DscResource -ModuleName PSDesiredStateConfiguration
Node CentOS{ Node CentOS{
#Ensure Apache packages are installed #Ensure Apache packages are installed
nxPackage httpd { nxPackage httpd {
Ensure = "Present" Ensure = "Present"
Name = "httpd" Name = "httpd"
PackageManager = "yum" PackageManager = "yum"
} }
#Include vhostdir #Include vhostdir
nxFile vHostDir{ nxFile vHostDir{
DestinationPath = "/etc/httpd/conf.d/vhosts.conf" DestinationPath = "/etc/httpd/conf.d/vhosts.conf"
Ensure = "Present" Ensure = "Present"
Contents = "IncludeOptional /etc/httpd/sites-enabled/*.conf`n" Contents = "IncludeOptional /etc/httpd/sites-enabled/*.conf`n"
Type = "File" Type = "File"
} }
nxFile vHostDirectory{ nxFile vHostDirectory{
DestinationPath = "/etc/httpd/sites-enabled" DestinationPath = "/etc/httpd/sites-enabled"
Type = "Directory" Type = "Directory"
Ensure = "Present" Ensure = "Present"
} }
#Ensure directory for Wordpress site #Ensure directory for Wordpress site
nxFile wpHttpDir{ nxFile wpHttpDir{
DestinationPath = "/var/www/wordpress" DestinationPath = "/var/www/wordpress"
Type = "Directory" Type = "Directory"
Ensure = "Present" Ensure = "Present"
Mode = "755" Mode = "755"
} }
#Ensure share directory #Ensure share directory
nxFile share{ nxFile share{
DestinationPath = "/mnt/share" DestinationPath = "/mnt/share"
Type = "Directory" Type = "Directory"
Ensure = "Present" Ensure = "Present"
Mode = "755" Mode = "755"
} }
#Bind httpd to port 8080 #Bind httpd to port 8080
nxFile HttpdPort{ nxFile HttpdPort{
DestinationPath = "/etc/httpd/conf.d/listen.conf" DestinationPath = "/etc/httpd/conf.d/listen.conf"
Ensure = "Present" Ensure = "Present"
Contents = "Listen 8080`n" Contents = "Listen 8080`n"
Type = "File" Type = "File"
} }
#nfs mounts #nfs mounts
nxScript nfsMount{ nxScript nfsMount{
TestScript= "#!/bin/bash" TestScript= "#!/bin/bash"
GetScript="#!/bin/bash" GetScript="#!/bin/bash"
SetScript="#!/bin/bash" SetScript="#!/bin/bash"
} }
#Retrieve latest wordpress #Retrieve latest wordpress
nxFile WordPressTar{ nxFile WordPressTar{
SourcePath = "/mnt/share/latest.zip" SourcePath = "/mnt/share/latest.zip"
DestinationPath = "/tmp/wordpress.zip" DestinationPath = "/tmp/wordpress.zip"
Checksum = "md5" Checksum = "md5"
Type = "file" Type = "file"
DependsOn = "[nxScript]nfsMount" DependsOn = "[nxScript]nfsMount"
} }
#Extract wordpress if changed #Extract wordpress if changed
nxArchive ExtractSite{ nxArchive ExtractSite{
SourcePath = "/tmp/wordpress.zip" SourcePath = "/tmp/wordpress.zip"
DestinationPath = "/var/www/wordpress" DestinationPath = "/var/www/wordpress"
Ensure = "Present" Ensure = "Present"
DependsOn = "[nxFile]WordpressTar" DependsOn = "[nxFile]WordpressTar"
} }
#Set wp-config #Set wp-config
#Fixup SE Linux context #Fixup SE Linux context
#nxScript SELinuxContext{ #nxScript SELinuxContext{
#TestScript= "#!/bin/bash" #TestScript= "#!/bin/bash"
#GetScript = "#!/bin/bash" #GetScript = "#!/bin/bash"
#SetScript = "#!/bin/bash" #SetScript = "#!/bin/bash"
#} #}
#Disable SELinux #Disable SELinux
nxFileLine SELinux { nxFileLine SELinux {
Filepath = "/etc/selinux/config" Filepath = "/etc/selinux/config"
DoesNotContainPattern = "SELINUX=enforcing" DoesNotContainPattern = "SELINUX=enforcing"
ContainsLine = "SELINUX=disabled" ContainsLine = "SELINUX=disabled"
} }
nxScript SELinuxHTTPNet{ nxScript SELinuxHTTPNet{
GetScript = "#!/bin/bash`ngetsebool httpd_can_network_connect" GetScript = "#!/bin/bash`ngetsebool httpd_can_network_connect"
setScript = "#!/bin/bash`nsetsebool -P httpd_can_network_connect=1" setScript = "#!/bin/bash`nsetsebool -P httpd_can_network_connect=1"
TestScript = "#!/bin/bash`n exit 1" TestScript = "#!/bin/bash`n exit 1"
} }
} }
} }
WordPressServer WordPressServer -OutputPath TestDrive:\DscTestConfig3
"@).Invoke() "@) | 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
}
} }