Skip to content

Commit c55a494

Browse files
committed
[Bug] Backward compatibility: Test-JSONChecksum
- To ensure backward compatibility, we use the older Test-JSON -JSON syntax instead of the Test-JSON -Path command, which was introduced in later versions of PowerShell 7.
1 parent aeaf32e commit c55a494

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ You can find documentation for these functions here: [Containers-Toolkit Documen
3030

3131
## Prerequisites
3232

33-
This module requires `ThreadJob` and `HNS` modules.
33+
1. PowerShell Version 7
3434

3535
1. `ThreadJob` module
3636

Tests/CommonToolUtilities.Tests.ps1

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -423,18 +423,10 @@ Describe "CommonToolUtilities.psm1" {
423423
}
424424

425425
# Validate Checksum file content
426-
Should -Invoke Get-Content -ModuleName "CommonToolUtilities" -ParameterFilter {
427-
$Path -eq $Script:ChecksumFile
428-
}
426+
Should -Invoke Get-Content -ModuleName "CommonToolUtilities" -ParameterFilter { $Path -eq $Script:ChecksumFile }
429427

430428
# Validate JSON file
431-
# Should -Invoke Get-Content -ModuleName "CommonToolUtilities" -ParameterFilter {
432-
# $Path -eq "$Script:SchemaFile"
433-
# } # FIXME: This test is failing
434-
Should -Invoke Test-Json -Times 1 -Scope It -ModuleName "CommonToolUtilities" -ParameterFilter {
435-
$Path -eq $Script:ChecksumFile -and
436-
$SchemaFile -eq $Script:SchemaFile
437-
}
429+
Should -Invoke Test-Json -Times 1 -Scope It -ModuleName "CommonToolUtilities"
438430

439431
# Assert success
440432
Should -Invoke Get-FileHash -Times 1 -Scope It -ModuleName "CommonToolUtilities" -ParameterFilter {
@@ -467,12 +459,12 @@ Describe "CommonToolUtilities.psm1" {
467459

468460
# Validate JSON file
469461
Should -Invoke Get-Content -Times 1 -Scope It -ModuleName "CommonToolUtilities" -ParameterFilter {
470-
$Path -eq $Script:SchemaFile
462+
$Path -eq $Script:ChecksumFile
471463
}
472-
Should -Invoke Test-Json -Times 1 -Scope It -ModuleName "CommonToolUtilities" -ParameterFilter {
473-
$Path -eq $Script:ChecksumFile -and
474-
$SchemaFile -eq $Script:SchemaFile
464+
Should -Invoke Get-Content -Times 1 -Scope It -ModuleName "CommonToolUtilities" -ParameterFilter {
465+
$Path -eq $Script:SchemaFile
475466
}
467+
Should -Invoke Test-Json -Times 1 -Scope It -ModuleName "CommonToolUtilities"
476468

477469
# Assert success
478470
Should -Invoke Get-FileHash -Times 1 -Scope It -ModuleName "CommonToolUtilities" -ParameterFilter {

containers-toolkit/Private/CommonToolUtilities.psm1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
###########################################################################
1+
###########################################################################
22
# #
33
# Copyright (c) Microsoft Corporation. All rights reserved. #
44
# #
@@ -339,6 +339,7 @@ function DownloadCheckSumFile {
339339
Throw "Checksum file download failed: $checksumUri.`n$($_.Exception.Message)"
340340
}
341341

342+
Write-Debug "Checksum file downloaded to `"$OutFile`""
342343
return $OutFile
343344
}
344345

@@ -350,6 +351,8 @@ function ValidateJSONChecksumFile {
350351
[String]$SchemaFile
351352
)
352353

354+
Write-Debug "Validating JSON checksum file...`n`t Checksum file path:$ChecksumFilePath`n`tSchema file: $SchemaFile"
355+
353356
# Check if the schema file exists
354357
if (-not (Test-Path -Path $SchemaFile)) {
355358
Throw "Couldn't find the provided schema file: $SchemaFile"
@@ -363,7 +366,8 @@ function ValidateJSONChecksumFile {
363366
# Test JSON checksum file is valid
364367
try {
365368
Write-Debug "Validating checksum JSON file $checksumFilePath"
366-
return (Test-Json -Path "$checksumFilePath" -SchemaFile $SchemaFile)
369+
$isValidJSON = Test-Json -Json (Get-Content -Path $checksumFilePath -Raw) -Schema (Get-Content -Path $schemafile -Raw)
370+
return $isValidJSON
367371
}
368372
catch {
369373
Throw "Invalid JSON format in checksum file. $_"

0 commit comments

Comments
 (0)