Tuesday, December 02, 2014

Pester tests are like any other script. They grow and evolve
over time. Here are a few more tests that I have testing my DSC resources and
configurations that I recently added to my collection.

Does every resource
have a pester test?

This is probably one of the most important tests I have.
Every resource should have a test, so why not test for that?

describe"DSCResources
located in $PSScriptRoot\DSCResources" {

foreach($Resourcein$ResourceList)

{

context$Resource.name
{

it"Has a pester test" {

($Resource.fullname +"\*.test.ps1") |shouldexist

}

If it is a standard
resource, does it have the files it needs?

Each DSC resource needs to have two files in it. A *.psm1
file and a *.schema.mof file. I use the *.psm1 file as a quick way to identify
standard resources differently than a composite resource. I know I will not
ever reach a test condition that would cause once of these to fail, but I left
it in place so I could change the logic later.

if(Test-Path
($Resource.fullname
+"\$Resource.psm1"))

{

it"Has a $Resource.schema.mof" {

($Resource.fullname
+"\$Resource.schema.mof")
|shouldexist

}

it"Has a $Resource.psm1" {

($Resource.fullname
+"\$Resource.psm1")
|shouldexist

}

Does it pass
Test-xDscSchema and Test-xDscResource tests?

I may as well test for these as part of my pester tests.
They already validate a lot of things that are easy to overlook.

A composite resource uses different files than a standard
resource. It has a *.psd1 and a *.shema.psm1 that should exists. I don’t have
any Test-xDSC functions for the composite resources so I add a few extra
checks. I verify that the *.psd1 file references the *.psm1 and that the module
does not throw any errors when dot sourcing it.

Have you ever ...

Have you ever had a problem that is hard to search on? Some key words generate too many unrelated results. Other problems may be so basic that it’s just expected everyone will know it. I often run into problems that I expect others to have but nobody talks about it or just accepts that’s the way it is.

When I run into something that felt like it was harder to find then it should be, I will post it here. I don't have a set theme and many of my solutions are unrelated. But I hope you were able to find the solution to your problem within the pages of my blog.