do not edit — generated by btf.
git.druid.rocksindexdruid520mptest/suites/multirepo.sh

test/suites/multirepo.sh


# suite: multi-repo ports resolution -- REPO_<name>=/REPO_<name>_PRIORITY=
# priority-ordered search across several independently configured ports
# repos, and that CUSTOM_PORTS still wins over all of them regardless of
# priority. these tests build the repos' directory trees directly (no
# real "git clone" -- init() only clones a repo dir that doesn't already
# exist, so pre-creating it keeps this fully offline) rather than through
# mkport/$SCRATCH, since $SCRATCH is fixed to the single default repo's
# layout ($PORTS_DIR/ports/scratch).
 
# writes a single trivial port "name" into repo directory "$1", installing
# a file stamped with tag "$2" so which repo actually won is checkable.
mr_write_port() {
	dir="$1"; name="$2"; tag="$3"
	mkdir -p "$dir/ports/scratch/$name"
	cat > "$dir/ports/scratch/$name/pkg.conf" <<EOF
pkg_name="$name"
pkg_ver="1.0"
install:
	touch \$MP_PREFIX/$tag-installed
remove:
	rm -f \$MP_PREFIX/$tag-installed
EOF
}
 
# two repos declaring the same port name -- the one with the LOWER
# REPO_*_PRIORITY value wins, resolved via the bare-name / all_ports()
# scan path (find_portdir's pkg_name/pkg_pref fallback when nothing is
# named exactly "mrbare" -- here it IS named exactly "mrbare", so this
# actually exercises all_ports()'s own priority-ordered, first-seen-wins
# dedup, the path a plain "mp install mrbare" takes).
test_repo_priority_lower_wins_bare() {
	t_begin "repo_priority_lower_wins_bare"
	reset_state
	rm -rf "$PORTS_DIR/repos"
	mr_write_port "$PORTS_DIR/repos/rpA" mrbare mrbare-A
	mr_write_port "$PORTS_DIR/repos/rpB" mrbare mrbare-B
	cat >> "$CONF" <<EOF
REPO_rpA=file://$PORTS_DIR/repos/rpA
REPO_rpA_PRIORITY=5
REPO_rpB=file://$PORTS_DIR/repos/rpB
REPO_rpB_PRIORITY=50
EOF
	mp install mrbare >/tmp/mr_bare.out 2>&1
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || { rm -rf "$PORTS_DIR/repos"; return; }
	assert_file_exists "$MP_PREFIX/mrbare-A-installed" "$CUR_TEST" || { rm -rf "$PORTS_DIR/repos"; return; }
	assert_file_absent "$MP_PREFIX/mrbare-B-installed" "$CUR_TEST" || { rm -rf "$PORTS_DIR/repos"; return; }
	rm -rf "$PORTS_DIR/repos"
	t_pass
}
 
# same shape, but installed by explicit "category/name" -- find_portdir's
# OWN priority-ordered loop (a separate code path from all_ports(), for
# the "user named the exact category/port" case).
test_repo_priority_lower_wins_explicit() {
	t_begin "repo_priority_lower_wins_explicit"
	reset_state
	rm -rf "$PORTS_DIR/repos"
	mr_write_port "$PORTS_DIR/repos/rpA" mrexplicit mrexplicit-A
	mr_write_port "$PORTS_DIR/repos/rpB" mrexplicit mrexplicit-B
	cat >> "$CONF" <<EOF
REPO_rpA=file://$PORTS_DIR/repos/rpA
REPO_rpA_PRIORITY=50
REPO_rpB=file://$PORTS_DIR/repos/rpB
REPO_rpB_PRIORITY=5
EOF
	mp install scratch/mrexplicit >/tmp/mr_explicit.out 2>&1
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || { rm -rf "$PORTS_DIR/repos"; return; }
	assert_file_exists "$MP_PREFIX/mrexplicit-B-installed" "$CUR_TEST" || { rm -rf "$PORTS_DIR/repos"; return; }
	assert_file_absent "$MP_PREFIX/mrexplicit-A-installed" "$CUR_TEST" || { rm -rf "$PORTS_DIR/repos"; return; }
	rm -rf "$PORTS_DIR/repos"
	t_pass
}
 
# CUSTOM_PORTS is checked before every configured repo, regardless of
# repo priority -- a local override always wins.
test_custom_ports_beats_all_repos() {
	t_begin "custom_ports_beats_all_repos"
	reset_state
	rm -rf "$PORTS_DIR/repos" /tmp/mr_custom
	mr_write_port "$PORTS_DIR/repos/rpA" mrcustom mrcustom-repo
	mkdir -p /tmp/mr_custom/scratch/mrcustom
	cat > /tmp/mr_custom/scratch/mrcustom/pkg.conf <<'EOF'
pkg_name="mrcustom"
pkg_ver="1.0"
install:
	touch $MP_PREFIX/mrcustom-custom-installed
remove:
	rm -f $MP_PREFIX/mrcustom-custom-installed
EOF
	cat >> "$CONF" <<EOF
REPO_rpA=file://$PORTS_DIR/repos/rpA
REPO_rpA_PRIORITY=1
EOF
	CUSTOM_PORTS_DIR=/tmp/mr_custom mp install mrcustom >/tmp/mr_custom.out 2>&1
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || { rm -rf "$PORTS_DIR/repos" /tmp/mr_custom; return; }
	assert_file_exists "$MP_PREFIX/mrcustom-custom-installed" "$CUR_TEST" || { rm -rf "$PORTS_DIR/repos" /tmp/mr_custom; return; }
	assert_file_absent "$MP_PREFIX/mrcustom-repo-installed" "$CUR_TEST" || { rm -rf "$PORTS_DIR/repos" /tmp/mr_custom; return; }
	rm -rf "$PORTS_DIR/repos" /tmp/mr_custom
	t_pass
}
 
# zero REPO_* configured (the default $CONF_ORIG this whole suite runs
# under) resolves ports directly from $PORTS_DIR/ports, exactly as a
# single PORTS_REPO always did -- the backward-compatible path every
# other suite in this whole tree already relies on implicitly; this test
# just makes that reliance explicit and locked-down.
test_zero_repo_config_uses_portsdir_directly() {
	t_begin "zero_repo_config_uses_portsdir_directly"
	reset_state
	mkport mrdefault <<'EOF'
pkg_name="mrdefault"
pkg_ver="1.0"
install:
	touch $MP_PREFIX/mrdefault-installed
remove:
	rm -f $MP_PREFIX/mrdefault-installed
EOF
	mp install mrdefault >/tmp/mr_default.out 2>&1
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || return
	assert_file_exists "$MP_PREFIX/mrdefault-installed" "$CUR_TEST" || return
	assert_file_exists "$PORTS_DIR/ports/scratch/mrdefault/pkg.conf" "$CUR_TEST" || return
	t_pass
}
 
# a "::reponame" atom suffix (mplib::version::parse_dep_token) picks
# ONE specific repo's copy outright, overriding the normal priority
# order entirely -- rpA would win by priority alone (lower number),
# same setup as test_repo_priority_lower_wins_bare, but naming "::rpB"
# explicitly must still resolve to rpB's own copy regardless.
test_repo_qualifier_overrides_priority() {
	t_begin "repo_qualifier_overrides_priority"
	reset_state
	rm -rf "$PORTS_DIR/repos"
	mr_write_port "$PORTS_DIR/repos/rpA" mrqual mrqual-A
	mr_write_port "$PORTS_DIR/repos/rpB" mrqual mrqual-B
	cat >> "$CONF" <<EOF
REPO_rpA=file://$PORTS_DIR/repos/rpA
REPO_rpA_PRIORITY=5
REPO_rpB=file://$PORTS_DIR/repos/rpB
REPO_rpB_PRIORITY=50
EOF
	mp install mrqual::rpB >/tmp/mr_qual.out 2>&1
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || { rm -rf "$PORTS_DIR/repos"; return; }
	assert_file_exists "$MP_PREFIX/mrqual-B-installed" "$CUR_TEST" || { rm -rf "$PORTS_DIR/repos"; return; }
	assert_file_absent "$MP_PREFIX/mrqual-A-installed" "$CUR_TEST" || { rm -rf "$PORTS_DIR/repos"; return; }
	rm -rf "$PORTS_DIR/repos"
	t_pass
}
 
# same setup, but naming a repo that isn't configured at all -- must
# fail cleanly (not silently fall back to the normal priority search,
# which would defeat the whole point of asking for one specific repo).
test_repo_qualifier_nonexistent_repo_fails() {
	t_begin "repo_qualifier_nonexistent_repo_fails"
	reset_state
	rm -rf "$PORTS_DIR/repos"
	mr_write_port "$PORTS_DIR/repos/rpA" mrqualbad mrqualbad-A
	cat >> "$CONF" <<EOF
REPO_rpA=file://$PORTS_DIR/repos/rpA
EOF
	out=$(mp install mrqualbad::nosuchrepo 2>&1)
	rc=$?
	assert_exit_nonzero "$rc" "$CUR_TEST" || { rm -rf "$PORTS_DIR/repos"; return; }
	assert_file_absent "$MP_PREFIX/mrqualbad-A-installed" "$CUR_TEST" || { rm -rf "$PORTS_DIR/repos"; return; }
	assert_contains "$out" "not found" "$CUR_TEST" || { rm -rf "$PORTS_DIR/repos"; return; }
	rm -rf "$PORTS_DIR/repos"
	t_pass
}
 
run_multirepo_suite() {
	test_repo_priority_lower_wins_bare
	test_repo_priority_lower_wins_explicit
	test_custom_ports_beats_all_repos
	test_zero_repo_config_uses_portsdir_directly
	test_repo_qualifier_overrides_priority
	test_repo_qualifier_nonexistent_repo_fails
}
powered by btf.