Skip to content

Commit ddf85f0

Browse files
committed
Add a test for generating the trigger queue
1 parent eca0bed commit ddf85f0

File tree

7 files changed

+894
-4
lines changed

7 files changed

+894
-4
lines changed

.test/jq.sh

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,23 @@ dir="$(readlink -ve "$dir")"
88

99
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)
1010

11-
# TODO arguments for choosing a test? directory? name?
12-
for t in "$dir/"*"/test.jq"; do
11+
tests=( )
12+
# arguments can be a test name in "$dir" (that has a test.jq)
13+
if [ "$#" -gt 0 ]; then
14+
for t; do
15+
t="${t%/}" # drop trailing slash from user input
16+
file="$dir/$t/test.jq"
17+
if [ -f "$file" ]; then
18+
tests+=( "$file" )
19+
else
20+
echo >&2 'warning: skipping jq test "'"$t"'", missing test.jq'
21+
fi
22+
done
23+
else
24+
tests=( "$dir/"*"/test.jq" )
25+
fi
26+
27+
for t in "${tests[@]}"; do
1328
td="$(dirname "$t")"
1429
echo -n 'test: '
1530
basename "$td"
@@ -19,6 +34,20 @@ for t in "$dir/"*"/test.jq"; do
1934
else
2035
args+=( -n )
2136
fi
37+
for js in "$td/"*.json; do
38+
bn="$(basename "$js")"
39+
case "$bn" in
40+
'in.json'|'out.json')
41+
continue
42+
;;
43+
*)
44+
# create a variable name for the extra json file and slurp it
45+
bn="${bn%.json}" # drop the ".json" fileaname
46+
bn="${bn//[.-]/}" # jq variables don't work with dashes or dots
47+
args+=( --slurpfile "$bn" "$js" )
48+
;;
49+
esac
50+
done
2251
out="$td/out.json"
2352
outs=( "$td/out."* )
2453
if [ "${#outs[@]}" -eq 1 ]; then

.test/meta-queue/fake-data.sh

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
4+
dir="$(dirname "$BASH_SOURCE")"
5+
6+
tmpJson="$(mktemp)"
7+
trap 'rm $tmpJson' EXIT
8+
9+
jq -n -c '
10+
# input arch and test values
11+
# output unique buildId string
12+
def buildId($arch):
13+
[$arch, .[] | tostring] | join("-")
14+
;
15+
[
16+
# add new test cases here
17+
# each item will be used for each architecture generated
18+
# [ ".build.resloved", "count", "skips" ]
19+
[ null, 1, 0 ], # buildable, tried once
20+
[ null, 23, 0 ], # buildable, tried many but less than skip threshold
21+
[ null, 24, 0 ], # buildable, tried many, just on skip threshold
22+
[ null, 25, 23 ], # buildable, final skip
23+
[ null, 25, 24 ], # buildable, no longer skipped
24+
[ {}, 3, 0 ], # build "complete" (not queued or skipped)
25+
empty # trailing comma
26+
] as $data
27+
| [ "amd64", "arm32v7", "windows-amd64" ]
28+
| to_entries
29+
| (
30+
# making a list of build objects as a "builds.json"
31+
map(
32+
(.key | tostring) as $archindex
33+
| .value as $arch
34+
| $data | to_entries[]
35+
| (.value | buildId($arch)) as $buildId
36+
| .key as $index
37+
| .value[0] as $resolved
38+
| {
39+
($buildId): {
40+
$buildId,
41+
"build": {
42+
$arch,
43+
$resolved,
44+
"resolvedParents": {
45+
(if $arch | startswith("windows") then
46+
"windows:ltsc2022"
47+
else
48+
"debian:fake"
49+
end
50+
): {
51+
"manifests": [{
52+
"platform": (
53+
if $arch | startswith("windows") then
54+
{
55+
"architecture": "amd64",
56+
"os": "windows",
57+
"os.version": "10.0.20348.12345"
58+
}
59+
else
60+
{
61+
"architecture": ($arch | rtrimstr("v6")|rtrimstr("v7")|rtrimstr("v8")),
62+
"os": "linux"
63+
}
64+
end
65+
)
66+
}]
67+
}
68+
}
69+
},
70+
"source": {
71+
"arches": {
72+
($arch): {
73+
"tags": [("a","b","c") | . * ($index + 1)]
74+
}
75+
}
76+
}
77+
}
78+
}
79+
)
80+
| add
81+
), (
82+
# making a list of minimal build records like in "past-jobs.json"
83+
map(
84+
(.key | tostring) as $archindex
85+
| .value as $arch
86+
| $data | to_entries[]
87+
| (.value | buildId($arch)) as $buildId
88+
| .value[1] as $count
89+
| .value[2] as $skips
90+
| {
91+
($buildId|tostring): {
92+
$count,
93+
$skips
94+
}
95+
}
96+
)
97+
| add
98+
)
99+
' > "$tmpJson"
100+
101+
head -n1 "$tmpJson" | jq --tab '.' > "$dir/in.json"
102+
tail -n1 "$tmpJson" | jq --tab '.' > "$dir/past-jobs.json"

0 commit comments

Comments
 (0)