Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Tests/Private/Get-PackageBinaryData.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Requires -Modules chocolatey-diff

Describe "Get-PackageBinaryData tests" {
}
44 changes: 44 additions & 0 deletions chocolatey-diff/Private/Get-PackageBinaryData.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function Get-PackageBinaryData {
<#
.SYNOPSIS
The meta information about binaries included in package
.DESCRIPTION
The meta information about binaries included in the package, including
the relative path, the checksum of the file, the embedded file and product
version as well as the embedded company name.
.OUTPUTS
An array of hashtables with the basic information about each binary file.
.EXAMPLE
PS > Get-PackageBinaryData -packageDirectory path\to\package\dir
#>
param (
[Parameter(Mandatory = $true)]
[string]$packageDirectory,
[ValidateSet('sha1', 'sha256', 'sha512')]
[string]$hashAlgorithm = 'sha256'
)

Push-Location $packageDirectory | Out-Null

try {
Write-Verbose "Finding binary files in '$packageDirectory..."
$binaryFiles = Get-ChildItem -Path $packageDirectory -Recurse -File | ? { Test-IsBinary -Path $_.FullName }

foreach ($file in $binaryFiles) {
Write-Verbose "Aquiring binary data from $($file.Name)..."

$item = Get-Item $file.FullName
$result = @{
path = Resolve-Path $file.FullName -Relative
checksum = Get-FileHash $file.FullName -Algorithm $hashAlgorithm | % Hash
fileVersion = $item.VersionInfo.FileVersion
productVersion = $item.VersionInfo.ProductVersion
CompanyName = $item.VersionInfo.CompanyName
}
$result
}
} finally {

Pop-Location | Out-Null
}
}
57 changes: 35 additions & 22 deletions chocolatey-diff/Public/Get-ChocolateyPackageDiff.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,29 @@
Get-ChocolateyPackageDiff -packageName chocolatey -oldPackageVersion 0.10.14 -newPackageVersion 0.10.15

#>
[cmdletbinding(DefaultParameterSetName='Default')]
[cmdletbinding(DefaultParameterSetName = 'Default')]
param(
[parameter(Mandatory = $true, Position = 0, ParameterSetName='Default')]
[parameter(Mandatory = $true, Position = 0, ParameterSetName='DiffTool')]
[string] $packageName,
[parameter(Mandatory = $false, Position = 1, ParameterSetName='Default')]
[parameter(Mandatory = $false, Position = 1, ParameterSetName='DiffTool')]
[string] $oldPackageVersion,
[parameter(Mandatory = $false, Position = 2, ParameterSetName='Default')]
[parameter(Mandatory = $false, Position = 2, ParameterSetName='DiffTool')]
[string] $newPackageVersion,
[parameter(Mandatory = $false, ParameterSetName='Default')]
[parameter(Mandatory = $false, ParameterSetName='DiffTool')]
[string] $downloadLocation = $(Get-TempPath),
[parameter(Mandatory = $false, ParameterSetName='Default')]
[parameter(Mandatory = $false, ParameterSetName='DiffTool')]
[switch] $keepFiles = $false,
[parameter(Mandatory = $false, ParameterSetName='Default')]
[switch] $ignoreExpectedChanges = $false,
[parameter(Mandatory = $false, ParameterSetName='DiffTool')]
[switch] $compareFolder = $false,
[parameter(Mandatory = $false, ParameterSetName='DiffTool')]
[switch] $useDiffTool = $false
[parameter(Mandatory = $true, Position = 0, ParameterSetName = 'Default')]
[parameter(Mandatory = $true, Position = 0, ParameterSetName = 'DiffTool')]
[string] $packageName,
[parameter(Mandatory = $false, Position = 1, ParameterSetName = 'Default')]
[parameter(Mandatory = $false, Position = 1, ParameterSetName = 'DiffTool')]
[string] $oldPackageVersion,
[parameter(Mandatory = $false, Position = 2, ParameterSetName = 'Default')]
[parameter(Mandatory = $false, Position = 2, ParameterSetName = 'DiffTool')]
[string] $newPackageVersion,
[parameter(Mandatory = $false, ParameterSetName = 'Default')]
[parameter(Mandatory = $false, ParameterSetName = 'DiffTool')]
[string] $downloadLocation = $(Get-TempPath),
[parameter(Mandatory = $false, ParameterSetName = 'Default')]
[parameter(Mandatory = $false, ParameterSetName = 'DiffTool')]
[switch] $keepFiles = $false,
[parameter(Mandatory = $false, ParameterSetName = 'Default')]
[switch] $ignoreExpectedChanges = $false,
[parameter(Mandatory = $false, ParameterSetName = 'DiffTool')]
[switch] $compareFolder = $false,
[parameter(Mandatory = $false, ParameterSetName = 'DiffTool')]
[switch] $useDiffTool = $false
)
$currentProgressPreference = $ProgressPreference
$ProgressPreference = 'SilentlyContinue'
Expand Down Expand Up @@ -107,6 +107,19 @@
Expand-Archive -Path $oldFileName -DestinationPath $oldExtractPath -Force
Expand-Archive -Path $newFileName -DestinationPath $newExtractPath -Force

foreach ($path in @($oldExtractPath; $newExtractPath)) {
# Temporary workaround until mocking and unit tests
# are figured out.
if (!(Test-Path $path)) { continue; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this there? What is the use of this?
I think you'll need to create Mocks to get around this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember right now, I have had this code in a stash for quite some time.
I remember that the unit tests were failing until I added this statement, but the unit tests have been updated since the initial stash creation so it may not be needed any longer.

The comment was also more a reminder to myself to figure out why the unit test was failing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Pester tests mock the folder and should not actually go out on the internet to download an actual package. I guess it's due to that.

You'll do need to make actual Pester tests.


$metaDestination = Join-Path $path "binary-data.txt"
if (Test-Path $metaDestination) {
Remove-Item $metaDestination
}

Get-PackageBinaryData -packageDirectory $path | Out-File -Encoding utf8 -FilePath $metaDestination
}

if ($compareFolder) {
# We need to remove files that should not be compared
$fullIgnoreList = $ignoreList | ForEach-Object { Join-Path $oldExtractPath $_ }
Expand Down