Author Posts

October 24, 2016 at 11:51 pm

I am just testing out a statement in Pesterto test multiple values.

The reason why I am doing this is to get the values of DNS Client Server address. I know I will get multiple values so I thought I would write a 'proof of concept' test below:

Describe "Test pester test" {
    It "Test multiple strings and contain" {
        $a =  '192.168.1.234' , '192.168.1.235'
       $a | should contain '192.168.1.234' , '192.168.1.235'
    }

}

However what I am finding is that Pester does not accept the string value like what I have listed above.
Is there any way that I can test on multiple values in pester? Or is this not possible? Or another way to test DNS Client Server address?

Thanks for any guidance!

October 25, 2016 at 1:05 am

The contain operator checks for file contents. To compare an array with an array, I'd use Compare-Object. Something like this should work:

Describe "Test pester test" {
It "Test multiple strings and contain" {
$expectedValues = '192.168.1.234' , '192.168.1.235'
$actualValues = '192.168.1.234','192,168.1.235'
Compare-Object $expectedValues $actualValues | should be $null
}

}

October 25, 2016 at 1:40 am

Could do something like this:

Describe "Test DNS Suffix" {
    $a =  '192.168.1.234' , '192.168.1.235'
    It "Test contains Primary DNS server" {
       $a -contains '192.168.1.234' | Should Be $true
    }
    It "Test contains Secondary DNS server" {
       $a -contains '192.168.1.235' | Should Be $true
    }
}