Skip to content

Commit 521e929

Browse files
committed
make tests actaully fail:
1 parent 5ba0e3d commit 521e929

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

e2e/validators.go

+22-8
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ func ValidateNonEmptyDirectory(ctx context.Context, s *Scenario, dirName string)
8181
func ValidateFileHasContent(ctx context.Context, s *Scenario, fileName string, contents string) {
8282
if s.VHD.OS == config.OSWindows {
8383
steps := []string{
84+
"$ErrorActionPreference = \"Stop\"",
8485
fmt.Sprintf("dir %[1]s", fileName),
8586
fmt.Sprintf("Get-Content %[1]s", fileName),
86-
fmt.Sprintf("if (Select-String -Path %s -Pattern \"%s\" -SimpleMatch -Quiet) { return 1 } else { return 0 }", fileName, contents),
87+
fmt.Sprintf("if ( -not ( Test-Path -Path %s ) ) { exit 2 }", fileName),
88+
fmt.Sprintf("if (Select-String -Path %s -Pattern \"%s\" -SimpleMatch -Quiet) { exit 0 } else { exit 1 }", fileName, contents),
8789
}
8890

8991
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
102104
func ValidateFileExcludesContent(ctx context.Context, s *Scenario, fileName string, contents string) {
103105
require.NotEqual(s.T, "", contents, "Test setup failure: Can't validate that a file excludes an empty string. Filename: %s", fileName)
104106

105-
steps := []string{
106-
"set -ex",
107-
fmt.Sprintf("test -f %[1]s || exit 0", fileName),
108-
fmt.Sprintf("ls -la %[1]s", fileName),
109-
fmt.Sprintf("sudo cat %[1]s", fileName),
110-
fmt.Sprintf("(sudo cat %[1]s | grep -q -v -F -e %[2]q)", fileName, contents),
107+
if s.VHD.OS == config.OSWindows {
108+
steps := []string{
109+
"$ErrorActionPreference = \"Stop\"",
110+
fmt.Sprintf("dir %[1]s", fileName),
111+
fmt.Sprintf("Get-Content %[1]s", fileName),
112+
fmt.Sprintf("if ( -not ( Test-Path -Path %s ) ) { exit 2 }", fileName),
113+
fmt.Sprintf("if (Select-String -Path %s -Pattern \"%s\" -SimpleMatch -Quiet) { exit 1 } else { exit 0 }", fileName, contents),
114+
}
115+
116+
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")
117+
} else {
118+
steps := []string{
119+
"set -ex",
120+
fmt.Sprintf("test -f %[1]s || exit 0", fileName),
121+
fmt.Sprintf("ls -la %[1]s", fileName),
122+
fmt.Sprintf("sudo cat %[1]s", fileName),
123+
fmt.Sprintf("(sudo cat %[1]s | grep -q -v -F -e %[2]q)", fileName, contents),
124+
}
125+
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")
111126
}
112-
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")
113127
}
114128

115129
func ServiceCanRestartValidator(ctx context.Context, s *Scenario, serviceName string, restartTimeoutInSeconds int) {

0 commit comments

Comments
 (0)