Using Pester tags in test logic

Welcome Forums Pester Using Pester tags in test logic

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
3 months ago.

  • Author
    Posts
  • #160851

    Participant
    Topics: 6
    Replies: 7
    Points: 35
    Rank: Member

    Is it possible to use Pester tags in logic?  For example, I have the following Describe block:

    Describe "Connected to vCenter instance 1" -Tag @("vmware-vdi","vmware-all") {
      Connect-ViServer MyVcenter1
      $arrConnectedViServers=$global:DefaultVIServers
      $bolConnected=$false
      foreach ($ConnectedViServerin$arrConnectedViServers) {
        if ($ConnectedViServer.Name -eq$VdiVcenter) {
          $bolConnected=$true
        }
      }
      It "We should be connected to the vCenter instance 1" {
        $bolConnected|Should Be $true
      }
    }

    Since I have two separate instances of VMware vCenter, I have to have two separate Describe blocks (using different tag arrays).  What I would like to be able to do is use a Switch statement based on the tags.  That would allow me to connect to either one or both vCenter instances in one Describe block.

  • #161949

    Participant
    Topics: 0
    Replies: 28
    Points: -7
    Rank: Member

    Not possible in v4, might be possible in v5 in the future once the metadata are available to the test itself. Then you might be able to so something like `switch ($test.root.tags[0])` but that is far in the future. Theoretially you can reach into the Pester internal state and find the tag (not sure right now where it is stored) and do the same thing, but that would depend on the internal state a lot, and would not be supported or reliable.

The topic ‘Using Pester tags in test logic’ is closed to new replies.