Functions/Get-JsonStringMaximumDepth.Tests.ps1
describe "BitTitan.Runbooks.Common/Get-JsonStringMaximumDepth" -Tags "module", "unit" { # Import the function to test . "$($PSScriptRoot)\Get-JsonStringMaximumDepth.ps1" it -TestCases @( @{ JsonString = '{ "layer1": { "layer2": { "layer3": { "layer4": "deepestLayer" } } } }' Depth = 4 }, @{ JsonString = '{ "layer1": [ {"layer2": { "layer3": { "layer4": "notDeepestLayer" } }} ], "layer01": { "layer02": [ {"layer04": { "layer05": [ {"layer 07": "deepestLayer"} ] }} ] } }' Depth = 7 } ) "returns the correct maximum JSON depth of <depth>" { param ($JsonString, $Depth) # Call the function $output = Get-JsonStringMaximumDepth $JsonString # Verify the output $output | Should Be $Depth } it "outputs an error and returns null when the JSON string is invalid" { # Call the function $output = Get-JsonStringMaximumDepth "[[" -ErrorAction SilentlyContinue -ErrorVariable errorVariable # Verify the output $errorVariable | Should Not BeNullOrEmpty $output | Should Be $null } } |