Skip to content

Commit 610bb08

Browse files
author
Justin Chung
committed
PassThru with FileIno instead of string
1 parent fe9c4d6 commit 610bb08

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

src/code/CompressPSResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using Microsoft.PowerShell.PSResourceGet.UtilClasses;
55
using System.IO;
6-
using System.Linq;
76
using System.Management.Automation;
87

98
namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
@@ -15,6 +14,7 @@ namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
1514
"PSResource",
1615
SupportsShouldProcess = true)]
1716
[Alias("cmres")]
17+
[OutputType(typeof(FileInfo))]
1818
public sealed class CompressPSResource : PSCmdlet
1919
{
2020
#region Parameters

src/code/PublishHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,10 @@ private bool PackNupkg(string outputDir, string outputNupkgDir, string nuspecFil
566566
{
567567
if (PassThru)
568568
{
569-
_cmdletPassedIn.WriteObject(System.IO.Path.Combine(outputNupkgDir, _pkgName + "." + _pkgVersion.ToNormalizedString() + ".nupkg"));
569+
var nupkgPath = System.IO.Path.Combine(outputNupkgDir, _pkgName + "." + _pkgVersion.ToNormalizedString() + ".nupkg");
570+
_cmdletPassedIn.WriteObject(new FileInfo(nupkgPath));
570571
}
572+
571573
_cmdletPassedIn.WriteVerbose("Successfully packed the resource into a .nupkg");
572574
}
573575
else

test/PublishPSResourceTests/CompressPSResource.Tests.ps1

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,44 @@ Describe "Test Compress-PSResource" -tags 'CI' {
4646
BeforeAll {
4747
Get-NewPSResourceRepositoryFile
4848

49+
$testDir = (get-item $psscriptroot).parent.FullName
50+
51+
function CreateTestModule
52+
{
53+
param (
54+
[string] $Path = "$TestDrive",
55+
[string] $ModuleName = 'TestModule'
56+
)
57+
58+
$modulePath = Join-Path -Path $Path -ChildPath $ModuleName
59+
$moduleMan = Join-Path $modulePath -ChildPath ($ModuleName + '.psd1')
60+
$moduleSrc = Join-Path $modulePath -ChildPath ($ModuleName + '.psm1')
61+
62+
if ( Test-Path -Path $modulePath) {
63+
Remove-Item -Path $modulePath -Recurse -Force
64+
}
65+
66+
$null = New-Item -Path $modulePath -ItemType Directory -Force
67+
68+
@'
69+
@{{
70+
RootModule = "{0}.psm1"
71+
ModuleVersion = '1.0.0'
72+
Author = 'None'
73+
Description = 'None'
74+
GUID = '0c2829fc-b165-4d72-9038-ae3a71a755c1'
75+
FunctionsToExport = @('Test1')
76+
RequiredModules = @('NonExistentModule')
77+
}}
78+
'@ -f $ModuleName | Out-File -FilePath $moduleMan
79+
80+
@'
81+
function Test1 {
82+
Write-Output 'Hello from Test1'
83+
}
84+
'@ | Out-File -FilePath $moduleSrc
85+
}
86+
4987
# Register temporary repositories
5088
$tmpRepoPath = Join-Path -Path $TestDrive -ChildPath "tmpRepoPath"
5189
New-Item $tmpRepoPath -Itemtype directory -Force
@@ -154,14 +192,17 @@ Describe "Test Compress-PSResource" -tags 'CI' {
154192
Test-Path -Path (Join-Path -Path $unzippedPath -ChildPath $testFile) | Should -Be $True
155193
}
156194

157-
It "Compress-PSResource -PassThru returns the path to the nupkg" {
195+
It "Compress-PSResource -PassThru returns a FileInfo object with the correct path" {
158196
$version = "1.0.0"
159197
New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module"
160198

161-
$nupkgPath = Compress-PSResource -Path $script:PublishModuleBase -DestinationPath $script:repositoryPath -PassThru
199+
$fileInfoObject = Compress-PSResource -Path $script:PublishModuleBase -DestinationPath $script:repositoryPath -PassThru
162200

163201
$expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$script:PublishModuleName.$version.nupkg"
164-
$nupkgPath | Should -Be $expectedPath
202+
$fileInfoObject | Should -BeOfType 'System.IO.FileSystemInfo'
203+
$fileInfoObject.FullName | Should -Be $expectedPath
204+
$fileInfoObject.Extension | Should -Be '.nupkg'
205+
$fileInfoObject.Name | Should -Be "$script:PublishModuleName.$version.nupkg"
165206
}
166207

167208
<# Test for Signing the nupkg. Signing doesn't work

0 commit comments

Comments
 (0)