mirror of
https://github.com/block/buzz.git
synced 2026-11-06 01:11:33 +00:00
fix(scripts): pass rename values as --name=value
clap reads a separate value that starts with "-" as a flag, so a duplicate named "-ops" failed to rename on every run. Attach each value with "=" and make the test's stand-in CLI accept only that form, with a name that starts with "-". Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Logan Johnson <loganj@squareup.com>
This commit is contained in:
@@ -194,7 +194,8 @@ async fn plan_picks_a_free_name_when_the_short_one_is_taken() {
|
||||
|
||||
/// The real script, with a stand-in CLI that logs each call and applies the
|
||||
/// rename. A name may hold any character but NUL, so a name holding control
|
||||
/// characters must still yield exactly one rename, of its own channel.
|
||||
/// characters must still yield exactly one rename, of its own channel. Like
|
||||
/// clap, the stand-in takes a value that starts with "-" only as `--name=`.
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
#[ignore = "requires Postgres"]
|
||||
@@ -203,7 +204,7 @@ async fn script_renames_each_planned_channel_once_whatever_its_name() {
|
||||
let (pool, name) = create_scratch_db(&admin, "listed_name_script").await;
|
||||
let seed = Seed::new(&pool).await;
|
||||
let [kept, duplicate, other] = [(); 3].map(|_| Uuid::new_v4());
|
||||
let tricky = format!("ops\x1e{other}\x1fowned\x1f\n\t\"$(x)");
|
||||
let tricky = format!("-ops\x1e{other}\x1fowned\x1f\n\t\"$(x)");
|
||||
seed.open(&pool, kept, &tricky, 30).await;
|
||||
seed.open(&pool, duplicate, &tricky, 10).await;
|
||||
seed.open(&pool, other, "other", 20).await;
|
||||
@@ -214,7 +215,8 @@ async fn script_renames_each_planned_channel_once_whatever_its_name() {
|
||||
std::fs::write(
|
||||
&cli,
|
||||
"#!/usr/bin/env bash\nset -euo pipefail\nprintf '%s\\0' \"$@\" >>\"$STUB_LOG\"\n\
|
||||
psql \"$DATABASE_URL\" -X -q -v ON_ERROR_STOP=1 -v id=\"$4\" -v name=\"$6\" <<'SQL'\n\
|
||||
[[ $3 == --channel=* && $4 == --name=* ]] || exit 2\n\
|
||||
psql \"$DATABASE_URL\" -X -q -v ON_ERROR_STOP=1 -v id=\"${3#*=}\" -v name=\"${4#*=}\" <<'SQL'\n\
|
||||
UPDATE channels SET name = :'name' WHERE id = :'id';\nSQL\n",
|
||||
)
|
||||
.unwrap();
|
||||
@@ -248,14 +250,13 @@ async fn script_renames_each_planned_channel_once_whatever_its_name() {
|
||||
let new_name = renamed(duplicate, &tricky).1;
|
||||
let calls = std::fs::read(&log).unwrap();
|
||||
let args: Vec<&[u8]> = calls.split(|b| *b == 0).collect();
|
||||
let channel = duplicate.to_string();
|
||||
let channel = format!("--channel={duplicate}");
|
||||
let name_arg = format!("--name={new_name}");
|
||||
let expected: Vec<&[u8]> = vec![
|
||||
b"channels",
|
||||
b"update",
|
||||
b"--channel",
|
||||
channel.as_bytes(),
|
||||
b"--name",
|
||||
new_name.as_bytes(),
|
||||
name_arg.as_bytes(),
|
||||
b"",
|
||||
];
|
||||
assert_eq!(args, expected, "one call, for the duplicate only");
|
||||
|
||||
@@ -62,10 +62,11 @@ renamed=0
|
||||
failed=0
|
||||
while IFS= read -r -d '' channel && IFS= read -r -d '' name &&
|
||||
IFS= read -r -d '' new_name; do
|
||||
# --name=value, so a name that starts with "-" is not read as a flag.
|
||||
if $dry_run; then
|
||||
printf 'would rename %s from %q to %q\n' "$channel" "$name" "$new_name"
|
||||
elif BUZZ_RELAY_URL=$relay_url "$buzz" channels update \
|
||||
--channel "$channel" --name "$new_name" </dev/null >/dev/null; then
|
||||
--channel="$channel" --name="$new_name" </dev/null >/dev/null; then
|
||||
printf 'renamed %s from %q to %q\n' "$channel" "$name" "$new_name"
|
||||
renamed=$((renamed + 1))
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user