microsoft / DSCEA

DSC Environment Analyzer (DSCEA) is a simple implementation of PowerShell Desired State Configuration that uses the declarative nature of DSC to scan systems in an environment against a defined reference MOF file and generate compliance reports as to whether systems match the desired configuration.
https://microsoft.github.io/DSCEA
Other
197 stars 41 forks source link

All functions should return values for Pester integration #12

Closed krjhitch closed 7 years ago

krjhitch commented 7 years ago

Pester as a framework seems to be limited to a) not handling non-function/cmdlet code, and not handling anything called in the runspaces

rkyttle commented 7 years ago

How come I was able to get things to work just using write-host?

krjhitch commented 7 years ago

I didn't find any issue with starting/testing the main function, but to test the logic - things like 'if I pass in 2 CIM objects, I want Test-DSCConfiguration to be called twice' I can't test, since those runspaces are hidden from the pipeline (and therefore pester). Additionally, since I can't mock Test-DSCConfiguration I re-direct it to run synthetically (and test for success/failure scenarios).

The big key is going to be the integration testing, which hopefully we can test in appveyor, or if not, we work on a script that looks similar to the following:

Set-Location $env:temp
Import-Module -Path .\DSCEA.psm1
SampleConfig.ps1 (generate localhost.mof)
Start-DSCEAScan -ComputerName 'localhost'
Start-DSCEAScan -ComputerName 'localhost','expectedServer1'
Get-DSCEAReport -Overall
Get-DSCEAReport -Compliance
$results = (Import-XMLCLI).TestForNoExceptionsSomehow()

As long as we write everything to a temp directory and/or clean up with each run, that'll be useful, but I'm not sure how much good pester itself is going to do