-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRemove-Configuration.Unit.Tests.ps1
More file actions
146 lines (118 loc) · 5.98 KB
/
Copy pathRemove-Configuration.Unit.Tests.ps1
File metadata and controls
146 lines (118 loc) · 5.98 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "5.7"; MaximumVersion = "5.999" }
Describe "Remove-Configuration" -Tag Unit {
BeforeAll {
. "$PSScriptRoot/../Helpers/TestTools.ps1"
$script:moduleToTest = Initialize-TestEnvironment
Import-Module $script:moduleToTest
}
InModuleScope "AtlassianPS.Configuration" {
BeforeEach {
#region Mocking
Mock Write-DebugMessage -ModuleName "AtlassianPS.Configuration" {}
Mock Write-Verbose -ModuleName "AtlassianPS.Configuration" {}
Mock Save-Configuration -ModuleName "AtlassianPS.Configuration" {}
Mock Get-Configuration {
$tempConfig = $script:Configuration.Clone()
$tempConfig.Keys |
ForEach-Object {
[PSCustomObject]@{
Name = $_
Value = $tempConfig[$_]
}
}
}
#endregion Mocking
}
Context "Sanity checking" {
BeforeAll {
$script:command = Get-Command -Name Remove-Configuration
}
It "has a mandatory parameter 'Name' of type [String[]] with ArgumentCompleter" {
$command | Should -HaveParameter "Name" -Mandatory -Type [String[]] -HasArgumentCompleter
}
}
Context "Behavior checking" {
#region Arrange
BeforeEach {
$script:Configuration = @{
Foo = "lorem ipsum"
Bar = 42
Baz = (Get-Date)
ServerList = @(
[AtlassianPS.ServerData]@{
Id = 1
Name = "Google"
Uri = "https://google.com"
Type = "Jira"
}
[AtlassianPS.ServerData]@{
Id = 2
Name = "Google with Session"
Uri = "https://google.com"
Type = "Jira"
Session = (New-Object -TypeName Microsoft.PowerShell.Commands.WebRequestSession)
}
)
}
}
#endregion Arrange
It "removes one entry of the configuration" {
Get-Configuration | Should -HaveCount 4
Get-Configuration | Where-Object Name -eq "Foo" | Should -Not -BeNullOrEmpty
Get-Configuration | Where-Object Name -eq "Bar" | Should -Not -BeNullOrEmpty
Remove-Configuration -Name "Foo"
Get-Configuration | Should -HaveCount 3
Get-Configuration | Where-Object Name -eq "Foo" | Should -BeNullOrEmpty
Get-Configuration | Where-Object Name -eq "Bar" | Should -Not -BeNullOrEmpty
}
It "does not remove or save a configuration key when WhatIf is used" {
Remove-Configuration -Name "Foo" -WhatIf
Get-Configuration | Should -HaveCount 4
Get-Configuration | Where-Object Name -eq "Foo" | Should -Not -BeNullOrEmpty
Should -Invoke "Save-Configuration" -ModuleName "AtlassianPS.Configuration" -Exactly -Times 0 -Scope It
}
It "removes multiple entries at once" {
Get-Configuration | Should -HaveCount 4
Get-Configuration | Where-Object Name -eq "Foo" | Should -Not -BeNullOrEmpty
Get-Configuration | Where-Object Name -eq "Bar" | Should -Not -BeNullOrEmpty
Get-Configuration | Where-Object Name -eq "Baz" | Should -Not -BeNullOrEmpty
Remove-Configuration -Name "Foo", "Bar"
Get-Configuration | Should -HaveCount 2
Get-Configuration | Where-Object Name -eq "Foo" | Should -BeNullOrEmpty
Get-Configuration | Where-Object Name -eq "Bar" | Should -BeNullOrEmpty
Get-Configuration | Where-Object Name -eq "Baz" | Should -Not -BeNullOrEmpty
}
It "accepts an object over the pipeline" {
Get-Configuration | Should -HaveCount 4
Get-Configuration |
Where-Object Name -ne "ServerList" |
Remove-Configuration
Get-Configuration | Should -HaveCount 1
Get-Configuration | Where-Object Name -eq "ServerList" | Should -Not -BeNullOrEmpty
}
It "accepts strings over the pipeline" {
Get-Configuration | Should -HaveCount 4
"Foo", "Bar" | Remove-Configuration
Get-Configuration | Should -HaveCount 2
}
It "is not case sensitive" {
Get-Configuration | Should -HaveCount 4
Get-Configuration | Where-Object Name -eq "Foo" | Should -Not -BeNullOrEmpty
Get-Configuration | Where-Object Name -eq "Bar" | Should -Not -BeNullOrEmpty
Remove-Configuration -Name "foo"
Get-Configuration | Should -HaveCount 3
Get-Configuration | Where-Object Name -eq "Foo" | Should -BeNullOrEmpty
Get-Configuration | Where-Object Name -eq "Bar" | Should -Not -BeNullOrEmpty
}
It "does not allow reserved configuration keys to be removed" {
{ Remove-Configuration -Name "ServerList" -ErrorAction Stop } | Should -Throw
Get-Configuration | Where-Object Name -eq "ServerList" | Should -Not -BeNullOrEmpty
}
It "allows the Message configuration key to be removed" {
$script:Configuration["Message"] = [AtlassianPS.MessageStyle]::new()
Remove-Configuration -Name "Message"
Get-Configuration | Where-Object Name -eq "Message" | Should -BeNullOrEmpty
}
}
}
}