Skip to content

Commit 2dbdea0

Browse files
deadlydogCopilot
andcommitted
test: Use proper Pester v5 syntax for Mocks
Co-authored-by: Copilot <copilot@github.com>
1 parent 28b602d commit 2dbdea0

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

src/AzureArtifactsPowerShellModuleHelper/AzureArtifactsPowerShellModuleHelper.Tests.ps1

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ Describe 'Tests setup' {
7575

7676
Describe 'Registering an Azure Artifacts PS Repository' {
7777
Context 'When relying on retrieving the Azure Artifacts PAT from the environment variable that exists' {
78-
Mock Get-SecurePersonalAccessTokenFromEnvironmentVariable { return $SecurePersonalAccessToken } -ModuleName $ModuleNameBeingTested
78+
BeforeEach {
79+
Mock Get-SecurePersonalAccessTokenFromEnvironmentVariable { return $SecurePersonalAccessToken } -ModuleName $ModuleNameBeingTested
80+
}
7981

8082
It 'Should register a new PS repository properly when relying in PAT from environmental variable' {
8183
# Arrange.
@@ -209,7 +211,9 @@ Describe 'Registering an Azure Artifacts PS Repository' {
209211
}
210212

211213
Context 'When connecting to a feed without using a Credential' {
212-
Mock Get-AzureArtifactsCredential { return $null } -ModuleName $ModuleNameBeingTested
214+
BeforeEach {
215+
Mock Get-AzureArtifactsCredential { return $null } -ModuleName $ModuleNameBeingTested
216+
}
213217

214218
It 'Should not throw an error when credentials are not found. (Assumes the FeedUrl allows you to register it without a Credential)' {
215219
# Arrange.
@@ -228,7 +232,9 @@ Describe 'Registering an Azure Artifacts PS Repository' {
228232

229233
Describe 'Finding a PowerShell module from Azure Artifacts' {
230234
Context 'When relying on retrieving the Azure Artifacts PAT from the environment variable that exists' {
231-
Mock Get-SecurePersonalAccessTokenFromEnvironmentVariable { return $SecurePersonalAccessToken } -ModuleName $ModuleNameBeingTested
235+
BeforeEach {
236+
Mock Get-SecurePersonalAccessTokenFromEnvironmentVariable { return $SecurePersonalAccessToken } -ModuleName $ModuleNameBeingTested
237+
}
232238

233239
It 'Should find the module properly' {
234240
# Arrange.
@@ -241,7 +247,9 @@ Describe 'Finding a PowerShell module from Azure Artifacts' {
241247
}
242248

243249
Context 'When connecting to a feed without using a Credential' {
244-
Mock Get-AzureArtifactsCredential { return $null } -ModuleName $ModuleNameBeingTested
250+
BeforeEach {
251+
Mock Get-AzureArtifactsCredential { return $null } -ModuleName $ModuleNameBeingTested
252+
}
245253

246254
It 'Should throw an exception' {
247255
# Arrange.
@@ -267,7 +275,9 @@ Describe 'Finding a PowerShell module from Azure Artifacts' {
267275

268276
Describe 'Installing a PowerShell module from Azure Artifacts' {
269277
Context 'When relying on retrieving the Azure Artifacts PAT from the environment variable that exists' {
270-
Mock Get-SecurePersonalAccessTokenFromEnvironmentVariable { return $SecurePersonalAccessToken } -ModuleName $ModuleNameBeingTested
278+
BeforeEach {
279+
Mock Get-SecurePersonalAccessTokenFromEnvironmentVariable { return $SecurePersonalAccessToken } -ModuleName $ModuleNameBeingTested
280+
}
271281

272282
It 'Should install the module properly' {
273283
# Arrange.
@@ -284,7 +294,9 @@ Describe 'Installing a PowerShell module from Azure Artifacts' {
284294

285295
Describe 'Updating a PowerShell module from Azure Artifacts' {
286296
Context 'When relying on retrieving the Azure Artifacts PAT from the environment variable that exists' {
287-
Mock Get-SecurePersonalAccessTokenFromEnvironmentVariable { return $SecurePersonalAccessToken } -ModuleName $ModuleNameBeingTested
297+
BeforeEach {
298+
Mock Get-SecurePersonalAccessTokenFromEnvironmentVariable { return $SecurePersonalAccessToken } -ModuleName $ModuleNameBeingTested
299+
}
288300

289301
It 'Should update the module properly when already installed, resulting in 2 versions being installed' {
290302
# Arrange.
@@ -304,7 +316,9 @@ Describe 'Updating a PowerShell module from Azure Artifacts' {
304316

305317
Describe 'Installing-and-Updating a PowerShell module from Azure Artifacts' {
306318
Context 'When relying on retrieving the Azure Artifacts PAT from the environment variable that exists' {
307-
Mock Get-SecurePersonalAccessTokenFromEnvironmentVariable { return $SecurePersonalAccessToken } -ModuleName $ModuleNameBeingTested
319+
BeforeEach {
320+
Mock Get-SecurePersonalAccessTokenFromEnvironmentVariable { return $SecurePersonalAccessToken } -ModuleName $ModuleNameBeingTested
321+
}
308322

309323
It 'Should install the module properly' {
310324
# Arrange.

0 commit comments

Comments
 (0)