Add expect_match function to simplify tests Change-Id: I1bbf9546ac09a46972a176f3a2f8efb420283a69
diff --git a/setup.sh b/setup.sh index a8e58f3..08c3fd1 100644 --- a/setup.sh +++ b/setup.sh
@@ -326,6 +326,32 @@ fi fi +## Watch a file for a pattern and exit when matched or timed out +function expect_match +{ + local log_path="$(realpath $1)" + local match_string="$2" + local timeout="$3" + + local usage="Usage: expect_match <file path> <pattern> [timeout] + filepath: Path to file to search + pattern: grep regexp pattern + timeout: optional timeout, defaults to 30s" + + if [[ -z "${log_path}" ]]; then + echo usage + return 1 + fi + + if [[ -z "${timeout}" ]]; then + timeout="30s" + fi + + echo "Watching for ${match_string} in ${log_path}" + timeout "${timeout}" bash -c "until grep -q -e \"${match_string}\" \"${log_path}\"; do sleep 1; done" +} + + # Explicitly set the variables to run the venv python interpreter. export PATH="${PYTHON_SHODAN_ENV}/bin:${PATH}" export VIRTUAL_ENV="${PYTHON_SHODAN_ENV}"