Skip to content

Commit fe18c35

Browse files
Group command tests by feature file
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent bc02714 commit fe18c35

16 files changed

Lines changed: 351 additions & 422 deletions

tests/Auth/Connect-DomeneshopAccount.Tests.ps1 renamed to tests/Auth/Auth.Tests.ps1

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,60 @@ Describe 'Connect-DomeneshopAccount' {
133133
Should -Invoke Set-Context -Times 0 -Exactly
134134
}
135135
}
136+
137+
Describe 'Get-DomeneshopContext' {
138+
BeforeAll {
139+
. (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Domeneshop.TestSetup.ps1')
140+
}
141+
142+
It 'gets the configured default context' {
143+
Mock Get-DomeneshopConfig { [pscustomobject]@{ DefaultContext = 'demo' } }
144+
Mock Get-Context { [pscustomobject]@{ ID = 'demo' } }
145+
146+
$result = Get-DomeneshopContext
147+
148+
$result.ID | Should -Be 'demo'
149+
Should -Invoke Get-Context -Times 1 -Exactly -ParameterFilter {
150+
$ID -eq 'demo' -and $Vault -eq 'Domeneshop'
151+
}
152+
}
153+
154+
It 'throws when no default context is configured' {
155+
Mock Get-DomeneshopConfig { [pscustomobject]@{ DefaultContext = '' } }
156+
157+
{ Get-DomeneshopContext } | Should -Throw '*No default Domeneshop context found*'
158+
}
159+
160+
It 'rejects an explicit request for the reserved module configuration context' {
161+
{ Get-DomeneshopContext -Context '__Domeneshop.Config' } |
162+
Should -Throw '*reserved for Domeneshop module configuration*'
163+
}
164+
165+
It 'throws when the configured default context is missing from the vault' {
166+
Mock Get-DomeneshopConfig { [pscustomobject]@{ DefaultContext = 'missing' } }
167+
Mock Get-Context {}
168+
169+
{ Get-DomeneshopContext } |
170+
Should -Throw '*Domeneshop context*missing*was not found in the Domeneshop vault*'
171+
}
172+
173+
It 'throws when an explicitly requested context is missing from the vault' {
174+
Mock Get-Context {}
175+
176+
{ Get-DomeneshopContext -Context 'missing' } |
177+
Should -Throw '*Domeneshop context*missing*was not found in the Domeneshop vault*'
178+
}
179+
180+
It 'excludes the module configuration when listing contexts' {
181+
Mock Get-Context {
182+
@(
183+
[pscustomobject]@{ ID = '__Domeneshop.Config' }
184+
[pscustomobject]@{ ID = 'demo' }
185+
)
186+
}
187+
188+
$result = Get-DomeneshopContext -ListAvailable
189+
190+
$result.ID | Should -Be 'demo'
191+
}
192+
}

tests/Auth/Get-DomeneshopContext.Tests.ps1

Lines changed: 0 additions & 69 deletions
This file was deleted.
File renamed without changes.

tests/Dns/Add-DomeneshopDnsRecord.Tests.ps1

Lines changed: 0 additions & 40 deletions
This file was deleted.

tests/Dns/Dns.Tests.ps1

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#Requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '6.0.0'; MaximumVersion = '6.*' }
2+
3+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
4+
'PSReviewUnusedParameter', '',
5+
Justification = 'Required for Pester mock parameter filters.'
6+
)]
7+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
8+
'PSUseDeclaredVarsMoreThanAssignments', '',
9+
Justification = 'Required for Pester test setup.'
10+
)]
11+
[CmdletBinding()]
12+
param()
13+
14+
Describe 'Add-DomeneshopDnsRecord' {
15+
BeforeAll {
16+
. (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Domeneshop.TestSetup.ps1')
17+
}
18+
19+
BeforeEach {
20+
Mock Get-DomeneshopContext { $script:DomeneshopTestContext }
21+
Mock Invoke-DomeneshopApiRequest {}
22+
$script:Record = @{ host = 'www'; type = 'A'; data = '192.0.2.10' }
23+
}
24+
25+
It 'posts the DNS record to the domain endpoint' {
26+
Add-DomeneshopDnsRecord -Context 'demo' -DomainID 42 -Record $script:Record
27+
28+
Should -Invoke Invoke-DomeneshopApiRequest -Times 1 -Exactly -ParameterFilter {
29+
$Method -eq 'Post' -and
30+
$Uri -eq 'https://api.domeneshop.no/v0/domains/42/dns' -and
31+
$Body -eq $script:Record
32+
}
33+
}
34+
35+
It 'does not send a request when WhatIf is specified' {
36+
Add-DomeneshopDnsRecord -Context 'demo' -DomainID 42 -Record $script:Record -WhatIf
37+
38+
Should -Invoke Invoke-DomeneshopApiRequest -Times 0 -Exactly
39+
}
40+
}
41+
42+
Describe 'Get-DomeneshopDnsRecord' {
43+
BeforeAll {
44+
. (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Domeneshop.TestSetup.ps1')
45+
}
46+
47+
BeforeEach {
48+
Mock Get-DomeneshopContext { $script:DomeneshopTestContext }
49+
Mock Invoke-DomeneshopApiRequest {}
50+
}
51+
52+
It 'builds an escaped list query' {
53+
Get-DomeneshopDnsRecord -Context 'demo' -DomainID 42 -RecordHost 'home office' -Type 'A' -Data '192.0.2.10'
54+
55+
Should -Invoke Invoke-DomeneshopApiRequest -Times 1 -Exactly -ParameterFilter {
56+
$Method -eq 'Get' -and
57+
$Uri -eq 'https://api.domeneshop.no/v0/domains/42/dns?host=home%20office&type=A&data=192.0.2.10'
58+
}
59+
}
60+
61+
It 'gets a DNS record by ID' {
62+
Get-DomeneshopDnsRecord -Context 'demo' -DomainID 42 -RecordID 7
63+
64+
Should -Invoke Invoke-DomeneshopApiRequest -Times 1 -Exactly -ParameterFilter {
65+
$Method -eq 'Get' -and
66+
$Uri -eq 'https://api.domeneshop.no/v0/domains/42/dns/7'
67+
}
68+
}
69+
70+
It 'rejects whitespace-only list filters' {
71+
{ Get-DomeneshopDnsRecord -Context 'demo' -DomainID 42 -RecordHost ' ' } | Should -Throw
72+
{ Get-DomeneshopDnsRecord -Context 'demo' -DomainID 42 -Type ' ' } | Should -Throw
73+
{ Get-DomeneshopDnsRecord -Context 'demo' -DomainID 42 -Data ' ' } | Should -Throw
74+
75+
Should -Invoke Invoke-DomeneshopApiRequest -Times 0 -Exactly
76+
}
77+
}
78+
79+
Describe 'Remove-DomeneshopDnsRecord' {
80+
BeforeAll {
81+
. (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Domeneshop.TestSetup.ps1')
82+
}
83+
84+
BeforeEach {
85+
Mock Get-DomeneshopContext { $script:DomeneshopTestContext }
86+
Mock Invoke-DomeneshopApiRequest {}
87+
}
88+
89+
It 'deletes the DNS record endpoint' {
90+
Remove-DomeneshopDnsRecord -Context 'demo' -DomainID 42 -RecordID 7 -Confirm:$false
91+
92+
Should -Invoke Invoke-DomeneshopApiRequest -Times 1 -Exactly -ParameterFilter {
93+
$Method -eq 'Delete' -and
94+
$Uri -eq 'https://api.domeneshop.no/v0/domains/42/dns/7'
95+
}
96+
}
97+
98+
It 'does not send a request when WhatIf is specified' {
99+
Remove-DomeneshopDnsRecord -Context 'demo' -DomainID 42 -RecordID 7 -WhatIf
100+
101+
Should -Invoke Invoke-DomeneshopApiRequest -Times 0 -Exactly
102+
}
103+
}
104+
105+
Describe 'Set-DomeneshopDnsRecord' {
106+
BeforeAll {
107+
. (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Domeneshop.TestSetup.ps1')
108+
}
109+
110+
BeforeEach {
111+
Mock Get-DomeneshopContext { $script:DomeneshopTestContext }
112+
Mock Invoke-DomeneshopApiRequest {}
113+
$script:Record = @{ host = 'www'; type = 'A'; data = '192.0.2.20' }
114+
}
115+
116+
It 'puts the replacement record to the record endpoint' {
117+
Set-DomeneshopDnsRecord -Context 'demo' -DomainID 42 -RecordID 7 -Record $script:Record
118+
119+
Should -Invoke Invoke-DomeneshopApiRequest -Times 1 -Exactly -ParameterFilter {
120+
$Method -eq 'Put' -and
121+
$Uri -eq 'https://api.domeneshop.no/v0/domains/42/dns/7' -and
122+
$Body -eq $script:Record
123+
}
124+
}
125+
126+
It 'does not send a request when WhatIf is specified' {
127+
Set-DomeneshopDnsRecord -Context 'demo' -DomainID 42 -RecordID 7 -Record $script:Record -WhatIf
128+
129+
Should -Invoke Invoke-DomeneshopApiRequest -Times 0 -Exactly
130+
}
131+
}

tests/Dns/Get-DomeneshopDnsRecord.Tests.ps1

Lines changed: 0 additions & 49 deletions
This file was deleted.

tests/Dns/Remove-DomeneshopDnsRecord.Tests.ps1

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)