Skip to content

Commit

Permalink
Merge pull request #16 from arkasha/dev
Browse files Browse the repository at this point in the history
Adding web binding cert store tests
  • Loading branch information
TravisEz13 committed May 26, 2015
2 parents d4de005 + 68b14af commit ef3b635
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DSCResources/MSFT_xWebsite/MSFT_xWebsite.schema.mof
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Class MSFT_xWebBindingInformation
[write]String IPAddress;
[write]String HostName;
[write]String CertificateThumbprint;
[write,ValueMap{"Personal", "WebHosting"},Values{"Personal", "WebHosting"}] string CertificateStoreName;
[write,ValueMap{"My", "WebHosting"},Values{"My", "WebHosting"}] string CertificateStoreName;
};


Expand Down
50 changes: 50 additions & 0 deletions Tests/MSFT_xWebBindingInformation.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Path

# should check for the server OS
if($env:APPVEYOR_BUILD_VERSION)
{
Add-WindowsFeature Web-Server -Verbose
}

Import-Module (Join-Path $here -ChildPath "..\DSCResources\MSFT_xWebsite\MSFT_xWebsite.psm1")

Describe "MSFT_xWebBindingInformation" {
It 'Should be able to get xWebsite' -test {
# just a good idea.
# I thought it might force the classes to register, but it does not.
$resources = Get-DscResource -Name xWebsite
$resources.count | should be 1
}

It 'Should compile and run without throwing (But does not currently forcing pass)' -test {
{
# Force Cim Classes to register
# Update the system environment path so that LCM will load the module
# Requires WMF 5
[System.Environment]::SetEnvironmentVariable('PSModulePath',$env:PSModulePath,[System.EnvironmentVariableTarget]::Machine)
configuration foo
{
Import-DscResource -ModuleName xWebAdministration

xWebsite foo
{
Name = 'foobar'
Ensure = 'absent'
}
}

foo -OutputPath $env:temp\foo
Start-DscConfiguration -Path $env:temp\foo -Wait -Verbose -ErrorAction Stop} | should throw # This really should not throw, needs fix
}

# Directly interacting with Cim classes is not supported by PowerShell DSC
# it is being done here explicitly for the purpose of testing. Please do not
# do this in actual resource code
$xWebBindingInforationClass = (Get-CimClass -Namespace "root/microsoft/Windows/DesiredStateConfiguration" -ClassName "MSFT_xWebBindingInformation")
$storeNames = (Get-CimClass -Namespace "root/microsoft/Windows/DesiredStateConfiguration" -ClassName "MSFT_xWebBindingInformation").CimClassProperties['CertificateStoreName'].Qualifiers['Values'].Value
foreach ($storeName in $storeNames){
It "Uses valid credential store: $storeName" {
(Join-Path -Path Cert:\LocalMachine -ChildPath $storeName) | Should Exist
}
}
}
5 changes: 5 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This is necessary to use WMF5
os: unstable
install:
- cinst -y pester
- git clone https://github.com/PowerShell/DscResource.Tests
Expand All @@ -7,7 +9,10 @@ build: false
test_script:
- ps: |
$testResultsFile = ".\TestsResults.xml"
$tempModulePath = (Resolve-Path (join-path $PWD '..')).ProviderPath
$env:PSModulePath = "$env:PSModulePath;$tempModulePath"
$res = Invoke-Pester -OutputFormat NUnitXml -OutputFile $testResultsFile -PassThru
(New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $testResultsFile))
if ($res.FailedCount -gt 0) {
throw "$($res.FailedCount) tests failed."
Expand Down

0 comments on commit ef3b635

Please sign in to comment.