AzurePublicIPAddresses.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
Import-Module $PSScriptRoot\AzurePublicIPAddresses.psm1 -Force -Verbose


Describe 'AzurePublicIPAddresses' {
    Context 'Script Analyzer' {
        It 'Does not have any issues with the Script Analyser - Get-MicrosoftAzureDatacenterIPRange' {
            Invoke-ScriptAnalyzer $PSScriptRoot\Functions\Get-MicrosoftAzureDatacenterIPRange.ps1 | Should be $null
        }
        It 'Does not have any issues with the Script Analyser - Get-MicrosoftAzureDatacenterIPRangeFile' {
            Invoke-ScriptAnalyzer $PSScriptRoot\Functions\Get-MicrosoftAzureDatacenterIPRangeFile.ps1 | Should be $null
        }
    }

    Context 'Get-MicrosoftAzureDatacenterIPRange outputs results for each supported Azure region' {
        It 'returns output for West Europe' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'West Europe' | Should not be $null
        }

        It 'returns output for East US' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'East US'| Should not be $null
        }

        It 'returns output for East US 2' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'East US 2' | Should not be $null
        }

        It 'returns output for West US' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'West US' | Should not be $null
        }

        It 'returns output for North Central US' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'North Central US' | Should not be $null
        }

        It 'returns output for North Europe' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'North Europe' | Should not be $null
        }

        It 'returns output for Central US' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'Central US' | Should not be $null
        }

        It 'returns output for East Asia' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'East Asia' | Should not be $null
        }

        It 'returns output for Southeast Asia' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'Southeast Asia' | Should not be $null
        }

        It 'returns output for South Central US' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'South Central US' | Should not be $null
        }

        It 'returns output for Japan West' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'Japan West' | Should not be $null
        }

        It 'returns output for Japan East' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'Japan East' | Should not be $null
        }

        It 'returns output for Brazil South' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'Brazil South' | Should not be $null
        }

        It 'returns output for Australia East' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'Australia East' | Should not be $null
        }

        It 'returns output for Australia Southeast' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'Australia Southeast' | Should not be $null
        }

        It 'returns output for Central India' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'Central India' | Should not be $null
        }

        It 'returns output for West India' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'West India' | Should not be $null
        }

        It 'returns output for South India' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'South India' | Should not be $null
        }

        It 'returns output for Canada Central' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'Canada Central' | Should not be $null
        }

        It 'returns output for Canada East' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'Canada East' | Should not be $null
        }

        It 'returns output for West Central US' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'West Central US' | Should not be $null
        }

        It 'returns output for West US 2' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'West US 2' | Should not be $null
        }

        It 'returns output for UK South' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'UK South' | Should not be $null
        }

        <# Currently this region appears to be missing from the file (is available in Azure though)
        It 'returns output for UK West' {
            Get-MicrosoftAzureDatacenterIPRange -AzureRegion 'UK West' | Should not be $null
        }
        #>

        It 'accepts an Azure region from the pipeline' {
            {'West US 2' | Get-MicrosoftAzureDatacenterIPRange} | Should not be $null
        }

        It 'accepts multiple Azure regions from the pipeline' {
            { @('West US 2', 'Canada East') | Get-MicrosoftAzureDatacenterIPRange} | Should not be $null
        }

        It 'returns values if no region is specified' {
            Get-MicrosoftAzureDatacenterIPRange | Should not be $null
        }
    }

    Context 'File operations' {
        $TestPath = "TestDrive:\test.txt"

        It 'Get-MicrosoftAzureDatacenterIPRangeFile saves the IP range file as specified' {
            $Test = Get-MicrosoftAzureDatacenterIPRangeFile -Path $TestPath
            $Test | Should be $null
            Test-Path -Path $TestPath | Should be $true
        }

        It 'Get-MicrosoftAzureDatacenterIPRange reads from the IP range file if specifies' {
            Get-MicrosoftAzureDatacenterIPRange -Path $TestPath | should not be $null
        }
    }

    Context 'Get-MicrosoftAzureDatacenterIPRangeFile' {
        It 'outputs an xml document if no path is specified' {
            $null -ne  (Get-MicrosoftAzureDatacenterIPRangeFile).AzurePublicIpAddresses | should be $true
            $null -ne  (Get-MicrosoftAzureDatacenterIPRangeFile).AzurePublicIpAddresses.Region | should be $true
        }
    }
}