-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExtensions.tests.ps1
More file actions
128 lines (106 loc) · 5.13 KB
/
Copy pathExtensions.tests.ps1
File metadata and controls
128 lines (106 loc) · 5.13 KB
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
BeforeDiscovery {
$ModuleName = 'AzureDevOpsPowerShell'
Get-Module $ModuleName | Remove-Module -Force -ErrorAction Ignore
$path = Join-Path -Path $PSScriptRoot -ChildPath "..\..\..\..\$ModuleName\$ModuleName.psm1" | Resolve-Path
Import-Module -Name $path -Verbose:$false -ErrorAction Stop
}
InModuleScope $ModuleName {
BeforeAll {
$collectionUri = "https://dev.azure.com/AzureDevOpsPowerShell"
$params = @{
CollectionUri = $collectionUri
Confirm = $false
}
}
Describe "Get-AzDoExtension" -Tag Local {
BeforeAll {
Mock Invoke-AzDoRestMethod {
@{
value = @(
[PSCustomObject]@{
CollectionURI = $CollectionUri
ExtensionCollectionURI = $extensionCollectionUri
ExtensionId = 'vss-testextension'
ExtensionName = 'extensionTest'
ExtensionPublisherId = 'rbnmk'
ExtensionPublisherName = 'RobinM'
ExtensionVersion = '0.0.1'
ExtensionBaseUri = 'baseUri'
ExtensionFallbackBaseUri = 'fallbackBaseUri'
}
[PSCustomObject]@{
CollectionURI = $CollectionUri
ExtensionCollectionURI = $extensionCollectionUri
ExtensionId = 'vss-testextension2'
ExtensionName = 'extensionTest2'
ExtensionPublisherId = 'rbnmk2'
ExtensionPublisherName = 'RobinM2'
ExtensionVersion = '0.0.1'
ExtensionBaseUri = 'baseUri2'
ExtensionFallbackBaseUri = 'fallbackBaseUri2'
}
[PSCustomObject]@{
CollectionURI = $CollectionUri
ExtensionCollectionURI = $extensionCollectionUri
ExtensionId = 'vss-testextension3'
ExtensionName = 'extensionTest3'
ExtensionPublisherId = 'rbnmk3'
ExtensionPublisherName = 'RobinM3'
ExtensionVersion = '0.0.1'
ExtensionBaseUri = 'baseUri3'
ExtensionFallbackBaseUri = 'fallbackBaseUri3'
}
)
}
}
}
It "It provides users with feedback via ShouldProcess when using WhatIf" {
Get-AzDoExtension @params -WhatIf -Verbose 4>&1 | Out-String | Should -BeLike "*Calling Invoke-AzDoRestMethod with {*"
}
It "Outputs all extensions when no value to ExtensionName or ExtensionId was provided" {
(Get-AzDoExtension @params | Measure-Object).Count | Should -BeGreaterThan 1
}
It "Outputs extension which matches the name of ExtensionName" {
(Get-AzDoExtension @params -ExtensionName "extensionTest3").ExtensionName | Should -Be "extensionTest3"
}
It "Outputs extension which matches the Id of ExtensionId" {
(Get-AzDoExtension @params -ExtensionId "vss-testextension2").ExtensionId | Should -Be "vss-testextension2"
}
It "Outputs extensions which matches the Id of ExtensionId AND ExtensionName" {
(Get-AzDoExtension @params -ExtensionId "vss-testextension2" -ExtensionName "extensionTest3" | Measure-Object).count | Should -BeExactly 2
}
}
Describe "New-AzDoExtension" -Tag Local {
BeforeAll {
$params.Add("ExtensionId", "vss-testextension")
$params.Add("ExtensionPublisherId", "rbnmk")
Mock Invoke-AzDoRestMethod { $null }
}
It "It provides users with feedback via ShouldProcess when using WhatIf" {
New-AzDoExtension @params -WhatIf -Verbose 4>&1 | Out-String | Should -BeLike "*Calling Invoke-AzDoRestMethod with {*"
}
It "Installs AzDo extension when ExtensionId and ExtensionPublisherId are provided and returns null or empty" {
(New-AzDoExtension @params) | Should -BeNullOrEmpty
}
It "Installs AzDo extension when ExtensionId, ExtensionPublisherId and ExtensionVersion are provided and returns null or empty" {
$params.Add("ExtensionVersion", "0.0.1")
(New-AzDoExtension @params) | Should -BeNullOrEmpty
}
It "Throws exception when ExtensionId/PublisherName is already installed" {
Mock Invoke-AzDoRestMethod { throw "Extension already installed" }
{ New-AzDoExtension @params } | Should -Throw -Because "Extension already installed"
}
}
Describe "Remove-AzDoExtension" -Tag Local {
BeforeAll {
Mock Invoke-AzDoRestMethod { $null }
$params.Remove("ExtensionVersion")
}
It "It provides users with feedback via ShouldProcess when using WhatIf" {
Remove-AzDoExtension @params -ExtensionId "vss-testextension" -ExtensionPublisherid "pesterpublisher" -WhatIf -Verbose 4>&1 | Out-String | Should -BeLike "*Calling Invoke-AzDoRestMethod with {*"
}
It "Removes AzDo extension when ExtensionId and ExtensionPublisherId are provided and returns null or empty" {
(New-AzDoExtension @params -ExtensionId "vss-testextension" -ExtensionPublisherid "pesterpublisher") | Should -BeNullOrEmpty
}
}
}