1+ #! /bin/bash
2+
3+ # shellcheck disable=SC1091,SC2034
4+
5+ set -euo pipefail
6+
7+ script_dir=$( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd)
8+ src_dir=$( cd " $script_dir /.." && pwd)
9+ workdir=$( mktemp -d)
10+
11+ cleanup () {
12+ rm -rf " $workdir "
13+ }
14+
15+ fail () {
16+ echo " $1 " >&2
17+ exit 1
18+ }
19+
20+ init_bkg_state () {
21+ local now
22+ now=$( date -u +%s)
23+ : > " $BKG_ENV "
24+ : > " $BKG_OWNERS "
25+ : > " $BKG_OPTOUT "
26+ mkdir -p " $BKG_INDEX_DIR "
27+ BKG_SCRIPT_START=" $now "
28+ set_BKG BKG_SCRIPT_START " $now "
29+ set_BKG BKG_RATE_LIMIT_START " $now "
30+ set_BKG BKG_MIN_RATE_LIMIT_START " $now "
31+ set_BKG BKG_CALLS_TO_API " 0"
32+ set_BKG BKG_MIN_CALLS_TO_API " 0"
33+ }
34+
35+ trap cleanup EXIT
36+
37+ pushd " $src_dir " > /dev/null
38+ export BKG_SKIP_DEP_VERIFY=1
39+ source lib/owner.sh
40+ popd > /dev/null
41+
42+ BKG_ENV=" $workdir /env.env"
43+ BKG_OWNERS=" $workdir /owners.txt"
44+ BKG_OPTOUT=" $workdir /optout.txt"
45+ BKG_INDEX_DIR=" $workdir /index"
46+
47+ connections=" $workdir /connections.txt"
48+ owners_file=" $workdir /manual-owners.txt"
49+ index_repo=" $workdir /index-repo"
50+
51+ mkdir -p " $index_repo "
52+ git -C " $index_repo " init -q
53+ git -C " $index_repo " config user.name test
54+ git -C " $index_repo " config user.email test@example.com
55+ echo README > " $index_repo /README.md"
56+ git -C " $index_repo " add README.md
57+ git -C " $index_repo " commit -qm init
58+
59+ printf ' %s\n' gianlazz Lazztech > " $connections "
60+ : > " $owners_file "
61+ : > " $workdir /all_owners_in_db"
62+ : > " $workdir /owners_partially_updated"
63+ : > " $workdir /owners_stale"
64+
65+ pushd " $workdir " > /dev/null
66+ admitted=$( bash " $src_dir /lib/get.sh" 0 " $connections " 20 ipitio " $owners_file " " $index_repo " )
67+ popd > /dev/null
68+
69+ grep -Fxq Lazztech <<< " $admitted" || fail " Expected discovered second-hop org to survive owner admission"
70+
71+ init_bkg_state
72+ save_owner " 556677/Lazztech" > /dev/null
73+ grep -Fxq " 556677/Lazztech" <<< " $(get_BKG_set BKG_OWNERS_QUEUE)" || fail " Expected discovered org to be queued for owner updates"
74+
75+ pushd " $workdir " > /dev/null
76+ : > packages_already_updated
77+ owner_id=556677
78+ owner=Lazztech
79+ owner_type=orgs
80+ fast_out=false
81+
82+ curl () {
83+ cat << 'EOF '
84+ <div>
85+ <a href="/orgs/Lazztech/packages/container/package/libre-closet">libre-closet</a>
86+ <a href="/Lazztech/Libre-Closet">Libre-Closet</a>
87+ </div>
88+ EOF
89+ }
90+
91+ run_parallel () {
92+ local function_name=$1
93+ local items=$2
94+
95+ while IFS= read -r item; do
96+ [ -n " $item " ] || continue
97+ " $function_name " " $item "
98+ done <<< " $items"
99+ }
100+
101+ page_package 1 > /dev/null
102+ popd > /dev/null
103+
104+ grep -Fxq " container/Libre-Closet/libre-closet" <<< " $(get_BKG_set BKG_PACKAGES_Lazztech)" || fail " Expected queued package list to include Lazztech/libre-closet"
105+
106+ echo " Second-hop discovery regression test passed"
0 commit comments