Re: New test function replace_conf() to get rid of unlink/append pattern

From: Nazir Bilal Yavuz <byavuz81(at)gmail(dot)com>
To: Daniel Gustafsson <daniel(at)yesql(dot)se>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: New test function replace_conf() to get rid of unlink/append pattern
Date: 2026-10-13 08:30:57
Message-ID: CAN55FZ3z=sTxuJRYZxJ0fzNF_VqXDSMrmxo6iXthjXZ+UgEWNA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Mon, 12 Oct 2026 at 12:19, Daniel Gustafsson <daniel(at)yesql(dot)se> wrote:
>
> To make the TAP tests more readable I propose a utility function which combines
> these two operations, replace_conf(). It works just like how unlink() together
> with append_conf() does but in fewer and more readable lines of code. I chose
> replace rather than rewrite since it IMO more clearly signals that nothing in
> the file is kept.

LGTM. We might add these as well:

diff --git a/src/test/ssl/t/SSL/Server.pm b/src/test/ssl/t/SSL/Server.pm
index db70e8d5255..d0e7d29c12c 100644
--- a/src/test/ssl/t/SSL/Server.pm
+++ b/src/test/ssl/t/SSL/Server.pm
@@ -323,8 +323,7 @@ sub switch_server_cert
my %params = @_;
my $pgdata = $node->data_dir;

- ok(unlink($node->data_dir . '/sslconfig.conf'));
- $node->append_conf('sslconfig.conf', 'ssl=on');
+ $node->replace_conf('sslconfig.conf', 'ssl=on');
$node->append_conf('sslconfig.conf',
$backend->set_server_cert(\%params));
# use lists of ECDH curves and cipher suites for syntax testing
$node->append_conf('sslconfig.conf', 'ssl_groups=prime256v1:secp521r1');
@@ -357,8 +356,7 @@ sub _configure_hba_for_ssl
# but seems best to keep it as narrow as possible for security reasons.
#
# When connecting to certdb, also check the client certificate.
- ok(unlink($node->data_dir . '/pg_hba.conf'));
- $node->append_conf(
+ $node->replace_conf(
'pg_hba.conf', <<EOF
# TYPE DATABASE USER ADDRESS METHOD OPTIONS
hostssl trustdb md5testuser $servercidr md5
@@ -374,8 +372,7 @@ EOF
);

# Also set the ident maps. Note: fields with commas must be quoted
- ok(unlink($node->data_dir . '/pg_ident.conf'));
- $node->append_conf(
+ $node->replace_conf(
'pg_ident.conf', <<EOF
# MAPNAME SYSTEM-USERNAME PG-USERNAME
dn "CN=ssltestuser-dn,OU=Testing,OU=Engineering,O=PGDG" ssltestuser

I also thought if it would be better that replace_conf() accepts full
path instead of a relative path. I think what you did (relative path)
is better.

--
Regards,
Nazir Bilal Yavuz
Microsoft

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Dilip Kumar 2026-10-13 09:08:57 Re: Proposal: Conflict log history table for Logical Replication
Previous Message jian he 2026-10-13 08:23:26 Re: json/jsonb cleanup + FmgrInfo caching