-
Notifications
You must be signed in to change notification settings - Fork 9
Adding helper functions that reduce code duplications in TAP tests #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occ 8000 asionally send you account related emails.
Already on GitHub? Sign in to your account
base: TDE_REL_17_STABLE
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,4 +81,65 @@ sub compare_results | |
return compare($expected_filename_with_path, $out_filename_with_path); | ||
} | ||
|
||
# Common TDE helpers | ||
|
||
# Check if the encryption status of a table is as expected and return 't' or 'f' | ||
sub check_encryption_status | ||
{ | ||
my ($node, $table_name, $expected) = @_; | ||
my $result = | ||
safe_psql('postgres', "SELECT pg_tde_is_encrypted('$table_name')"); | ||
append_to_result_file($node->name . ": encryption check result for $table_name = $result"); | ||
is($result, $expected, "Check encryption status for '$table_name' on " . $node->name); | ||
} | ||
|
||
# Set up pg_tde extension and add a global key provider and set the server key | ||
sub setup_pg_tde_global_environment | ||
{ | ||
my ($node, $key_name, $provider_name, $provider_path) = @_; | ||
psql($node, 'postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;'); | ||
psql($node, 'postgres', | ||
"SELECT pg_tde_add_global_key_provider_file('$provider_name', '$provider_path');"); | ||
psql($node, 'postgres', | ||
"SELECT pg_tde_set_server_key_using_global_key_provider('$key_name', '$provider_name');"); | ||
} | ||
|
||
# Set up pg_tde extension and add a database key provider and set the database key | ||
sub setup_pg_tde_db_environment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and the previous function: maybe |
||
{ | ||
my ($node, $key_name, $provider_name, $provider_path) = @_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In most cases in tests nobody cares about the key and provider name, and path. So maybe have defaults like:
And then in most cases you call much more convenient |
||
psql($node, 'postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;'); | ||
psql($node, 'postgres', | ||
"SELECT pg_tde_add_database_key_provider_file('$provider_name', '$provider_path');"); | ||
psql($node, 'postgres', | ||
"SELECT pg_tde_set_key_using_database_key_provider('$key_name', '$provider_name');"); | ||
} | ||
|
||
# Set up pg_tde in postgresql.conf | ||
sub enable_pg_tde_in_conf | ||
{ | ||
my ($node) = @_; | ||
$node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_tde'"); | ||
} | ||
|
||
# Set default table access method to tde_heap | ||
sub set_default_table_am_tde_heap | ||
{ | ||
my ($node) = @_; | ||
$node->append_conf('postgresql.conf', "default_table_access_method = 'tde_heap'"); | ||
} | ||
Comment on lines
+119
to
+130
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about those two functions. I don't think anyone would memorize this func names, hence they would be copied from the existing tests anyway. But then it's not a bit difference which line is to copy (I mean |
||
|
||
# Set pg_tde.wal_encrypt and restart the server | ||
sub set_wal_encryption_and_restart | ||
{ | ||
my ($node, $value) = @_; | ||
|
||
die "Invalid value for wal_encrypt: must be 'on' or 'off'\n" | ||
unless $value eq 'on' || $value eq 'off'; | ||
|
||
psql($node, 'postgres', "ALTER SYSTEM SET pg_tde.wal_encrypt = $value;"); | ||
append_to_result_file("-- server restart with wal encryption = $value"); | ||
$node->restart; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having such helper functions for scaffolding purposes is a good idea, will reduce the clutter in the test files and look better. |
||
1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest not having such a test assertion (anything we use from Test::More) as part of a helper function; this should be handled in the main test file. That will make it easier to understand and follow the test case.