Pester - Multiple Values

This topic contains 2 replies, has 3 voices, and was last updated by Profile photo of Rob Simmers Rob Simmers 1 month, 2 weeks ago.

  • Author
    Posts
  • #55931
    Profile photo of Wei-Yen Tan
    Wei-Yen Tan
    Participant

    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!

  • #55939
    Profile photo of Adam Bertram
    Adam Bertram
    Participant

    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
    }

    }

  • #55942
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    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
        }
    }
    

You must be logged in to reply to this topic.