Skip to content

Commit

Permalink
refactor: enhance test case for R4 with MultiLineAssertion
Browse files Browse the repository at this point in the history
- Updated testR4 function to utilize MultiLineAssertion for error message validation.
- Replaced ExpectedOutput and FallbackPatterns with a more structured approach using AddSingleLineAssertion.
- Improved regex handling for error messages to ensure accurate assertions.
  • Loading branch information
ryan-gang committed Dec 27, 2024
1 parent 3ec77e8 commit 11b3d98
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions internal/stage_r4.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,20 @@ func testR4(stageHarness *test_case_harness.TestCaseHarness) error {
"cat: nonexistent: No such file or directory",
"ls: nonexistent: No such file or directory",
}

linuxLSErrorMessage := "ls: cannot access 'nonexistent': No such file or directory"
linuxLSErrorMessageRegex := []*regexp.Regexp{regexp.MustCompile(fmt.Sprintf("^%s$", linuxLSErrorMessage))}
alpineCatErrorMessage := "cat: can't open 'nonexistent': No such file or directory"
essorMessagesInFileRegex := []*regexp.Regexp{
regexp.MustCompile(fmt.Sprintf("^%s\n%s$", errorMessagesInFile[0], linuxLSErrorMessage)),
regexp.MustCompile(fmt.Sprintf("^%s\n%s$", alpineCatErrorMessage, errorMessagesInFile[1])),
}
alpineCatErrorMessageRegex := []*regexp.Regexp{regexp.MustCompile(fmt.Sprintf("^%s$", alpineCatErrorMessage))}

multiLineAssertion := assertions.NewEmptyMultiLineAssertion()
multiLineAssertion.AddSingleLineAssertion(errorMessagesInFile[0], alpineCatErrorMessageRegex)
multiLineAssertion.AddSingleLineAssertion(errorMessagesInFile[1], linuxLSErrorMessageRegex)

multiLineResponseTestCase := test_cases.CommandWithMultilineResponseTestCase{
Command: command7,
ExpectedOutput: errorMessagesInFile,
FallbackPatterns: essorMessagesInFileRegex,
SuccessMessage: "✓ Received redirected file content",
Command: command7,
MultiLineAssertion: multiLineAssertion,
SuccessMessage: "✓ Received redirected file content",
}
if err := multiLineResponseTestCase.Run(asserter, shell, logger); err != nil {
return err
Expand Down

0 comments on commit 11b3d98

Please sign in to comment.