-
-
Notifications
You must be signed in to change notification settings - Fork 21
[FEATURE]: extract line from file_regex and regex status check #1761
Description
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: -1I 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
- Update schema https://github.com/buildtesters/buildtest/blob/devel/buildtest/schemas/definitions.schema.json
- Add example buildspec in https://github.com/buildtesters/buildtest/tree/devel/tutorials/test_status
- Add implementation, see methods for
regex_checkandfile_regexandbuildtest/buildtest/buildsystem/checks.py
Line 97 in 140aabd
def file_regex_check(builder): . These are called in methodbuildtest/buildtest/buildsystem/checks.py
Line 161 in 140aabd
def regex_check(builder): check_test_stateseebuildtest/buildtest/builders/base.py
Line 1080 in 140aabd
def check_test_state(self): - Add regression test in https://github.com/buildtesters/buildtest/blob/devel/tests/builders/test_builders.py and create symlink for file
- Add symlink for valid buildspec example in https://github.com/buildtesters/buildtest/tree/devel/buildtest/schemas/examples/script.schema.json/valid
- Add an invalid test in https://github.com/buildtesters/buildtest/tree/devel/buildtest/schemas/examples/script.schema.json/invalid you can try to specify an invalid type for
linenumsuch as specifying a floating point value or using a list so you can do something likelinenum: 1.0orlinenum: [1, 3]. Anything that makes the schema fail.
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