Skip to content

Commit 547081e

Browse files
Merge branch 'master' into skip-ssl-check
2 parents dc4b4c3 + 5e9ecbc commit 547081e

File tree

8 files changed

+106
-23
lines changed

8 files changed

+106
-23
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ with testgres.get_new_node() as node:
5959
# ... node stops and its files are about to be removed
6060
```
6161

62-
There are four API methods for runnig queries:
62+
There are four API methods for running queries:
6363

6464
| Command | Description |
6565
|----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
6666
| `node.psql(query, ...)` | Runs query via `psql` command and returns tuple `(error code, stdout, stderr)`. |
67-
| `node.safe_psql(query, ...)` | Same as `psql()` except that it returns only `stdout`. If an error occures during the execution, an exception will be thrown. |
67+
| `node.safe_psql(query, ...)` | Same as `psql()` except that it returns only `stdout`. If an error occurs during the execution, an exception will be thrown. |
6868
| `node.execute(query, ...)` | Connects to PostgreSQL using `psycopg2` or `pg8000` (depends on which one is installed in your system) and returns two-dimensional array with data. |
6969
| `node.connect(dbname, ...)` | Returns connection wrapper (`NodeConnection`) capable of running several queries within a single transaction. |
7070

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
readme = f.read()
2828

2929
setup(
30-
version='1.10.1',
30+
version='1.10.3',
3131
name='testgres',
3232
packages=['testgres', 'testgres.operations', 'testgres.helpers'],
3333
description='Testing utility for PostgreSQL and its extensions',

testgres/node.py

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ def restore(self, filename, dbname=None, username=None):
11611161
filename
11621162
] # yapf: disable
11631163

1164-
# try pg_restore if dump is binary formate, and psql if not
1164+
# try pg_restore if dump is binary format, and psql if not
11651165
try:
11661166
execute_utility(_params, self.utils_log_name)
11671167
except ExecUtilException:
@@ -1304,7 +1304,7 @@ def set_synchronous_standbys(self, standbys):
13041304
13051305
Args:
13061306
standbys: either :class:`.First` or :class:`.Any` object specifying
1307-
sychronization parameters or just a plain list of
1307+
synchronization parameters or just a plain list of
13081308
:class:`.PostgresNode`s replicas which would be equivalent
13091309
to passing ``First(1, <list>)``. For PostgreSQL 9.5 and below
13101310
it is only possible to specify a plain list of standbys as
@@ -1646,23 +1646,31 @@ def set_auto_conf(self, options, config='postgresql.auto.conf', rm_options=None)
16461646

16471647
name, var = line.partition('=')[::2]
16481648
name = name.strip()
1649-
var = var.strip()
1650-
var = var.strip('"')
1651-
var = var.strip("'")
16521649

1653-
# remove options specified in rm_options list
1650+
# Remove options specified in rm_options list
16541651
if name in rm_options:
16551652
continue
16561653

16571654
current_options[name] = var
16581655

16591656
for option in options:
1660-
current_options[option] = options[option]
1657+
assert type(option) == str # noqa: E721
1658+
assert option != ""
1659+
assert option.strip() == option
1660+
1661+
value = options[option]
1662+
valueType = type(value)
1663+
1664+
if valueType == str:
1665+
value = __class__._escape_config_value(value)
1666+
elif valueType == bool:
1667+
value = "on" if value else "off"
1668+
1669+
current_options[option] = value
16611670

16621671
auto_conf = ''
16631672
for option in current_options:
1664-
auto_conf += "{0} = '{1}'\n".format(
1665-
option, current_options[option])
1673+
auto_conf += option + " = " + str(current_options[option]) + "\n"
16661674

16671675
for directive in current_directives:
16681676
auto_conf += directive + "\n"
@@ -1710,6 +1718,30 @@ def _get_bin_path(self, filename):
17101718
bin_path = get_bin_path(filename)
17111719
return bin_path
17121720

1721+
def _escape_config_value(value):
1722+
assert type(value) == str # noqa: E721
1723+
1724+
result = "'"
1725+
1726+
for ch in value:
1727+
if ch == "'":
1728+
result += "\\'"
1729+
elif ch == "\n":
1730+
result += "\\n"
1731+
elif ch == "\r":
1732+
result += "\\r"
1733+
elif ch == "\t":
1734+
result += "\\t"
1735+
elif ch == "\b":
1736+
result += "\\b"
1737+
elif ch == "\\":
1738+
result += "\\\\"
1739+
else:
1740+
result += ch
1741+
1742+
result += "'"
1743+
return result
1744+
17131745

17141746
class NodeApp:
17151747

testgres/plugins/pg_probackup2/pg_probackup2/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
7474
command = [command[0], *use_backup_dir.pb_args, *command[1:]]
7575
elif use_backup_dir:
7676
command = [command[0], *self.backup_dir.pb_args, *command[1:]]
77+
else:
78+
command = [command[0], *self.backup_dir.pb_args[2:], *command[1:]]
7779

7880
if not self.probackup_old_path and old_binary:
7981
logging.error('PGPROBACKUPBIN_OLD is not set')

testgres/plugins/pg_probackup2/pg_probackup2/gdb.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self, cmd, env, attach=False):
3737
" to run GDB tests")
3838
raise GdbException("No gdb usage possible.")
3939

40-
# Check gdb presense
40+
# Check gdb presence
4141
try:
4242
gdb_version, _ = subprocess.Popen(
4343
['gdb', '--version'],
@@ -108,6 +108,9 @@ def kill(self):
108108
self.proc.stdin.close()
109109
self.proc.stdout.close()
110110

111+
def terminate_subprocess(self):
112+
self._execute('kill')
113+
111114
def set_breakpoint(self, location):
112115

113116
result = self._execute('break ' + location)

testgres/plugins/pg_probackup2/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from distutils.core import setup
55

66
setup(
7-
version='0.0.3',
7+
version='0.0.4',
88
name='testgres_pg_probackup2',
99
packages=['pg_probackup2', 'pg_probackup2.storage'],
1010
description='Plugin for testgres that manages pg_probackup2',

tests/test_simple.py

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -501,15 +501,15 @@ def test_logical_replication(self):
501501
sub.disable()
502502
node1.safe_psql('insert into test values (3, 3)')
503503

504-
# enable and ensure that data successfully transfered
504+
# enable and ensure that data successfully transferred
505505
sub.enable()
506506
sub.catchup()
507507
res = node2.execute('select * from test')
508508
self.assertListEqual(res, [(1, 1), (2, 2), (3, 3)])
509509

510510
# Add new tables. Since we added "all tables" to publication
511511
# (default behaviour of publish() method) we don't need
512-
# to explicitely perform pub.add_tables()
512+
# to explicitly perform pub.add_tables()
513513
create_table = 'create table test2 (c char)'
514514
node1.safe_psql(create_table)
515515
node2.safe_psql(create_table)
@@ -526,7 +526,7 @@ def test_logical_replication(self):
526526
pub.drop()
527527

528528
# create new publication and subscription for specific table
529-
# (ommitting copying data as it's already done)
529+
# (omitting copying data as it's already done)
530530
pub = node1.publish('newpub', tables=['test'])
531531
sub = node2.subscribe(pub, 'newsub', copy_data=False)
532532

@@ -535,7 +535,7 @@ def test_logical_replication(self):
535535
res = node2.execute('select * from test')
536536
self.assertListEqual(res, [(1, 1), (2, 2), (3, 3), (4, 4)])
537537

538-
# explicitely add table
538+
# explicitly add table
539539
with self.assertRaises(ValueError):
540540
pub.add_tables([]) # fail
541541
pub.add_tables(['test2'])
@@ -1045,7 +1045,7 @@ def test_the_same_port(self):
10451045
node2._should_free_port = False
10461046
node2.init().start()
10471047

1048-
def test_make_simple_with_bin_dir(self):
1048+
def test_simple_with_bin_dir(self):
10491049
with get_new_node() as node:
10501050
node.init().start()
10511051
bin_dir = node.bin_dir
@@ -1063,6 +1063,52 @@ def test_make_simple_with_bin_dir(self):
10631063
except FileNotFoundError:
10641064
pass # Expected error
10651065

1066+
def test_set_auto_conf(self):
1067+
# elements contain [property id, value, storage value]
1068+
testData = [
1069+
["archive_command",
1070+
"cp '%p' \"/mnt/server/archivedir/%f\"",
1071+
"'cp \\'%p\\' \"/mnt/server/archivedir/%f\""],
1072+
["restore_command",
1073+
'cp "/mnt/server/archivedir/%f" \'%p\'',
1074+
"'cp \"/mnt/server/archivedir/%f\" \\'%p\\''"],
1075+
["log_line_prefix",
1076+
"'\n\r\t\b\\\"",
1077+
"'\\\'\\n\\r\\t\\b\\\\\""],
1078+
["log_connections",
1079+
True,
1080+
"on"],
1081+
["log_disconnections",
1082+
False,
1083+
"off"],
1084+
["autovacuum_max_workers",
1085+
3,
1086+
"3"]
1087+
]
1088+
1089+
with get_new_node() as node:
1090+
node.init().start()
1091+
1092+
options = {}
1093+
1094+
for x in testData:
1095+
options[x[0]] = x[1]
1096+
1097+
node.set_auto_conf(options)
1098+
node.stop()
1099+
node.slow_start()
1100+
1101+
auto_conf_path = f"{node.data_dir}/postgresql.auto.conf"
1102+
with open(auto_conf_path, "r") as f:
1103+
content = f.read()
1104+
1105+
for x in testData:
1106+
self.assertIn(
1107+
x[0] + " = " + x[2],
1108+
content,
1109+
x[0] + " stored wrong"
1110+
)
1111+
10661112

10671113
if __name__ == '__main__':
10681114
if os.environ.get('ALT_CONFIG'):

tests/test_simple_remote.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,15 +480,15 @@ def test_logical_replication(self):
480480
sub.disable()
481481
node1.safe_psql('insert into test values (3, 3)')
482482

483-
# enable and ensure that data successfully transfered
483+
# enable and ensure that data successfully transferred
484484
sub.enable()
485485
sub.catchup()
486486
res = node2.execute('select * from test')
487487
self.assertListEqual(res, [(1, 1), (2, 2), (3, 3)])
488488

489489
# Add new tables. Since we added "all tables" to publication
490490
# (default behaviour of publish() method) we don't need
491-
# to explicitely perform pub.add_tables()
491+
# to explicitly perform pub.add_tables()
492492
create_table = 'create table test2 (c char)'
493493
node1.safe_psql(create_table)
494494
node2.safe_psql(create_table)
@@ -505,7 +505,7 @@ def test_logical_replication(self):
505505
pub.drop()
506506

507507
# create new publication and subscription for specific table
508-
# (ommitting copying data as it's already done)
508+
# (omitting copying data as it's already done)
509509
pub = node1.publish('newpub', tables=['test'])
510510
sub = node2.subscribe(pub, 'newsub', copy_data=False)
511511

@@ -514,7 +514,7 @@ def test_logical_replication(self):
514514
res = node2.execute('select * from test')
515515
self.assertListEqual(res, [(1, 1), (2, 2), (3, 3), (4, 4)])
516516

517-
# explicitely add table
517+
# explicitly add table
518518
with self.assertRaises(ValueError):
519519
pub.add_tables([]) # fail
520520
pub.add_tables(['test2'])

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy