From 7e1c18af5468c7708e28de759911ec5542d23c4b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 21 Jul 2021 14:05:50 +0000 Subject: init: allow arbitrary key-values via -c KEY=VALUE This won't blindly append identical key=values, but allows specifying multiple, different key=value pairs as long as the values are different. --- t/init.t | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 't/init.t') diff --git a/t/init.t b/t/init.t index d46bef23..7382e05b 100644 --- a/t/init.t +++ b/t/init.t @@ -48,6 +48,40 @@ sub quiet_fail { is($? >> 8, 255, 'got expected exit code on lock failure'); ok(unlink("$cfgfile.lock"), '-init did not unlink lock on failure'); + + my @init_args = ('i', "$tmpdir/i", + qw(http://example.com/i i@example.com)); + $cmd = [ qw(-init -c .bogus=val), @init_args ]; + quiet_fail($cmd, 'invalid -c KEY=VALUE fails'); + $cmd = [ qw(-init -c .bogus=val), @init_args ]; + quiet_fail($cmd, '-c KEY-only fails'); + $cmd = [ qw(-init -c address=clist@example.com), @init_args ]; + quiet_fail($cmd, '-c address=CONFLICTING-VALUE fails'); + + $cmd = [ qw(-init -c no=problem -c no=problemo), @init_args ]; + ok(run_script($cmd), '-c KEY=VALUE runs'); + my $env = { GIT_CONFIG => "$ENV{PI_DIR}/config" }; + chomp(my @v = xqx([qw(git config --get-all publicinbox.i.no)], $env)); + is_deeply(\@v, [ qw(problem problemo) ]) or xbail(\@v); + + ok(run_script($cmd), '-c KEY=VALUE runs idempotently'); + chomp(my @v2 = xqx([qw(git config --get-all publicinbox.i.no)], $env)); + is_deeply(\@v, \@v2, 'nothing repeated') or xbail(\@v2); + + ok(run_script([@$cmd, '-c', 'no=more']), '-c KEY=VALUE addendum'); + chomp(@v = xqx([qw(git config --get-all publicinbox.i.no)], $env)); + is_deeply(\@v, [ qw(problem problemo more) ]) or xbail(\@v); + + + ok(run_script([@$cmd, '-c', 'no=problem']), '-c KEY=VALUE repeated'); + chomp(@v = xqx([qw(git config --get-all publicinbox.i.no)], $env)); + is_deeply(\@v, [ qw(problem problemo more) ]) or xbail(\@v); + + ok(run_script([@$cmd, '-c', 'address=j@example.com']), + '-c KEY=VALUE address'); + chomp(@v = xqx([qw(git config --get-all publicinbox.i.address)], $env)); + is_deeply(\@v, [ qw(i@example.com j@example.com) ], + 'extra address added via -c KEY=VALUE'); } { my $env = { PI_DIR => "$tmpdir/.public-inbox/" }; -- cgit v1.2.3-24-ge0c7