From 11b3d9887cfa55c52f55c47749fb3ba27d3f5610 Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Fri, 27 Dec 2024 21:28:55 +0530 Subject: [PATCH] refactor: enhance test case for R4 with MultiLineAssertion - 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. --- internal/stage_r4.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/internal/stage_r4.go b/internal/stage_r4.go index 59c16342..944a2a2f 100644 --- a/internal/stage_r4.go +++ b/internal/stage_r4.go @@ -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