Skip to content

Commit

Permalink
Add a test for generating the trigger queue
Browse files Browse the repository at this point in the history
  • Loading branch information
yosifkit committed Nov 19, 2024
1 parent 0e0243a commit 929478c
Show file tree
Hide file tree
Showing 7 changed files with 891 additions and 4 deletions.
33 changes: 31 additions & 2 deletions .test/jq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,23 @@ dir="$(readlink -ve "$dir")"

export SOURCE_DATE_EPOCH=0 # TODO come up with a better way for a test to specify it needs things like this (maybe a file that gets sourced/read for options/setup type things? could also provide args/swap 'out' like our "-r" hank below)

# TODO arguments for choosing a test? directory? name?
for t in "$dir/"*"/test.jq"; do
tests=( )
# arguments can be a test name in "$dir" (that has a test.jq)
if [ "$#" -gt 0 ]; then
for t; do
t="${t%/}" # drop trailing slash from user input
file="$dir/$t/test.jq"
if [ -f "$file" ]; then
tests+=( "$file" )
else
echo >&2 'warning: skipping jq test "'"$t"'", missing test.jq'
fi
done
else
tests=( "$dir/"*"/test.jq" )
fi

for t in "${tests[@]}"; do
td="$(dirname "$t")"
echo -n 'test: '
basename "$td"
Expand All @@ -19,6 +34,20 @@ for t in "$dir/"*"/test.jq"; do
else
args+=( -n )
fi
for js in "$td/"*.json; do
bn="$(basename "$js")"
case "$bn" in
'in.json'|'out.json')
continue
;;
*)
# create a variable name for the extra json file and slurp it
bn="${bn%.json}" # drop the ".json" fileaname
bn="${bn//[.-]/}" # jq variables don't work with dashes or dots
args+=( --slurpfile "$bn" "$js" )
;;
esac
done
out="$td/out.json"
outs=( "$td/out."* )
if [ "${#outs[@]}" -eq 1 ]; then
Expand Down
102 changes: 102 additions & 0 deletions .test/meta-queue/fake-data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env bash
set -Eeuo pipefail

dir="$(dirname "$BASH_SOURCE")"

tmpJson="$(mktemp)"
trap 'rm $tmpJson' EXIT

jq -n -c '
# input arch and test values
# output unique buildId string
def buildId($arch):
[$arch, .[] | tostring] | join("-")
;
[
# add new test cases here
# each item will be used for each architecture generated
# [ ".build.resloved", "count", "skips" ]
[ null, 1, 0 ], # buildable, tried once
[ null, 23, 0 ], # buildable, tried many but less than skip threshold
[ null, 24, 0 ], # buildable, tried many, just on skip threshold
[ null, 25, 23 ], # buildable, final skip
[ null, 25, 24 ], # buildable, no longer skipped
[ {}, 3, 0 ], # build "complete" (not queued or skipped)
empty # trailing comma
] as $data
| [ "amd64", "arm32v7", "windows-amd64" ]
| to_entries
| (
# making a list of build objects as a "builds.json"
map(
(.key | tostring) as $archindex
| .value as $arch
| $data | to_entries[]
| (.value | buildId($arch)) as $buildId
| .key as $index
| .value[0] as $resolved
| {
($buildId): {
$buildId,
"build": {
$arch,
$resolved,
"resolvedParents": {
(if $arch | startswith("windows") then
"windows:ltsc2022"
else
"debian:fake"
end
): {
"manifests": [{
"platform": (
if $arch | startswith("windows") then
{
"architecture": "amd64",
"os": "windows",
"os.version": "10.0.20348.12345"
}
else
{
"architecture": ($arch | rtrimstr("v6")|rtrimstr("v7")|rtrimstr("v8")),
"os": "linux"
}
end
)
}]
}
}
},
"source": {
"arches": {
($arch): {
"tags": [("a","b","c") | . * ($index + 1)]
}
}
}
}
}
)
| add
), (
# making a list of minimal build records like in "past-jobs.json"
map(
(.key | tostring) as $archindex
| .value as $arch
| $data | to_entries[]
| (.value | buildId($arch)) as $buildId
| .value[1] as $count
| .value[2] as $skips
| {
($buildId|tostring): {
$count,
$skips
}
}
)
| add
)
' > "$tmpJson"

head -n1 "$tmpJson" | jq --tab '.' > "$dir/in.json"
tail -n1 "$tmpJson" | jq --tab '.' > "$dir/past-jobs.json"
Loading

0 comments on commit 929478c

Please sign in to comment.