Tests/Server/BambooServer.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
. (Join-Path $PSScriptRoot '../TestCommon.ps1')

Describe "Bamboo Server cmdlets" {
    $expectedUrl = 'http://this-is-my-expected-url.com:1234'

    Context "Get-BambooServer" {
        $defaultUrl = 'http://localhost:8085'
        it "should have '$defaultUrl' as the default url" {
            Get-BambooServer | Should Be $defaultUrl
        }
    }

    Context "Set-BambooServer" {
        it "should accept only valid urls" {
            { Set-BambooServer -Url '' } | Should Throw
            { Set-BambooServer -Url 'wrongurl' } | Should Throw
            { Set-BambooServer -Url 'ftp://localhost' } | Should Throw

            Set-BambooServer -Url 'http://localhost' | Should BeNullOrEmpty
            Set-BambooServer -Url 'https://localhost'  | Should BeNullOrEmpty
            Set-BambooServer -Url 'http://localhost:8085'  | Should BeNullOrEmpty
            Set-BambooServer -Url 'https://localhost:8085' | Should BeNullOrEmpty
        }

        it "should modify url for valid urls" {
            Set-BambooServer -Url $expectedUrl | Should BeNullOrEmpty
            Get-BambooServer | Should Be $expectedUrl
        }

        it "should not modify url for invalid urls" {
            Set-BambooServer -Url $expectedUrl

            { Set-BambooServer -Url 'wrongurl' } | Should Throw
            Get-BambooServer | Should Be $expectedUrl
        }
    }
}