From f1bb031e436bbb5c5645ddc366ca0856ddbf0131 Mon Sep 17 00:00:00 2001 From: Aleksandr Chebotov <47745270+al-cheb@users.noreply.github.com> Date: Fri, 5 Aug 2022 20:50:37 +0200 Subject: [PATCH] [Windows] Disable mongodb service by default (#6023) * Disable mongodb service by default * Add ErrorAction Ignore --- .../scripts/Installers/Install-MongoDB.ps1 | 10 +++++- images/win/scripts/Tests/Databases.Tests.ps1 | 31 +++++++++++++++---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/images/win/scripts/Installers/Install-MongoDB.ps1 b/images/win/scripts/Installers/Install-MongoDB.ps1 index 2265b40aa..674207ed7 100644 --- a/images/win/scripts/Installers/Install-MongoDB.ps1 +++ b/images/win/scripts/Installers/Install-MongoDB.ps1 @@ -3,11 +3,19 @@ ## Desc: Install MongoDB #################################################################################### +# Install mongodb package $toolsetVersion = (Get-ToolsetContent).mongodb.version $latestChocoPackage = Get-LatestChocoPackageVersion -TargetVersion $toolsetVersion -PackageName "mongodb" Choco-Install -PackageName mongodb -ArgumentList "--version=$latestChocoPackage" -$mongoPath = (Get-CimInstance Win32_Service -Filter "Name LIKE 'mongodb'").PathName + +# Add mongodb to the PATH +$mongodbService = "mongodb" +$mongoPath = (Get-CimInstance Win32_Service -Filter "Name LIKE '$mongodbService'").PathName $mongoBin = Split-Path -Path $mongoPath.split('"')[1] Add-MachinePathItem "$mongoBin" +# Stop and disable mongodb service +Stop-Service -Name $mongodbService +Set-Service $mongodbService -StartupType Disabled + Invoke-PesterTests -TestFile "Databases" -TestName "MongoDB" \ No newline at end of file diff --git a/images/win/scripts/Tests/Databases.Tests.ps1 b/images/win/scripts/Tests/Databases.Tests.ps1 index 1e0c88a34..66e121057 100644 --- a/images/win/scripts/Tests/Databases.Tests.ps1 +++ b/images/win/scripts/Tests/Databases.Tests.ps1 @@ -1,10 +1,29 @@ Describe "MongoDB" { - It "" -TestCases @( - @{ ToolName = "mongo" } - @{ ToolName = "mongod" } - ) { - $toolsetVersion = (Get-ToolsetContent).mongodb.version - (&$ToolName --version)[2].Split('"')[-2] | Should -BeLike "$toolsetVersion*" + Context "Version" { + It "" -TestCases @( + @{ ToolName = "mongo" } + @{ ToolName = "mongod" } + ) { + $toolsetVersion = (Get-ToolsetContent).mongodb.version + (&$ToolName --version)[2].Split('"')[-2] | Should -BeLike "$toolsetVersion*" + } + } + + Context "Service" { + $mongoService = Get-Service -Name mongodb -ErrorAction Ignore + $mongoServiceTests = @{ + Name = $mongoService.Name + Status = $mongoService.Status + StartType = $mongoService.StartType + } + + It " service is stopped" -TestCases $mongoServiceTests { + $Status | Should -Be "Stopped" + } + + It " service is disabled" -TestCases $mongoServiceTests { + $StartType | Should -Be "Disabled" + } } }