@@ -535,7 +535,7 @@ Describe "CommonToolUtilities.psm1" {
535535 }
536536
537537 It " should skip JSON validation when Test-Json is not available" {
538- Mock Get-Command - ModuleName " CommonToolUtilities" - MockWith { return $null }- ParameterFilter {
538+ Mock Get-Command - ModuleName " CommonToolUtilities" - MockWith { return $null } - ParameterFilter {
539539 $Name -eq ' Test-Json'
540540 }
541541
@@ -585,7 +585,7 @@ Describe "CommonToolUtilities.psm1" {
585585 { & $Script :FunctionToCall } | Should - Throw " Invalid schema file: $Script :SchemaFile . Schema file is empty."
586586 }
587587
588- It " should throw an error if the JSON file is not valid " {
588+ It " should throw an error if Test-Json fails " {
589589 Mock Get-Content - ModuleName " CommonToolUtilities" - MockWith { return " Test data" }
590590
591591 # Test-Json returns true if the JSON is valid, otherwise it throws an error
@@ -595,6 +595,16 @@ Describe "CommonToolUtilities.psm1" {
595595 { & $Script :FunctionToCall } | Should - Throw " Error validating JSON checksum file. Error"
596596 }
597597
598+ It " should throw an error if the JSON file is not valid" {
599+ Mock Get-Content - ModuleName " CommonToolUtilities" - MockWith { return " Test data" }
600+
601+ # Test-Json returns true if the JSON is valid, otherwise it throws an error
602+ Mock Test-Json - ModuleName " CommonToolUtilities" - MockWith { return $false }
603+
604+ # Test the function
605+ { & $Script :FunctionToCall } | Should - Throw " Checksum file validation failed for $Script :ChecksumFile . Please check the file format and schema."
606+ }
607+
598608 It " should throw an error if script block throws an error" {
599609 # ParentContainsErrorRecordException: Exception calling "Invoke" with "1" argument(s): "Error message"
600610 { Test-CheckSum - DownloadedFile $Script :DownloadedFile - ChecksumFile $Script :ChecksumFile - JSON - SchemaFile $Script :SchemaFile - ExtractDigestScriptBlock { (Throw " Error message" ) } | `
0 commit comments