Skip to content

Commit 3df3e2a

Browse files
committed
test updates, code clean up
1 parent 80c47ae commit 3df3e2a

File tree

4 files changed

+38
-36
lines changed

4 files changed

+38
-36
lines changed

src/code/InstallHelper.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -685,21 +685,10 @@ private ConcurrentDictionary<string, Hashtable> BeginPackageInstall(
685685
break;
686686
}
687687

688-
_cmdletPassedIn.WriteDebug($"BeginPackageInstall() - 679");
689688
// Convert parent package to PSResourceInfo
690689
PSResourceInfo pkgToInstall = null;
691690
foreach (PSResourceResult currentResult in currentResponseUtil.ConvertToPSResourceResult(responses))
692691
{
693-
if (currentResult == null)
694-
{
695-
_cmdletPassedIn.WriteDebug($"BeginPackageInstall() - currentResult is null");
696-
continue;
697-
}
698-
else
699-
{
700-
_cmdletPassedIn.WriteDebug($"BeginPackageInstall() - currentResult is not null");
701-
}
702-
703692
if (currentResult.exception != null && !currentResult.exception.Message.Equals(string.Empty))
704693
{
705694
errRecord = new ErrorRecord(
@@ -765,7 +754,7 @@ private ConcurrentDictionary<string, Hashtable> BeginPackageInstall(
765754
// TODO: can use cache for this
766755
if (!_reinstall)
767756
{
768-
string currPkgNameVersion = $"{pkgToInstall.Name}{pkgToInstall.Version}";
757+
string currPkgNameVersion = $"{pkgToInstall.Name}{pkgVersion}";
769758
// Use HashSet lookup instead of Contains for O(1) performance
770759
if (_packagesOnMachine.Contains(currPkgNameVersion))
771760
{
@@ -844,15 +833,15 @@ private ConcurrentDictionary<string, Hashtable> BeginPackageInstall(
844833
else {
845834
// If we don't install dependencies, we're only installing the parent pkg so we can short circut and simply install the parent pkg.
846835
// TODO: check this version and prerelease combo
847-
Stream responseStream = currentServer.InstallPackage(pkgToInstall.Name, pkgToInstall.Version.ToString(), true, out ErrorRecord installNameErrRecord);
836+
Stream responseStream = currentServer.InstallPackage(pkgToInstall.Name, pkgVersion, true, out ErrorRecord installNameErrRecord);
848837

849838
if (installNameErrRecord != null)
850839
{
851840
errRecord = installNameErrRecord;
852841
return packagesHash;
853842
}
854-
bool installedToTempPathSuccessfully = _asNupkg ? TrySaveNupkgToTempPath(responseStream, tempInstallPath, pkgToInstall.Name, pkgToInstall.Version.ToString(), pkgToInstall, packagesHash, out updatedPackagesHash, out errRecord) :
855-
TryInstallToTempPath(responseStream, tempInstallPath, pkgToInstall.Name, pkgToInstall.Version.ToString(), pkgToInstall, packagesHash, out updatedPackagesHash, out warning, out errRecord);
843+
bool installedToTempPathSuccessfully = _asNupkg ? TrySaveNupkgToTempPath(responseStream, tempInstallPath, pkgToInstall.Name, pkgVersion, pkgToInstall, packagesHash, out updatedPackagesHash, out errRecord) :
844+
TryInstallToTempPath(responseStream, tempInstallPath, pkgToInstall.Name, pkgVersion, pkgToInstall, packagesHash, out updatedPackagesHash, out warning, out errRecord);
856845
if (!installedToTempPathSuccessfully)
857846
{
858847
return packagesHash;

test/FindPSResourceTests/FindPSResourceV2Server.Tests.ps1

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,15 +344,6 @@ Describe 'Test HTTP Find-PSResource for V2 Server Protocol' -tags 'CI' {
344344
# $foundTestScript | Should -Be $True
345345
# }
346346

347-
It "find all resources with specified tag given Tag property, with and without Prerelease property" {
348-
$tagToFind = "MyPSTag"
349-
$res = Find-PSResource -Tag $tagToFind -Repository $PSGalleryName
350-
$res | Should -HaveCount 1
351-
352-
$res = Find-PSResource -Tag $tagToFind -Repository $PSGalleryName -Prerelease
353-
$res | Should -HaveCount 2
354-
}
355-
356347
It "find resource, but only show listed versions" {
357348
# testmodule99 version 1.0.0-beta1 is unlisted
358349
$res = Find-PSResource -Name "testmodule99" -Repository $PSGalleryName

test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Describe 'Test Install-PSResource for GitHub packages' -tags 'CI' {
1313
$testScriptName = "test_script"
1414
$GithubPackagesRepoName = "GithubPackagesRepo"
1515
$GithubPackagesRepoUri = "https://nuget.pkg.github.com/PowerShell/index.json"
16-
# Get-NewPSResourceRepositoryFile
17-
# Register-PSResourceRepository -Name $GithubPackagesRepoName -Uri $GithubPackagesRepoUri
16+
Get-NewPSResourceRepositoryFile
17+
Register-PSResourceRepository -Name $GithubPackagesRepoName -Uri $GithubPackagesRepoUri
1818

1919
$secureString = ConvertTo-SecureString $env:MAPPED_GITHUB_PAT -AsPlainText -Force
2020
$credential = New-Object pscredential ($env:GITHUB_USERNAME, $secureString)
@@ -44,25 +44,22 @@ Describe 'Test Install-PSResource for GitHub packages' -tags 'CI' {
4444
}
4545

4646
It "Install specific module resource by name" {
47-
$DebugPreference = 'Continue'
48-
Install-PSResource -Name $testModuleName -Repository $GithubPackagesRepoName -Credential $credential -TrustRepository -Verbose -Debug
47+
Install-PSResource -Name $testModuleName -Repository $GithubPackagesRepoName -Credential $credential -TrustRepository
4948
$pkg = Get-InstalledPSResource $testModuleName
5049
$pkg.Name | Should -Be $testModuleName
5150
$pkg.Version | Should -Be "5.0.0"
5251
}
5352

5453
It "Install specific script resource by name" {
55-
#$DebugPreference = 'Continue'
56-
Install-PSResource -Name $testScriptName -Repository $GithubPackagesRepoName -Credential $credential -TrustRepository #-Verbose -Debug
54+
Install-PSResource -Name $testScriptName -Repository $GithubPackagesRepoName -Credential $credential -TrustRepository
5755
$pkg = Get-InstalledPSResource $testScriptName
5856
$pkg.Name | Should -Be $testScriptName
5957
$pkg.Version | Should -Be "3.5.0"
6058
}
6159

6260
It "Install multiple resources by name" {
63-
#$DebugPreference = 'Continue'
6461
$pkgNames = @($testModuleName, $testModuleName2)
65-
Install-PSResource -Name $pkgNames -Repository $GithubPackagesRepoName -Credential $credential -TrustRepository #-debug -verbose
62+
Install-PSResource -Name $pkgNames -Repository $GithubPackagesRepoName -Credential $credential -TrustRepository
6663
$pkg = Get-InstalledPSResource $pkgNames
6764
$pkg.Name | Should -Be $pkgNames
6865
}
@@ -91,16 +88,14 @@ Describe 'Test Install-PSResource for GitHub packages' -tags 'CI' {
9188
}
9289

9390
It "Should install resource given name and exact range inclusive [1.0.0, 5.0.0]" {
94-
#$DebugPreference = 'Continue'
95-
Install-PSResource -Name $testModuleName -Version "[1.0.0, 5.0.0]" -Repository $GithubPackagesRepoName -Credential $credential -TrustRepository #-Debug -Verbose
91+
Install-PSResource -Name $testModuleName -Version "[1.0.0, 5.0.0]" -Repository $GithubPackagesRepoName -Credential $credential -TrustRepository
9692
$pkg = Get-InstalledPSResource $testModuleName
9793
$pkg.Name | Should -Be $testModuleName
9894
$pkg.Version | Should -Be "5.0.0"
9995
}
10096

10197
It "Should install resource given name and exact range exclusive (1.0.0, 5.0.0)" {
102-
#$DebugPreference = 'Continue'
103-
Install-PSResource -Name $testModuleName -Version "(1.0.0, 5.0.0)" -Repository $GithubPackagesRepoName -Credential $credential -TrustRepository #-Verbose -Debug
98+
Install-PSResource -Name $testModuleName -Version "(1.0.0, 5.0.0)" -Repository $GithubPackagesRepoName -Credential $credential -TrustRepository
10499
$pkg = Get-InstalledPSResource $testModuleName
105100
$pkg.Name | Should -Be $testModuleName
106101
$pkg.Version | Should -Be "3.0.0"

test/ReleaseTests.ps1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,30 @@ Describe 'Test HTTP Find-PSResource for V2 Server Protocol' -tags 'Release' {
134134
}
135135
}
136136
}
137+
138+
139+
Describe 'Test HTTP Find-PSResource for V2 Server Protocol' -tags 'CI' {
140+
141+
BeforeAll{
142+
$PSGalleryName = Get-PSGalleryName
143+
$testModuleName = "test_module"
144+
$testScriptName = "test_script"
145+
$commandName = "Get-TargetResource"
146+
$dscResourceName = "SystemLocale"
147+
$parentModuleName = "SystemLocaleDsc"
148+
Get-NewPSResourceRepositoryFile
149+
}
150+
151+
AfterAll {
152+
Get-RevertPSResourceRepositoryFile
153+
}
154+
155+
It "find all resources with specified tag given Tag property, with and without Prerelease property" {
156+
$tagToFind = "MyPSTag"
157+
$res = Find-PSResource -Tag $tagToFind -Repository $PSGalleryName
158+
$res | Should -HaveCount 1
159+
160+
$res = Find-PSResource -Tag $tagToFind -Repository $PSGalleryName -Prerelease
161+
$res | Should -HaveCount 2
162+
}
163+
}

0 commit comments

Comments
 (0)