Skip to content

Commit e0fc6dc

Browse files
committed
Update test files to use the new logger module
- Import logger module and mock PS EventLog commands
1 parent cb3edde commit e0fc6dc

7 files changed

Lines changed: 36 additions & 5 deletions

Tests/AllToolsUtilities.Tests.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# #
77
###########################################################################
88

9+
using module ..\containers-toolkit\Private\Logger.psm1
910

1011
Describe "AllToolsUtilities.psm1" {
1112
BeforeAll {
@@ -17,6 +18,10 @@ Describe "AllToolsUtilities.psm1" {
1718
Import-Module -Name "$ModuleParentPath\Public\NerdctlTools.psm1" -Force
1819
Import-Module -Name "$ModuleParentPath\Public\ContainerNetworkTools.psm1" -Force
1920
Import-Module -Name "$ModuleParentPath\Public\AllToolsUtilities.psm1" -Force
21+
22+
# Mock functions
23+
Mock New-EventLog -ModuleName 'Logger'
24+
Mock Write-EventLog -ModuleName 'Logger'
2025
}
2126

2227
AfterAll {
@@ -268,4 +273,4 @@ Describe "AllToolsUtilities.psm1" {
268273
$Error[0].Exception.Message | Should -Be 'Failed to initialize NAT network. Error message'
269274
}
270275
}
271-
}
276+
}

Tests/BuildkitTools.Tests.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
###########################################################################
88

99
using module "..\containers-toolkit\Private\CommonToolUtilities.psm1"
10+
using module ..\containers-toolkit\Private\Logger.psm1
1011

1112
Describe "BuildkitTools.psm1" {
1213
BeforeAll {
@@ -28,6 +29,8 @@ Describe "BuildkitTools.psm1" {
2829
# Mock functions
2930
function Test-ServiceRegistered { }
3031
Mock Test-ServiceRegistered -ModuleName 'BuildkitTools' -MockWith { return $true }
32+
Mock New-EventLog -ModuleName 'Logger'
33+
Mock Write-EventLog -ModuleName 'Logger'
3134
}
3235

3336
AfterEach {
@@ -361,4 +364,4 @@ Describe "BuildkitTools.psm1" {
361364
Should -Invoke Remove-FeatureFromPath -Times 0 -Scope It -ModuleName "BuildkitTools"
362365
}
363366
}
364-
}
367+
}

Tests/CommonToolUtilities.Tests.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
using module "..\containers-toolkit\Private\CommonToolUtilities.psm1"
11+
using module ..\containers-toolkit\Private\Logger.psm1
1112

1213
$Script:SampleSha256Sum = @'
1314
6b8ff12339733a6SSaMpLeSHAe2ff9f8d333c9e898 nerdctl-2.0.0-linux-amd64.tar.gz
@@ -74,6 +75,10 @@ Describe "CommonToolUtilities.psm1" {
7475

7576
$ProgramFiles = "TestDrive:\Program Files"
7677
New-Item -Path $ProgramFiles -ItemType Directory -Force | Out-Null
78+
79+
# Mock functions
80+
Mock New-EventLog -ModuleName 'Logger'
81+
Mock Write-EventLog -ModuleName 'Logger'
7782
}
7883

7984
AfterAll {
@@ -838,4 +843,4 @@ Describe "CommonToolUtilities.psm1" {
838843
$Error[0].Exception.Message | Should -BeExactly "Failed to delete directory: 'TestDrive\Buildkit'. Error"
839844
}
840845
}
841-
}
846+
}

Tests/ContainerNetworkTools.Tests.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
using module "..\containers-toolkit\Private\CommonToolUtilities.psm1"
11+
using module ..\containers-toolkit\Private\Logger.psm1
1112

1213
Describe "ContainerNetworkTools.psm1" {
1314
BeforeAll {
@@ -17,6 +18,10 @@ Describe "ContainerNetworkTools.psm1" {
1718
Import-Module -Name "$ModuleParentPath\Private\CommonToolUtilities.psm1" -Force
1819
Import-Module -Name "$ModuleParentPath\Public\ContainerNetworkTools.psm1" -Force
1920
Import-Module -Name "$RootPath\Tests\TestData\MockClasses.psm1" -Force
21+
22+
# Mock functions
23+
Mock New-EventLog -ModuleName 'Logger'
24+
Mock Write-EventLog -ModuleName 'Logger'
2025
}
2126

2227
AfterEach {
@@ -295,4 +300,4 @@ Describe "ContainerNetworkTools.psm1" {
295300
$Error[0].Exception.Message | Should -Be 'Windows CNI plugin does not exist at TestDrive:\TestDir\cni or the directory is empty.'
296301
}
297302
}
298-
}
303+
}

Tests/ContainerdTools.Tests.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# #
77
###########################################################################
88

9+
using module ..\containers-toolkit\Private\Logger.psm1
910

1011
Describe "ContainerdTools.psm1" {
1112
BeforeAll {
@@ -28,6 +29,8 @@ Describe "ContainerdTools.psm1" {
2829
# Mock functions
2930
function Test-ServiceRegistered { }
3031
Mock Test-ServiceRegistered -ModuleName 'ContainerdTools' -MockWith { return $true }
32+
Mock New-EventLog -ModuleName 'Logger'
33+
Mock Write-EventLog -ModuleName 'Logger'
3134
}
3235

3336
AfterEach {
@@ -338,4 +341,4 @@ Describe "ContainerdTools.psm1" {
338341
Should -Invoke Remove-FeatureFromPath -Times 0 -Scope It -ModuleName "ContainerdTools"
339342
}
340343
}
341-
}
344+
}

Tests/NerdctlTools.Tests.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
using module "..\containers-toolkit\Private\CommonToolUtilities.psm1"
11+
using module ..\containers-toolkit\Private\Logger.psm1
1112

1213
Describe "NerdctlTools.psm1" {
1314
BeforeAll {
@@ -18,6 +19,10 @@ Describe "NerdctlTools.psm1" {
1819
Import-Module -Name "$ModuleParentPath\Public\ContainerdTools.psm1"
1920
Import-Module -Name "$ModuleParentPath\Public\ContainerNetworkTools.psm1"
2021
Import-Module -Name "$ModuleParentPath\Public\NerdctlTools.psm1" -Force
22+
23+
# Mock functions
24+
Mock New-EventLog -ModuleName 'Logger'
25+
Mock Write-EventLog -ModuleName 'Logger'
2126
}
2227

2328
AfterEach {

Tests/UpdateEnvironmentPath.Tests.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# #
77
###########################################################################
88

9+
using module ..\containers-toolkit\Private\Logger.psm1
910

1011
Describe "UpdateEnvironmentPath.psm1" {
1112
BeforeAll {
@@ -16,6 +17,10 @@ Describe "UpdateEnvironmentPath.psm1" {
1617
# Original enviromnent values
1718
$Script:originalUserPathString = $ENV:Path
1819
$Script:originalSysPathString = [System.Environment]::GetEnvironmentVariable("Path", "Machine")
20+
21+
# Mock functions
22+
Mock New-EventLog -ModuleName 'Logger'
23+
Mock Write-EventLog -ModuleName 'Logger'
1924
}
2025

2126
AfterAll {

0 commit comments

Comments
 (0)