mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Call initdb directly (#2633)
Previously it was called via `pg_ctl`, what required a special quoting of parameters passed to `initdb`. Co-authored-by: Israel <[email protected]>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from mock import Mock, PropertyMock, patch
|
||||
|
||||
@@ -99,6 +100,48 @@ class TestBootstrap(BaseTestPostgresql):
|
||||
self.assertRaises(Exception, self.b.bootstrap, {'initdb': [1]})
|
||||
self.assertRaises(Exception, self.b.bootstrap, {'initdb': 1})
|
||||
|
||||
def test__process_user_options(self):
|
||||
def error_handler(msg):
|
||||
raise Exception(msg)
|
||||
|
||||
self.assertEqual(self.b.process_user_options('initdb', ['string'], (), error_handler), ['--string'])
|
||||
self.assertEqual(
|
||||
self.b.process_user_options(
|
||||
'initdb',
|
||||
[{'key': 'value'}],
|
||||
(), error_handler
|
||||
),
|
||||
['--key=value'])
|
||||
if sys.platform != 'win32':
|
||||
self.assertEqual(
|
||||
self.b.process_user_options(
|
||||
'initdb',
|
||||
[{'key': 'value with spaces'}],
|
||||
(), error_handler
|
||||
),
|
||||
["--key=value with spaces"])
|
||||
self.assertEqual(
|
||||
self.b.process_user_options(
|
||||
'initdb',
|
||||
[{'key': "'value with spaces'"}],
|
||||
(), error_handler
|
||||
),
|
||||
["--key=value with spaces"])
|
||||
self.assertEqual(
|
||||
self.b.process_user_options(
|
||||
'initdb',
|
||||
{'key': 'value with spaces'},
|
||||
(), error_handler
|
||||
),
|
||||
["--key=value with spaces"])
|
||||
self.assertEqual(
|
||||
self.b.process_user_options(
|
||||
'initdb',
|
||||
{'key': "'value with spaces'"},
|
||||
(), error_handler
|
||||
),
|
||||
["--key=value with spaces"])
|
||||
|
||||
@patch.object(CancellableSubprocess, 'call', Mock())
|
||||
@patch.object(Postgresql, 'is_running', Mock(return_value=True))
|
||||
@patch.object(Postgresql, 'data_directory_empty', Mock(return_value=False))
|
||||
|
||||
+27
-1
@@ -1,8 +1,9 @@
|
||||
import unittest
|
||||
|
||||
from mock import Mock, patch
|
||||
|
||||
from patroni.exceptions import PatroniException
|
||||
from patroni.utils import Retry, RetryFailedError, enable_keepalive, polling_loop, validate_directory
|
||||
from patroni.utils import Retry, RetryFailedError, enable_keepalive, polling_loop, validate_directory, unquote
|
||||
|
||||
|
||||
class TestUtils(unittest.TestCase):
|
||||
@@ -41,6 +42,31 @@ class TestUtils(unittest.TestCase):
|
||||
with patch('sys.platform', platform):
|
||||
self.assertIsNone(enable_keepalive(Mock(), 10, 5))
|
||||
|
||||
def test_unquote(self):
|
||||
self.assertEqual(unquote('value'), 'value')
|
||||
self.assertEqual(unquote('value with spaces'), "value with spaces")
|
||||
self.assertEqual(unquote(
|
||||
'"double quoted value"'),
|
||||
'double quoted value')
|
||||
self.assertEqual(unquote(
|
||||
'\'single quoted value\''),
|
||||
'single quoted value')
|
||||
self.assertEqual(unquote(
|
||||
'value "with" double quotes'),
|
||||
'value "with" double quotes')
|
||||
self.assertEqual(unquote(
|
||||
'"value starting with" double quotes'),
|
||||
'"value starting with" double quotes')
|
||||
self.assertEqual(unquote(
|
||||
'\'value starting with\' single quotes'),
|
||||
'\'value starting with\' single quotes')
|
||||
self.assertEqual(unquote(
|
||||
'value with a \' single quote'),
|
||||
'value with a \' single quote')
|
||||
self.assertEqual(unquote(
|
||||
'\'value with a \'"\'"\' single quote\''),
|
||||
'value with a \' single quote')
|
||||
|
||||
|
||||
@patch('time.sleep', Mock())
|
||||
class TestRetrySleeper(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user