Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE]: extract line from file_regex and regex status check #1761

Closed
2 of 8 tasks
shahzebsiddiqui opened this issue Apr 22, 2024 · 1 comment · Fixed by #1781 or #1751
Closed
2 of 8 tasks

[FEATURE]: extract line from file_regex and regex status check #1761

shahzebsiddiqui opened this issue Apr 22, 2024 · 1 comment · Fixed by #1781 or #1751
Assignees

Comments

@shahzebsiddiqui
Copy link
Member

shahzebsiddiqui commented Apr 22, 2024

Please describe your feature

We should be able add support for extracting line when applying regular expression check in status check for file_regex and regex.

So take for example the following example, we have introduced linenum that can be applied to extract a line from file or stream. In this example we will extract the 1st and last line of count.txt which should evaluate to the correct expression which is 1, and 10 from the file. The regex check will pass for first test the expression 'Line\s\d+' should match any of the lines regardless of the line number we pick

In the next test, we should get a failure since we will extracting last line of stream which is ******** therefore the expression should fail.

buildspecs:
  extract_line_from_file_and_regex:
    type: script
    executor: generic.local.bash
    description: "Extract line from file and stream and apply regular expression"
    run: |
      for i in {1..10}; do      
        echo "Line $i"
      done
    status:
      file_regex:
        - file: count.txt
          exp: '^1$'
          linenum: 0
        - file: count.txt
          exp: '^10$'
          linenum: -1
      regex:
        stream: stdout
        exp: 'Line\s\d+'
  extract_line_failure:
    type: script
    executor: generic.local.bash
    description: Regular expression failure due to incorrect line
    run: |
      for i in {1..10}; do
        echo "Line $i" >> count.txt
        echo "Line $i"
      done
      echo "*********"
    status:
      regex:
        stream: stdout
        exp: 'Line\s\d+'
        linenum: -1

I ran this example without adding linenum to give you idea the 2nd test output should have ****** at end

(buildtest) ☁  general_tests [devel] ⚡  buildtest it query -o extract_line_failure 
──────────────────────────────────────────────────────────────────────────────────── extract_line_failure/5e3dbd09-4fb2-4d23-b628-b508108e04c6 ────────────────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Regular expression failure due to incorrect line
State: PASS
Returncode: 0
Runtime: 0.012094 sec
Starttime: 2024/04/26 12:45:15
Endtime: 2024/04/26 12:45:15
Command: bash extract_line_failure_build.sh
Test Script: /Users/siddiq90/Documents/buildtest/var/tests/generic.local.bash/a/extract_line_failure/5e3dbd09/extract_line_failure.sh
Build Script: /Users/siddiq90/Documents/buildtest/var/tests/generic.local.bash/a/extract_line_failure/5e3dbd09/extract_line_failure_build.sh
Output File: /Users/siddiq90/Documents/buildtest/var/tests/generic.local.bash/a/extract_line_failure/5e3dbd09/extract_line_failure.out
Error File: /Users/siddiq90/Documents/buildtest/var/tests/generic.local.bash/a/extract_line_failure/5e3dbd09/extract_line_failure.err
Log File: /Users/siddiq90/Documents/buildtest/var/logs/buildtest_t68eidr1.log
───────────────────────────────────────────── Output File: /Users/siddiq90/Documents/buildtest/var/tests/generic.local.bash/a/extract_line_failure/5e3dbd09/extract_line_failure.out ──────────────────────────────────────────────
Line 1                                                                                                                                                                                                                             
Line 2                                                                                                                                                                                                                             
Line 3                                                                                                                                                                                                                             
Line 4                                                                                                                                                                                                                             
Line 5                                                                                                                                                                                                                             
Line 6                                                                                                                                                                                                                             
Line 7                                                                                                                                                                                                                             
Line 8                                                                                                                                                                                                                             
Line 9                                                                                                                                                                                                                             
Line 10                                                                                                                                                                                                                            
*********                                 

TODO

Suggest potential solution

No response

Additional Information

No response

Post question in Slack

  • I agree that I posted my question in slack before creating this issue

Is there an existing issue

  • I confirm there is no existing issue for this issue
@shahzebsiddiqui
Copy link
Member Author

@Xiangs18 i think you should be able to complete this task, it is very similar to the ones you just completed #1726 except this is for status check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants