From c8b5332d58a1b45370bb36883001081aa3ea2f8e Mon Sep 17 00:00:00 2001 From: Paul Higinbotham Date: Wed, 8 Dec 2021 15:58:16 -0800 Subject: [PATCH] Suppress progress bar during testing --- src/code/InstallHelper.cs | 15 +++++---------- test/GetInstalledPSResource.Tests.ps1 | 1 + test/InstallPSResource.Tests.ps1 | 4 +--- test/SavePSResource.Tests.ps1 | 9 +++++---- test/UninstallPSResource.Tests.ps1 | 9 ++++++--- test/UpdatePSResource.Tests.ps1 | 3 ++- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/code/InstallHelper.cs b/src/code/InstallHelper.cs index 300c5b6c9..64c42dddd 100644 --- a/src/code/InstallHelper.cs +++ b/src/code/InstallHelper.cs @@ -332,16 +332,11 @@ private List InstallPackage( if (!_quiet) { int activityId = 0; - string activity = ""; - string statusDescription = ""; - - // Installing parent package (one whose name was passed in to install) - activityId = 0; - activity = string.Format("Installing {0}...", pkg.Name); - statusDescription = string.Format("{0}% Complete:", Math.Round(((double)totalInstalledPkgCount / totalPkgs) * 100), 2); - - var progressRecord = new ProgressRecord(activityId, activity, statusDescription); - _cmdletPassedIn.WriteProgress(progressRecord); + int percentComplete = ((totalInstalledPkgCount * 100) / totalPkgs); + string activity = string.Format("Installing {0}...", pkg.Name); + string statusDescription = string.Format("{0}% Complete", percentComplete); + _cmdletPassedIn.WriteProgress( + new ProgressRecord(activityId, activity, statusDescription)); } // Create PackageIdentity in order to download diff --git a/test/GetInstalledPSResource.Tests.ps1 b/test/GetInstalledPSResource.Tests.ps1 index b7901be78..63d44e241 100644 --- a/test/GetInstalledPSResource.Tests.ps1 +++ b/test/GetInstalledPSResource.Tests.ps1 @@ -1,6 +1,7 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +$ProgressPreference = "SilentlyContinue" Import-Module "$psscriptroot\PSGetTestUtils.psm1" -Force Describe 'Test Get-PSResource for Module' { diff --git a/test/InstallPSResource.Tests.ps1 b/test/InstallPSResource.Tests.ps1 index b87fd9868..b5cf93604 100644 --- a/test/InstallPSResource.Tests.ps1 +++ b/test/InstallPSResource.Tests.ps1 @@ -1,13 +1,12 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +$ProgressPreference = "SilentlyContinue" Import-Module "$psscriptroot\PSGetTestUtils.psm1" -Force Describe 'Test Install-PSResource for Module' { BeforeAll { - $OldProgressPreference = $ProgressPreference - $ProgressPreference = "SilentlyContinue" $TestGalleryName = Get-PoshTestGalleryName $PSGalleryName = Get-PSGalleryName $NuGetGalleryName = Get-NuGetGalleryName @@ -23,7 +22,6 @@ Describe 'Test Install-PSResource for Module' { } AfterAll { - $ProgressPreference = $OldProgressPreference Get-RevertPSResourceRepositoryFile } diff --git a/test/SavePSResource.Tests.ps1 b/test/SavePSResource.Tests.ps1 index 66858ce6d..8a0c4711d 100644 --- a/test/SavePSResource.Tests.ps1 +++ b/test/SavePSResource.Tests.ps1 @@ -1,11 +1,12 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +$ProgressPreference = "SilentlyContinue" Import-Module "$psscriptroot\PSGetTestUtils.psm1" -Force Describe 'Test Save-PSResource for PSResources' { - BeforeAll{ + BeforeAll { $TestGalleryName = Get-PoshTestGalleryName $PSGalleryName = Get-PSGalleryName $NuGetGalleryName = Get-NuGetGalleryName @@ -52,7 +53,7 @@ Describe 'Test Save-PSResource for PSResources' { } It "Should not save resource given nonexistant name" { - Save-PSResource -Name NonExistentModule -Repository $TestGalleryName -Path $SaveDir + Save-PSResource -Name NonExistentModule -Repository $TestGalleryName -Path $SaveDir -ErrorAction SilentlyContinue $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq "NonExistentModule" $pkgDir.Name | Should -BeNullOrEmpty } @@ -102,13 +103,13 @@ Describe 'Test Save-PSResource for PSResources' { ) { param($Version, $Description) - Save-PSResource -Name $testModuleName2 -Version $Version -Repository $TestGalleryName -Path $SaveDir + Save-PSResource -Name $testModuleName2 -Version $Version -Repository $TestGalleryName -Path $SaveDir -ErrorAction SilentlyContinue $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 $pkgDir | Should -BeNullOrEmpty } It "Save resource when given Name, Version '*', should install the latest version" { - Save-PSResource -Name $testModuleName2 -Version "*" -Repository $TestGalleryName -Path $SaveDir + Save-PSResource -Name $testModuleName2 -Version "*" -Repository $TestGalleryName -Path $SaveDir -ErrorAction SilentlyContinue $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 $pkgDir | Should -Not -BeNullOrEmpty $pkgDirVersion = Get-ChildItem -Path $pkgDir.FullName diff --git a/test/UninstallPSResource.Tests.ps1 b/test/UninstallPSResource.Tests.ps1 index 3c4bcdc66..996a9b77c 100644 --- a/test/UninstallPSResource.Tests.ps1 +++ b/test/UninstallPSResource.Tests.ps1 @@ -1,6 +1,7 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +$ProgressPreference = "SilentlyContinue" Import-Module "$psscriptroot\PSGetTestUtils.psm1" -Force Describe 'Test Uninstall-PSResource for Modules' { @@ -13,9 +14,11 @@ Describe 'Test Uninstall-PSResource for Modules' { Get-NewPSResourceRepositoryFile Uninstall-PSResource -name ContosoServer -Version "*" } - BeforeEach{ + + BeforeEach { $null = Install-PSResource ContosoServer -Repository $TestGalleryName -TrustRepository -WarningAction SilentlyContinue } + AfterAll { Get-RevertPSResourceRepositoryFile } @@ -36,14 +39,14 @@ Describe 'Test Uninstall-PSResource for Modules' { } It "Uninstall a list of modules by name" { - $null = Install-PSResource BaseTestPackage -Repository $TestGalleryName -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource BaseTestPackage -Repository $TestGalleryName -TrustRepository -WarningAction SilentlyContinue -SkipDependencyCheck Uninstall-PSResource -Name BaseTestPackage, ContosoServer Get-Module ContosoServer, BaseTestPackage -ListAvailable | Should -be $null } It "Uninstall a specific script by name" { - $null = Install-PSResource Test-RPC -Repository $TestGalleryName -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource Test-RPC -Repository $TestGalleryName -TrustRepository -WarningAction SilentlyContinue -SkipDependencyCheck Uninstall-PSResource -name Test-RPC } diff --git a/test/UpdatePSResource.Tests.ps1 b/test/UpdatePSResource.Tests.ps1 index c2449a276..cb11a8b59 100644 --- a/test/UpdatePSResource.Tests.ps1 +++ b/test/UpdatePSResource.Tests.ps1 @@ -1,12 +1,13 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +$ProgressPreference = "SilentlyContinue" Import-Module "$psscriptroot\PSGetTestUtils.psm1" -Force Describe 'Test Update-PSResource' { - BeforeAll{ + BeforeAll { $TestGalleryName = Get-PoshTestGalleryName $NuGetGalleryName = Get-NuGetGalleryName $testModuleName = "TestModule"