Tests/GetVirtualHost.Tests.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$here\TestSetup.ps1"
. "$here\..\Public\Get-RabbitMQVirtualHost.ps1"

function SetUpTest($vhosts = ("vh1","vh2")) {
    
    Add-RabbitMQVirtualHost -BaseUri $server -Name $vhosts

}
function TearDownTest($vhosts = ("vh1","vh2")) {
    
    foreach($vhost in $vhosts){
        Remove-RabbitMQVirtualHost -BaseUri $server -Name $vhost -ErrorAction Continue -Confirm:$false
    }
}

Describe -Tags "Example" "Get-RabbitMQVirtualHost" {

    It "should get Virtual Hosts registered with the server" {

        SetUpTest

        $actual = Get-RabbitMQVirtualHost -BaseUri $server | select -ExpandProperty name 

        $expected = $("/", "vh1", "vh2")

        AssertAreEqual $actual $expected

        TearDownTest
    }

    It "should get Virtual Hosts filtered by name" {

        SetUpTest

        $actual = Get-RabbitMQVirtualHost -BaseUri $server vh* | select -ExpandProperty name 

        $expected = $("vh1", "vh2")

        AssertAreEqual $actual $expected

        TearDownTest
    }

    It "should get VirtualHost names to filter by from the pipe" {

        SetUpTest

        $actual = $('vh1', 'vh2') | Get-RabbitMQVirtualHost -BaseUri $server | select -ExpandProperty name 

        $expected = $("vh1", "vh2")

        AssertAreEqual $actual $expected

        TearDownTest
    }

    It "should get VirtualHost and BaseUri from the pipe" {

        SetUpTest

        $pipe = $(
            New-Object -TypeName psobject -Prop @{"BaseUri" = $server; "Name" = "vh1" }
            New-Object -TypeName psobject -Prop @{"BaseUri" = $server; "Name" = "vh2" }
        )

        $actual = $pipe | Get-RabbitMQVirtualHost | select -ExpandProperty name 

        $expected = $("vh1", "vh2")

        AssertAreEqual $actual $expected

        TearDownTest
    }

    It "should pipe result from itself" {

        SetUpTest

        $actual = Get-RabbitMQVirtualHost -BaseUri $server | Get-RabbitMQVirtualHost | select -ExpandProperty name 

        $expected = Get-RabbitMQVirtualHost -BaseUri $server | select -ExpandProperty name 

        AssertAreEqual $actual $expected

        TearDownTest
    }
}