Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Backward compatibility: Test-JSONChecksum #36

Merged
merged 1 commit into from
Aug 31, 2024
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ You can find documentation for these functions here: [Containers-Toolkit Documen

## Prerequisites

This module requires `ThreadJob` and `HNS` modules.
1. PowerShell: Minimum Version 7

1. `ThreadJob` module

Expand Down
20 changes: 6 additions & 14 deletions Tests/CommonToolUtilities.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -423,18 +423,10 @@ Describe "CommonToolUtilities.psm1" {
}

# Validate Checksum file content
Should -Invoke Get-Content -ModuleName "CommonToolUtilities" -ParameterFilter {
$Path -eq $Script:ChecksumFile
}
Should -Invoke Get-Content -ModuleName "CommonToolUtilities" -ParameterFilter { $Path -eq $Script:ChecksumFile }

# Validate JSON file
# Should -Invoke Get-Content -ModuleName "CommonToolUtilities" -ParameterFilter {
# $Path -eq "$Script:SchemaFile"
# } # FIXME: This test is failing
Should -Invoke Test-Json -Times 1 -Scope It -ModuleName "CommonToolUtilities" -ParameterFilter {
$Path -eq $Script:ChecksumFile -and
$SchemaFile -eq $Script:SchemaFile
}
Should -Invoke Test-Json -Times 1 -Scope It -ModuleName "CommonToolUtilities"

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

# Validate JSON file
Should -Invoke Get-Content -Times 1 -Scope It -ModuleName "CommonToolUtilities" -ParameterFilter {
$Path -eq $Script:SchemaFile
$Path -eq $Script:ChecksumFile
}
Should -Invoke Test-Json -Times 1 -Scope It -ModuleName "CommonToolUtilities" -ParameterFilter {
$Path -eq $Script:ChecksumFile -and
$SchemaFile -eq $Script:SchemaFile
Should -Invoke Get-Content -Times 1 -Scope It -ModuleName "CommonToolUtilities" -ParameterFilter {
$Path -eq $Script:SchemaFile
}
Should -Invoke Test-Json -Times 1 -Scope It -ModuleName "CommonToolUtilities"

# Assert success
Should -Invoke Get-FileHash -Times 1 -Scope It -ModuleName "CommonToolUtilities" -ParameterFilter {
Expand Down
9 changes: 6 additions & 3 deletions containers-toolkit/Private/CommonToolUtilities.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
###########################################################################
###########################################################################
# #
# Copyright (c) Microsoft Corporation. All rights reserved. #
# #
Expand Down Expand Up @@ -339,6 +339,7 @@ function DownloadCheckSumFile {
Throw "Checksum file download failed: $checksumUri.`n$($_.Exception.Message)"
}

Write-Debug "Checksum file downloaded to `"$OutFile`""
return $OutFile
}

Expand All @@ -350,6 +351,8 @@ function ValidateJSONChecksumFile {
[String]$SchemaFile
)

Write-Debug "Validating JSON checksum file...`n`tChecksum file path:$ChecksumFilePath`n`tSchema file: $SchemaFile"

# Check if the schema file exists
if (-not (Test-Path -Path $SchemaFile)) {
Throw "Couldn't find the provided schema file: $SchemaFile"
Expand All @@ -362,8 +365,8 @@ function ValidateJSONChecksumFile {

# Test JSON checksum file is valid
try {
Write-Debug "Validating checksum JSON file $checksumFilePath"
return (Test-Json -Path "$checksumFilePath" -SchemaFile $SchemaFile)
$isValidJSON = Test-Json -Json (Get-Content -Path $checksumFilePath -Raw) -Schema (Get-Content -Path $schemafile -Raw)
return $isValidJSON
}
catch {
Throw "Invalid JSON format in checksum file. $_"
Expand Down
Loading