From 1e32ff255e7b8a040e05ad4de191eb6014316cc5 Mon Sep 17 00:00:00 2001 From: Matt Thalman Date: Fri, 28 Jun 2024 19:22:07 -0500 Subject: [PATCH] Update tests --- container/tests/check-image.tests.ps1 | 45 +++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/container/tests/check-image.tests.ps1 b/container/tests/check-image.tests.ps1 index 9bd38f5..785503e 100644 --- a/container/tests/check-image.tests.ps1 +++ b/container/tests/check-image.tests.ps1 @@ -22,7 +22,24 @@ Describe 'Get result' { $result | ConvertTo-Json } -ParameterFilter { $Command -eq "dredge image compare layers --output json $baseImage $targetImage --os linux --arch $architecture" } ` -ModuleName common - & $targetScript -TargetImage $targetImage -BaseImage $baseImage -Architecture $architecture | Should -Be "false" + + Mock Invoke-Expression { + "base-digest" + } -ParameterFilter { $Command -eq "dredge manifest resolve $baseImage --os linux --arch $architecture" } ` + -ModuleName common + + Mock Invoke-Expression { + "target-digest" + } -ParameterFilter { $Command -eq "dredge manifest resolve $targetImage --os linux --arch $architecture" } ` + -ModuleName common + $result = & $targetScript -TargetImage $targetImage -BaseImage $baseImage -Architecture $architecture + + $expected = @{ + sendDispatch = "false" + updates = @() + } | ConvertTo-Json + + $result | Should -Be $expected } It 'Given a target image that is not up-to-date with the base image, it returns true' { @@ -35,8 +52,32 @@ Describe 'Get result' { $result | ConvertTo-Json } -ParameterFilter { $Command -eq "dredge image compare layers --output json $baseImage $targetImage --os linux --arch $architecture" } ` -ModuleName common + + Mock Invoke-Expression { + "base-digest" + } -ParameterFilter { $Command -eq "dredge manifest resolve $baseImage --os linux --arch $architecture" } ` + -ModuleName common + + Mock Invoke-Expression { + "target-digest" + } -ParameterFilter { $Command -eq "dredge manifest resolve $targetImage --os linux --arch $architecture" } ` + -ModuleName common + $result = & $targetScript -TargetImage $targetImage -BaseImage $baseImage -Architecture $architecture + + $expected = @{ + sendDispatch = "true" + updates = @( + @{ + targetImageName = $targetImage + targetImageDigest = "target-digest" + dockerfile = "" + baseImageName = $baseImage + baseImageDigest = "base-digest" + } + ) + } | ConvertTo-Json - & $targetScript -TargetImage $targetImage -BaseImage $baseImage -Architecture $architecture | Should -Be "true" + $result | Should -Be $expected } It 'Given a failed dredge command, it throws an error' {