test: fix cloud functional tests - #585
Conversation
✅MegaLinter analysis: Success
Notices📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining See detailed reports in MegaLinter artifacts MegaLinter is graciously provided by OX Security |
| jq -r ' | ||
| if type == "array" then .[0].id // empty | ||
| else | ||
| .items[0].id |
There was a problem hiding this comment.
// does not catch jq errors. On a non-array object, .items[0].id throws Cannot index null with number whenever .items is absent, so the .projects / .filters / .rulesets / .deployments alternatives never run. With set -euo pipefail, ensure then aborts on a successful list like {"deployments":[{"id":"d1"}]}. Use try/catch (or ?) on each path, or pick one array with (.items // .projects // .filters // .rulesets // .deployments // [])[0].id.
| // `try` so a nested path like `.regions[0].id` against a bare array | ||
| // yields empty instead of aborting the script (jq cannot index an | ||
| // array with a string). | ||
| lines.push(`${indent}${bashVar}=$(echo "$RESPONSE" | jq -r 'try (${jqPath} // empty) catch empty')`) |
There was a problem hiding this comment.
Same jq pitfall in the skipEmptySet fallback: .items[0].id errors on objects that are not {items:[...]} (e.g. {"deployments":[]} after the primary path already yielded empty). skipNotFound also emits set -e, so that error aborts the script instead of reaching the SKIP. Wrap the fallback in try/catch empty (or only fall back when type=="array").
Skip empty-org item GETs and public QA 404s so Cloud functional tests can fail the build. CI creates search, observability, and security projects, traffic filters, and a hosted deployment when those lists are empty. Relates to #584.