From 521e9292151686766ace531febee7c1dbdaed58b Mon Sep 17 00:00:00 2001 From: Tim Wright Date: Thu, 6 Mar 2025 04:25:46 +0000 Subject: [PATCH] make tests actaully fail: --- e2e/validators.go | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/e2e/validators.go b/e2e/validators.go index 6f6e9b21c32..a0d9ac6253f 100644 --- a/e2e/validators.go +++ b/e2e/validators.go @@ -81,9 +81,11 @@ func ValidateNonEmptyDirectory(ctx context.Context, s *Scenario, dirName string) func ValidateFileHasContent(ctx context.Context, s *Scenario, fileName string, contents string) { if s.VHD.OS == config.OSWindows { steps := []string{ + "$ErrorActionPreference = \"Stop\"", fmt.Sprintf("dir %[1]s", fileName), fmt.Sprintf("Get-Content %[1]s", fileName), - fmt.Sprintf("if (Select-String -Path %s -Pattern \"%s\" -SimpleMatch -Quiet) { return 1 } else { return 0 }", fileName, contents), + fmt.Sprintf("if ( -not ( Test-Path -Path %s ) ) { exit 2 }", fileName), + fmt.Sprintf("if (Select-String -Path %s -Pattern \"%s\" -SimpleMatch -Quiet) { exit 0 } else { exit 1 }", fileName, contents), } execScriptOnVMForScenarioValidateExitCode(ctx, s, strings.Join(steps, "\n"), 0, "could not validate file has contents - might mean file does not have contents, might mean something went wrong") @@ -102,14 +104,26 @@ func ValidateFileHasContent(ctx context.Context, s *Scenario, fileName string, c func ValidateFileExcludesContent(ctx context.Context, s *Scenario, fileName string, contents string) { require.NotEqual(s.T, "", contents, "Test setup failure: Can't validate that a file excludes an empty string. Filename: %s", fileName) - steps := []string{ - "set -ex", - fmt.Sprintf("test -f %[1]s || exit 0", fileName), - fmt.Sprintf("ls -la %[1]s", fileName), - fmt.Sprintf("sudo cat %[1]s", fileName), - fmt.Sprintf("(sudo cat %[1]s | grep -q -v -F -e %[2]q)", fileName, contents), + if s.VHD.OS == config.OSWindows { + steps := []string{ + "$ErrorActionPreference = \"Stop\"", + fmt.Sprintf("dir %[1]s", fileName), + fmt.Sprintf("Get-Content %[1]s", fileName), + fmt.Sprintf("if ( -not ( Test-Path -Path %s ) ) { exit 2 }", fileName), + fmt.Sprintf("if (Select-String -Path %s -Pattern \"%s\" -SimpleMatch -Quiet) { exit 1 } else { exit 0 }", fileName, contents), + } + + execScriptOnVMForScenarioValidateExitCode(ctx, s, strings.Join(steps, "\n"), 0, "could not validate file has contents - might mean file does not have contents, might mean something went wrong") + } else { + steps := []string{ + "set -ex", + fmt.Sprintf("test -f %[1]s || exit 0", fileName), + fmt.Sprintf("ls -la %[1]s", fileName), + fmt.Sprintf("sudo cat %[1]s", fileName), + fmt.Sprintf("(sudo cat %[1]s | grep -q -v -F -e %[2]q)", fileName, contents), + } + execScriptOnVMForScenarioValidateExitCode(ctx, s, strings.Join(steps, "\n"), 0, "could not validate file excludes contents - might mean file does have contents, might mean something went wrong") } - execScriptOnVMForScenarioValidateExitCode(ctx, s, strings.Join(steps, "\n"), 0, "could not validate file excludes contents - might mean file does have contents, might mean something went wrong") } func ServiceCanRestartValidator(ctx context.Context, s *Scenario, serviceName string, restartTimeoutInSeconds int) {