From e0fc6dc014cbd3106bbbefe6f345e81cd231b579 Mon Sep 17 00:00:00 2001 From: TinaMor Date: Tue, 20 May 2025 23:40:07 +0300 Subject: [PATCH] Update test files to use the new logger module - Import logger module and mock PS EventLog commands --- Tests/AllToolsUtilities.Tests.ps1 | 7 ++++++- Tests/BuildkitTools.Tests.ps1 | 5 ++++- Tests/CommonToolUtilities.Tests.ps1 | 7 ++++++- Tests/ContainerNetworkTools.Tests.ps1 | 7 ++++++- Tests/ContainerdTools.Tests.ps1 | 5 ++++- Tests/NerdctlTools.Tests.ps1 | 5 +++++ Tests/UpdateEnvironmentPath.Tests.ps1 | 5 +++++ 7 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Tests/AllToolsUtilities.Tests.ps1 b/Tests/AllToolsUtilities.Tests.ps1 index 44f3451..e4a2fc4 100644 --- a/Tests/AllToolsUtilities.Tests.ps1 +++ b/Tests/AllToolsUtilities.Tests.ps1 @@ -6,6 +6,7 @@ # # ########################################################################### +using module ..\containers-toolkit\Private\Logger.psm1 Describe "AllToolsUtilities.psm1" { BeforeAll { @@ -17,6 +18,10 @@ Describe "AllToolsUtilities.psm1" { Import-Module -Name "$ModuleParentPath\Public\NerdctlTools.psm1" -Force Import-Module -Name "$ModuleParentPath\Public\ContainerNetworkTools.psm1" -Force Import-Module -Name "$ModuleParentPath\Public\AllToolsUtilities.psm1" -Force + + # Mock functions + Mock New-EventLog -ModuleName 'Logger' + Mock Write-EventLog -ModuleName 'Logger' } AfterAll { @@ -268,4 +273,4 @@ Describe "AllToolsUtilities.psm1" { $Error[0].Exception.Message | Should -Be 'Failed to initialize NAT network. Error message' } } -} \ No newline at end of file +} diff --git a/Tests/BuildkitTools.Tests.ps1 b/Tests/BuildkitTools.Tests.ps1 index 369d3bc..26a0854 100644 --- a/Tests/BuildkitTools.Tests.ps1 +++ b/Tests/BuildkitTools.Tests.ps1 @@ -7,6 +7,7 @@ ########################################################################### using module "..\containers-toolkit\Private\CommonToolUtilities.psm1" +using module ..\containers-toolkit\Private\Logger.psm1 Describe "BuildkitTools.psm1" { BeforeAll { @@ -28,6 +29,8 @@ Describe "BuildkitTools.psm1" { # Mock functions function Test-ServiceRegistered { } Mock Test-ServiceRegistered -ModuleName 'BuildkitTools' -MockWith { return $true } + Mock New-EventLog -ModuleName 'Logger' + Mock Write-EventLog -ModuleName 'Logger' } AfterEach { @@ -361,4 +364,4 @@ Describe "BuildkitTools.psm1" { Should -Invoke Remove-FeatureFromPath -Times 0 -Scope It -ModuleName "BuildkitTools" } } -} \ No newline at end of file +} diff --git a/Tests/CommonToolUtilities.Tests.ps1 b/Tests/CommonToolUtilities.Tests.ps1 index 972b016..bee4428 100644 --- a/Tests/CommonToolUtilities.Tests.ps1 +++ b/Tests/CommonToolUtilities.Tests.ps1 @@ -8,6 +8,7 @@ using module "..\containers-toolkit\Private\CommonToolUtilities.psm1" +using module ..\containers-toolkit\Private\Logger.psm1 $Script:SampleSha256Sum = @' 6b8ff12339733a6SSaMpLeSHAe2ff9f8d333c9e898 nerdctl-2.0.0-linux-amd64.tar.gz @@ -74,6 +75,10 @@ Describe "CommonToolUtilities.psm1" { $ProgramFiles = "TestDrive:\Program Files" New-Item -Path $ProgramFiles -ItemType Directory -Force | Out-Null + + # Mock functions + Mock New-EventLog -ModuleName 'Logger' + Mock Write-EventLog -ModuleName 'Logger' } AfterAll { @@ -838,4 +843,4 @@ Describe "CommonToolUtilities.psm1" { $Error[0].Exception.Message | Should -BeExactly "Failed to delete directory: 'TestDrive\Buildkit'. Error" } } -} \ No newline at end of file +} diff --git a/Tests/ContainerNetworkTools.Tests.ps1 b/Tests/ContainerNetworkTools.Tests.ps1 index df53d9e..fcacfeb 100644 --- a/Tests/ContainerNetworkTools.Tests.ps1 +++ b/Tests/ContainerNetworkTools.Tests.ps1 @@ -8,6 +8,7 @@ using module "..\containers-toolkit\Private\CommonToolUtilities.psm1" +using module ..\containers-toolkit\Private\Logger.psm1 Describe "ContainerNetworkTools.psm1" { BeforeAll { @@ -17,6 +18,10 @@ Describe "ContainerNetworkTools.psm1" { Import-Module -Name "$ModuleParentPath\Private\CommonToolUtilities.psm1" -Force Import-Module -Name "$ModuleParentPath\Public\ContainerNetworkTools.psm1" -Force Import-Module -Name "$RootPath\Tests\TestData\MockClasses.psm1" -Force + + # Mock functions + Mock New-EventLog -ModuleName 'Logger' + Mock Write-EventLog -ModuleName 'Logger' } AfterEach { @@ -295,4 +300,4 @@ Describe "ContainerNetworkTools.psm1" { $Error[0].Exception.Message | Should -Be 'Windows CNI plugin does not exist at TestDrive:\TestDir\cni or the directory is empty.' } } -} \ No newline at end of file +} diff --git a/Tests/ContainerdTools.Tests.ps1 b/Tests/ContainerdTools.Tests.ps1 index fd3893b..25e998f 100644 --- a/Tests/ContainerdTools.Tests.ps1 +++ b/Tests/ContainerdTools.Tests.ps1 @@ -6,6 +6,7 @@ # # ########################################################################### +using module ..\containers-toolkit\Private\Logger.psm1 Describe "ContainerdTools.psm1" { BeforeAll { @@ -28,6 +29,8 @@ Describe "ContainerdTools.psm1" { # Mock functions function Test-ServiceRegistered { } Mock Test-ServiceRegistered -ModuleName 'ContainerdTools' -MockWith { return $true } + Mock New-EventLog -ModuleName 'Logger' + Mock Write-EventLog -ModuleName 'Logger' } AfterEach { @@ -338,4 +341,4 @@ Describe "ContainerdTools.psm1" { Should -Invoke Remove-FeatureFromPath -Times 0 -Scope It -ModuleName "ContainerdTools" } } -} \ No newline at end of file +} diff --git a/Tests/NerdctlTools.Tests.ps1 b/Tests/NerdctlTools.Tests.ps1 index 75e3f52..f499368 100644 --- a/Tests/NerdctlTools.Tests.ps1 +++ b/Tests/NerdctlTools.Tests.ps1 @@ -8,6 +8,7 @@ using module "..\containers-toolkit\Private\CommonToolUtilities.psm1" +using module ..\containers-toolkit\Private\Logger.psm1 Describe "NerdctlTools.psm1" { BeforeAll { @@ -18,6 +19,10 @@ Describe "NerdctlTools.psm1" { Import-Module -Name "$ModuleParentPath\Public\ContainerdTools.psm1" Import-Module -Name "$ModuleParentPath\Public\ContainerNetworkTools.psm1" Import-Module -Name "$ModuleParentPath\Public\NerdctlTools.psm1" -Force + + # Mock functions + Mock New-EventLog -ModuleName 'Logger' + Mock Write-EventLog -ModuleName 'Logger' } AfterEach { diff --git a/Tests/UpdateEnvironmentPath.Tests.ps1 b/Tests/UpdateEnvironmentPath.Tests.ps1 index 03bba56..855d8c7 100644 --- a/Tests/UpdateEnvironmentPath.Tests.ps1 +++ b/Tests/UpdateEnvironmentPath.Tests.ps1 @@ -6,6 +6,7 @@ # # ########################################################################### +using module ..\containers-toolkit\Private\Logger.psm1 Describe "UpdateEnvironmentPath.psm1" { BeforeAll { @@ -16,6 +17,10 @@ Describe "UpdateEnvironmentPath.psm1" { # Original enviromnent values $Script:originalUserPathString = $ENV:Path $Script:originalSysPathString = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + + # Mock functions + Mock New-EventLog -ModuleName 'Logger' + Mock Write-EventLog -ModuleName 'Logger' } AfterAll {