"""Test Document Execution. No container is started here. The host is stood in for, so what is checked is the command that would run, the key it is cached under, and what a reader would be shown of what it wrote.""" #################################################################################################################################### import os import tempfile from harness.test import * import command.render.execute as execute_module from common.error import * from common.storage import file_read, file_write from common.var_store import VarStore from common.xml import xml_node_child, xml_node_child_list, xml_node_normalize, xml_parse from command.render.execute import CacheInvalidError, DocExecute, doc_user # What a stood-in host was asked to do, and what it should write when it is asked HOST_LIST = [] RESULT = {} #################################################################################################################################### class _Host: """Stands in for a host the documentation runs commands on.""" def __init__(self, name, container, image, user, mount_list=None, option=None, param=None, host_update=True): self.name = name self.image = image self.ip = "172.17.0.9" HOST_LIST.append(("add", name, image, mount_list, option, param)) def execute(self, command, **kwargs): HOST_LIST.append(("execute", command, kwargs)) return 0, RESULT.get("output", ""), RESULT.get("error", "") def copy_to(self, source, destination, owner=None, mode=None): HOST_LIST.append(("copy_to", source, destination, owner, mode)) def copy_from(self, source, destination): HOST_LIST.append(("copy_from", source, destination)) file_write(destination, RESULT.get("pg_config", "shared_buffers = 128MB\n")) #################################################################################################################################### class _Group: """Stands in for the hosts of a build.""" def host_add(self, host): HOST_LIST.append(("group", host.name)) #################################################################################################################################### class _Manifest: """Stands in for the documentation as a whole.""" def __init__(self, path_doc, cache_only=False, pre=False): self.path_doc = path_doc self.cache_only = cache_only self.pre = pre self.var_store = VarStore() self.require_list = [] self.source_map = {} self.page_anchor_map = {} self.link_list = [] def evaluate_if(self, node): return True def source_get(self, key): return self.source_map[key] def render_out_get(self, type, key): return _Out() if key == "user-guide" else None #################################################################################################################################### class _Out: """Stands in for a page of the documentation.""" def __init__(self): self.source = "user-guide" self.file = None self.menu = None #################################################################################################################################### class _Source: """Stands in for a document of the documentation.""" def __init__(self, root): self.root = root self.cache_list = None #################################################################################################################################### def _doc(content): """Parse a document the way the tool reads one.""" result = xml_parse(content, "test.xml") xml_node_normalize(result) return result #################################################################################################################################### def _execute(path, document=None, exe=True, cache_only=False, pre=False, cache_list=None): """Build a renderer for a document, with the host stood in for.""" HOST_LIST.clear() RESULT.clear() execute_module.Host = _Host execute_module.HOST_GROUP = _Group() manifest = _Manifest(path, cache_only, pre) root = _doc( """
One Setup ls -l
""" if document is None else document ) source = _Source(root) source.cache_list = cache_list manifest.source_map["user-guide"] = source return DocExecute("html", manifest, "user-guide", exe) #################################################################################################################################### def test_doc_user(): """A command runs as the user building the documentation unless it says otherwise.""" from common.user import user_name assert_equal(doc_user(), "ubuntu" if user_name() == "root" else user_name()) #################################################################################################################################### def test_execute_key(): """The key is everything that decides what a command would be, which is what makes the cache trustworthy.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) command = xml_node_child(xml_node_child(render.section_map["/one"], "execute-list"), "execute") assert_equal( render.execute_key("repo", command), {"host": "repo", "cmd": ["ls -l"], "output": False, "run-as-user": None, "load-env": True, "bash-wrap": True}, ) #################################################################################################################################### def test_execute_key_user(): """A command that names a user is reached with sudo unless it is showing what running as that user looks like.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) key = render.execute_key("repo", _doc('psql')) assert_equal(key["cmd"], ["sudo -u postgres psql"]) assert_is_none(key["run-as-user"]) assert_equal(render.execute_key("repo", _doc('id'))["cmd"], ["sudo id"]) # A command that is showing what running as a user looks like runs as that user rather than reaching it with sudo key = render.execute_key("repo", _doc('psql')) assert_equal(key["cmd"], ["psql"]) assert_equal(key["run-as-user"], "postgres") #################################################################################################################################### def test_execute_key_split(): """A command written over more than one line is shown that way, with a backslash where it breaks.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) key = render.execute_key("repo", _doc("pgbackrest backup\n --stanza=demo")) assert_equal(key["cmd"], ["pgbackrest backup \\", " --stanza=demo"]) #################################################################################################################################### def test_execute_key_output(): """Output is kept when the documentation shows it or takes a variable from it.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) assert_false(render.execute_key("repo", _doc("ls"))["output"]) assert_true(render.execute_key("repo", _doc('ls'))["output"]) assert_true(render.execute_key("repo", _doc('ls'))["output"]) assert_true(render.execute_key("repo", _doc('ls'))["output"]) # Everything else a command says about how it runs is part of the key as well key = render.execute_key( "repo", _doc( '' "ls-lerror" ), ) assert_equal(key["err-expect"], "1") assert_equal(key["cmd-extra"], "-l") assert_false(key["load-env"]) assert_false(key["bash-wrap"]) assert_true(key["output"]) assert_equal(key["highlight"], {"filter": False, "filter-context": 2, "list": ["error"]}) #################################################################################################################################### def test_execute(): """A command runs on the host and what it wrote is what a reader is shown.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) section = render.section_map["/one"] command = xml_node_child(xml_node_child(section, "execute-list"), "execute") render.host_map["repo"] = _Host("repo", "doc-repo", "image:1", "vagrant") RESULT["output"] = "one\ntwo\n" cmd, output = render.execute(section, "repo", command) assert_equal(cmd, "ls -l") # Output is only kept when the documentation is showing it assert_is_none(output) assert_equal(HOST_LIST[-1][1], "ls -l") # The command is cached so the documentation can be rendered again without running it assert_equal(render.source.cache_list[-1]["type"], "exe") #################################################################################################################################### def test_execute_output(): """A command whose output is shown has it kept, and a variable can be taken from it.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) section = render.section_map["/one"] render.host_map["repo"] = _Host("repo", "doc-repo", "image:1", "vagrant") RESULT["output"] = "\nversion 2.60\n" cmd, output = render.execute(section, "repo", _doc('ls')) assert_equal(output, "version 2.60") # Blank lines at the end are how the output ends rather than part of it, but a run of them is not all dropped RESULT["output"] = "a\n\n\n" assert_equal(render.execute(section, "repo", _doc('ls'))[1], "a\n") assert_equal(render.manifest.var_store.get("ver"), "version 2.60") # A command that is expected to fail is showing the error, so the error is part of what it wrote RESULT["output"] = "out" RESULT["error"] = "bad thing" _, output = render.execute(section, "repo", _doc('ls')) assert_equal(output, "outbad thing") #################################################################################################################################### def test_execute_no_exe(): """A build that does not run the commands still says what they are and shows something in place of what they wrote.""" with tempfile.TemporaryDirectory() as path: render = _execute(path, exe=False) section = render.section_map["/one"] cmd, output = render.execute(section, "repo", _doc('ls')) assert_equal(cmd, "ls") assert_equal(output, "Output suppressed for testing") # A command whose output the documentation does not show has nothing to show in place of it either assert_is_none(render.execute(section, "repo", _doc("ls"))[1]) # A host is not started either, since there is nothing to run on it render.section_child_process(section, _doc(''), 1) assert_equal(HOST_LIST, []) # A variable the documentation takes from a command still has to have a value render.execute(section, "repo", _doc('ls')) assert_equal(render.manifest.var_store.get("ver"), "[Test Variable]") #################################################################################################################################### def test_execute_error(): """A command that cannot be shown or cannot be run is reported rather than rendered.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) section = render.section_map["/one"] # A line that is too wide to read is an error, since the documentation is showing it to be read with assert_raises(ToolError) as raised: render.execute(section, "repo", _doc("%s" % ("x" * 100))) assert_in("command has a line > 80 characters", str(raised.exception)) # A command may raise the limit for itself when it holds something that cannot be broken render.host_map["repo"] = _Host("repo", "doc-repo", "image:1", "vagrant") render.execute(section, "repo", _doc('%s' % ("x" * 100))) # A command that is not shown is never read, so how wide it is does not matter render.execute(section, "repo", _doc('%s' % ("x" * 100))) # A command against a host that was never started with assert_raises(ToolError) as raised: render.execute(section, "missing", _doc("ls")) assert_equal(str(raised.exception), "cannot execute on host missing because the host does not exist") #################################################################################################################################### def test_execute_skip(): """A command that is skipped is shown but not run, which is how a command that ran while the image was built is handled.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) section = render.section_map["/one"] cmd, output = render.execute(section, "repo", _doc('ls')) assert_equal(cmd, "ls") assert_is_none(output) assert_equal(HOST_LIST, []) #################################################################################################################################### def test_output_filter(): """A command can write a great deal and the documentation is showing one thing in it.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) section = render.section_map["/one"] render.host_map["repo"] = _Host("repo", "doc-repo", "image:1", "vagrant") RESULT["output"] = ( "\n".join("line %d" % idx for idx in range(20)) + "\nmatch\n" + "\n".join("tail %d" % idx for idx in range(20)) ) _, output = render.execute( section, "repo", _doc('lsmatch'), ) # What is kept is the lines that match with a little either side, and how many were dropped is said assert_in("[filtered 18 lines of output]", output) assert_in("line 18\nline 19\nmatch\ntail 0\ntail 1", output) assert_in("[filtered 17 lines of output]", output.split("tail 1")[1]) #################################################################################################################################### def test_output_filter_edge(): """One dropped line takes as much room to say as to show, so it is shown.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) section = render.section_map["/one"] render.host_map["repo"] = _Host("repo", "doc-repo", "image:1", "vagrant") RESULT["output"] = "a\nb\nc\nmatch\nd\ne\nf" _, output = render.execute( section, "repo", _doc('lsmatch'), ) assert_equal(output, "a\nb\nc\nmatch\nd\ne") # A match at the very start, with nothing before it to drop RESULT["output"] = "match\na\nb" _, output = render.execute( section, "repo", _doc('lsmatch'), ) assert_equal(output, "match\na\nb") #################################################################################################################################### def test_cache(): """The cache is replayed in the order the commands were run, and a key that does not match means it is out of date.""" with tempfile.TemporaryDirectory() as path: cache_list = [ { "key": { "host": "repo", "cmd": ["ls -l"], "output": False, "run-as-user": None, "load-env": True, "bash-wrap": True, }, "type": "exe", "value": {"output": ["one"]}, } ] render = _execute(path, cache_list=cache_list) section = render.section_map["/one"] command = xml_node_child(xml_node_child(section, "execute-list"), "execute") cmd, output = render.execute(section, "repo", command) # Nothing was run, since what the command wrote is already known assert_equal(HOST_LIST, []) assert_equal(output, "one") # A cache that has run out no longer describes the document with assert_raises(CacheInvalidError) as raised: render.execute(section, "repo", command) assert_equal(str(raised.exception), "unable to get index from cache") #################################################################################################################################### def test_cache_invalid(): """A cache entry that does not describe what is about to happen means the whole document has to be built again.""" with tempfile.TemporaryDirectory() as path: section_of = lambda render: render.section_map["/one"] render = _execute(path, cache_list=[{"key": {"host": "other"}, "type": "exe"}]) command = xml_node_child(xml_node_child(section_of(render), "execute-list"), "execute") with assert_raises(CacheInvalidError) as raised: render.execute(section_of(render), "repo", command) assert_in("keys at index 0 do not match", str(raised.exception)) render = _execute(path, cache_list=[{"key": {}, "type": "host"}]) with assert_raises(CacheInvalidError) as raised: render.execute(section_of(render), "repo", command) assert_equal(str(raised.exception), "types do not match, cache is invalid") render = _execute(path, cache_list=[{"type": "exe"}]) with assert_raises(CacheInvalidError) as raised: render.execute(section_of(render), "repo", command) assert_equal(str(raised.exception), "unable to get key or type from cache") #################################################################################################################################### def test_cache_only(): """A build that was told to use the cache and nothing else cannot run a command that is not in it.""" with tempfile.TemporaryDirectory() as path: render = _execute(path, cache_only=True) section = render.section_map["/one"] with assert_raises(ToolError) as raised: render.execute(section, "repo", xml_node_child(xml_node_child(section, "execute-list"), "execute")) assert_equal(str(raised.exception), "cache only operation forced by --cache-only option") #################################################################################################################################### def test_cache_push(): """A build that is replaying the cache has nothing to add to it.""" with tempfile.TemporaryDirectory() as path: render = _execute(path, cache_list=[]) with assert_raises(ToolError) as raised: render.cache_push("exe", {}, None) assert_equal(str(raised.exception), "cache push should not be called when the cache is already present") #################################################################################################################################### def test_backrest_config(): """A configuration file is built up across a document, so a section shows the file with everything added so far and says what it changed, and a section that changes nothing has nothing to show.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) section = render.section_map["/one"] render.host_map["repo"] = _Host("repo", "doc-repo", "image:1", "vagrant") config = _doc( """Configure /var/lib/pgbackrest installed off /pg1 /pg2 """ ) file, content, show = render.backrest_config(section, config, 1) assert_equal(file, "/etc/pgbackrest.conf") assert_true(show) # What a reader sees leaves out the options that are only there so the build can watch what happens, and a file the document # has not shown before is all new assert_equal( content, [ ("add", "[global]"), ("add", "pg1-path=/pg1"), ("add", "pg1-path=/pg2"), ("add", "repo1-cipher-pass=shown"), ("add", "repo1-path=/var/lib/pgbackrest"), ], ) # The file that is installed on the host has everything in it and the installed values installed = file_read(os.path.join(path, "output/pgbackrest.conf")) assert_in("log-level-stderr=off", installed) assert_in("repo1-cipher-pass=installed", installed) # A later section adds to what is already there and only what it added is marked config = _doc( """More /pg """ ) _, content, _ = render.backrest_config(section, config, 1) assert_equal( content, [ ("add", "[demo]"), ("add", "pg1-path=/pg"), ("add", ""), ("same", "[global]"), ("same", "pg1-path=/pg1"), ("same", "pg1-path=/pg2"), ("same", "repo1-cipher-pass=shown"), ("same", "repo1-path=/var/lib/pgbackrest"), ], ) # A file on another host is compared against that host rather than against the file of the same name on this one render.host_map["repo2"] = _Host("repo2", "doc-repo2", "image:1", "vagrant") _, content, _ = render.backrest_config( section, _doc( """Other /pg """ ), 1, ) assert_equal(content, [("add", "[demo]"), ("add", "pg1-path=/pg")]) # A change that is shown but leaves the file as the reader last saw it gives the reader a file to read and nothing in it to # find, so it is an error with assert_raises(ToolError) as raised: render.backrest_config( section, _doc( """Again /pg """ ), 1, ) assert_equal( str(raised.exception), "config repo2:/etc/pgbackrest.conf in section /one is shown but changes nothing since it was last shown", ) #################################################################################################################################### def test_backrest_config_remove(): """An option that is removed leaves nothing behind for a later section to show, and a change that was not shown is marked on the next change that is.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) section = render.section_map["/one"] render.host_map["repo"] = _Host("repo", "doc-repo", "image:1", "vagrant") render.backrest_config( section, _doc( """C /var/lib """ ), 1, ) _, content, show = render.backrest_config( section, _doc( """C """ ), 1, ) # A file with nothing left in it is all of what it held marked as gone assert_equal(content, [("remove", "[global]"), ("remove", "repo1-path=/var/lib")]) assert_false(show) # A change the reader was not shown is left for the next change that is shown, so the option that was removed is marked here # rather than in the section that removed it _, content, show = render.backrest_config( section, _doc( """C /other """ ), 1, ) assert_true(show) assert_equal(content, [("same", "[global]"), ("remove", "repo1-path=/var/lib"), ("add", "repo1-path=/other")]) # A configuration against a host that was never started with assert_raises(ToolError) as raised: render.backrest_config( section, _doc('C'), 1 ) assert_equal(str(raised.exception), "cannot configure backrest on host missing because the host does not exist") #################################################################################################################################### def test_postgres_config(): """The PostgreSQL configuration is what the documentation added rather than the whole file.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) section = render.section_map["/one"] render.host_map["repo"] = _Host("repo", "doc-repo", "image:1", "vagrant") config = _doc( """Configure pgbackrest archive-push %p on """ ) file, content, show = render.postgres_config(section, config, 1) assert_equal(file, "/pg/postgresql.conf") assert_true(show) assert_equal(content, [("add", "archive_command = pgbackrest archive-push %p"), ("add", "archive_mode = on")]) # The file installed on the host is what was there plus what the documentation added assert_in("shared_buffers = 128MB", file_read(os.path.join(path, "output/postgresql.conf"))) assert_in("# pgBackRest Configuration", file_read(os.path.join(path, "output/postgresql.conf"))) # An option that is changed is marked as gone and added back rather than as a line that is somehow both _, content, _ = render.postgres_config( section, _doc( """C off """ ), 1, ) assert_equal( content, [ ("same", "archive_command = pgbackrest archive-push %p"), ("remove", "archive_mode = on"), ("add", "archive_mode = off"), ], ) # An option that is reset leaves nothing behind _, content, _ = render.postgres_config( section, _doc( """C """ ), 1, ) assert_equal( content, [("remove", "archive_command = pgbackrest archive-push %p"), ("remove", "archive_mode = off")], ) with assert_raises(ToolError) as raised: render.postgres_config( section, _doc('C'), 1 ) assert_equal(str(raised.exception), "cannot configure postgres on host missing because the host does not exist") #################################################################################################################################### def test_config_no_exe(): """A build that does not run the commands shows something in place of the configuration as well.""" with tempfile.TemporaryDirectory() as path: render = _execute(path, exe=False) section = render.section_map["/one"] _, content, _ = render.backrest_config( section, _doc('C'), 1 ) assert_equal(content, [("same", "Config suppressed for testing")]) _, content, _ = render.postgres_config( section, _doc('C'), 1 ) assert_equal(content, [("same", "Config suppressed for testing")]) #################################################################################################################################### def test_config_key(): """The key is everything that decides what a configuration change would be.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) key = render.config_key( _doc( """C 1 3 """ ) ) assert_equal(key["host"], "repo") assert_true(key["reset"]) assert_equal( key["option"], {"global": {"a": {"value": "1"}, "b": {"remove": True}, "c": {"value": "3", "display": "shown"}}} ) # A PostgreSQL option has no section of its own, since the file has none key = render.config_key( _doc( '' '1' ) ) assert_equal(key["option"], {"a": {"value": "1"}}) #################################################################################################################################### def test_host_key(): """The key is everything that decides what a host would be.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) assert_equal( render.host_key(_doc('')), {"name": "repo", "image": "image:1", "id": "repo", "update-hosts": True}, ) key = render.host_key( _doc('') ) assert_equal(key["id"], "r") assert_equal(key["option"], "-m 1g") assert_equal(key["param"], "run") assert_equal(key["os"], "u24") assert_false(key["update-hosts"]) #################################################################################################################################### def test_host_add(): """A host is started, told about the others, and set up by the commands the documentation gives it.""" document = """
One echo setup
""" with tempfile.TemporaryDirectory() as path: os.environ["HOME"] = path render = _execute(os.path.join(path, "doc"), document) section = render.section_map["/one"] render.section_child_process(section, xml_node_child(section, "host-add"), 1) # The repository is mounted from where it is on the host running the build assert_equal(HOST_LIST[0][0], "add") assert_equal(HOST_LIST[0][3], [os.path.join(path, "x:/x")]) assert_equal(HOST_LIST[0][4], "-v %s:/repo" % path) assert_equal(HOST_LIST[1], ("group", "repo")) assert_equal(HOST_LIST[2][1], "echo setup") # The address of the host is a variable the documentation can use assert_equal(render.manifest.var_store.get("host-repo-ip"), "172.17.0.9") # A host that is already up cannot be started again with assert_raises(ToolError) as raised: render.section_child_process(section, xml_node_child(section, "host-add"), 1) assert_equal(str(raised.exception), "cannot add host repo because the host already exists") #################################################################################################################################### def test_host_add_cache(): """A host that is replayed from the cache is not started, since the address it had is what the documentation showed.""" document = '
One
' with tempfile.TemporaryDirectory() as path: cache_list = [ { "key": {"name": "repo", "image": "image:1", "id": "repo", "update-hosts": True}, "type": "host", "value": {"ip": "172.17.0.5"}, } ] render = _execute(path, document, cache_list=cache_list) section = render.section_map["/one"] render.section_child_process(section, xml_node_child(section, "host-add"), 1) assert_equal(HOST_LIST, []) assert_equal(render.manifest.var_store.get("host-repo-ip"), "172.17.0.5") # A title is the only other thing a section holds that every renderer handles the same way render.section_child_process(section, xml_node_child(section, "title"), 1) with assert_raises(ToolError) as raised: render.section_child_process(section, _doc(""), 1) assert_equal(str(raised.exception), "unable to process child type unknown") #################################################################################################################################### def test_host_add_pre(): """Commands marked pre are run while the image is built, so a rebuild of the documentation does not run them again.""" document = """
One Setup apt-get update true
""" build_list = [] def _exec_result(command, **kwargs): build_list.append(command) return 0, "", "" exec_result_real = execute_module.exec_result execute_module.exec_result = _exec_result try: with tempfile.TemporaryDirectory() as path: os.environ["HOME"] = path render = _execute(os.path.join(path, "doc"), document, pre=True) section = render.section_map["/one"] render.section_child_process(section, xml_node_child(section, "host-add"), 1) # The image the host starts from is the one the pre commands were run into assert_equal(HOST_LIST[0][2], "pgbackrest/doc:u24-repo") script = file_read(os.path.join(path, "doc/output/doc-host.dockerfile")) assert_in("FROM pgbackrest/doc:u24", script) assert_in("RUN sudo -u vagrant bash -l -c 'apt-get update'", script) assert_in("RUN sudo -u vagrant true", script) assert_in("docker build -f", build_list[-1]) finally: execute_module.exec_result = exec_result_real #################################################################################################################################### def test_config_cache(): """A configuration that is replayed from the cache is not applied, since the file it left behind is already known.""" with tempfile.TemporaryDirectory() as path: cache_list = [ {"key": {"host": "repo", "file": "/etc/x", "option": {}}, "type": "cfg-pgbackrest", "value": {"config": ["[global]"]}}, {"key": {"host": "repo", "file": "/pg/x", "option": {}}, "type": "cfg-postgresql", "value": {"config": None}}, ] render = _execute(path, cache_list=cache_list) section = render.section_map["/one"] _, content, _ = render.backrest_config( section, _doc('C'), 1 ) assert_equal(content, [("add", "[global]")]) # A change that is not shown is not compared against anything the reader has seen, so a file with nothing in it is not an # error the way it would be if the reader were being shown it _, content, _ = render.postgres_config( section, _doc('C'), 1 ) assert_equal(content, []) assert_equal(HOST_LIST, []) #################################################################################################################################### def test_backrest_config_reset(): """A configuration that is reset starts from nothing rather than from what an earlier section left, so what is shown of it is all new rather than mostly gone.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) section = render.section_map["/one"] render.host_map["repo"] = _Host("repo", "doc-repo", "image:1", "vagrant") render.backrest_config( section, _doc( """C /var/lib /pg """ ), 1, ) _, content, _ = render.backrest_config( section, _doc( """C /other """ ), 1, ) assert_equal(content, [("add", "[global]"), ("add", "repo1-path=/other")]) #################################################################################################################################### def test_backrest_config_hidden(): """A file that holds nothing but the options the build watches with has nothing for a reader to see, so showing it is an error.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) section = render.section_map["/one"] render.host_map["repo"] = _Host("repo", "doc-repo", "image:1", "vagrant") with assert_raises(ToolError) as raised: render.backrest_config( section, _doc( """C off n """ ), 1, ) assert_equal( str(raised.exception), "config repo:/etc/pgbackrest.conf in section /one is shown but changes nothing since it was last shown", ) #################################################################################################################################### def test_backrest_config_remove_one(): """An option that is removed leaves the rest of its section behind.""" with tempfile.TemporaryDirectory() as path: render = _execute(path) section = render.section_map["/one"] render.host_map["repo"] = _Host("repo", "doc-repo", "image:1", "vagrant") render.backrest_config( section, _doc( """C 1 2 """ ), 1, ) _, content, _ = render.backrest_config( section, _doc( """C """ ), 1, ) assert_equal(content, [("same", "[global]"), ("remove", "a=1"), ("same", "b=2")])