Skip to content

Commit

Permalink
test ability to set default config values
Browse files Browse the repository at this point in the history
  • Loading branch information
gronke committed Apr 18, 2019
1 parent b78fb93 commit 56d1c4c
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion tests/test_Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,14 @@ def default_resource(
root_dataset: libzfs.ZFSDataset,
zfs: libzfs.ZFS,
) -> 'libioc.Resource.DefaultResource':
return libioc.Resource.DefaultResource(
default_resource = libioc.Resource.DefaultResource(
dataset=root_dataset,
logger=logger,
zfs=zfs
)
yield default_resource
if os.path.isfile(default_resource.config_handler.file):
os.remove(default_resource.config_handler.file)

def test_default_config_path(
self,
Expand Down Expand Up @@ -225,6 +228,28 @@ def test_fail_to_read_unknown_property(
default_resource.config["user.valid-property"] = "ok"
assert default_resource.config.data["user.valid-property"] == "ok"

def test_can_set_default_config(
self,
default_resource: 'libioc.Resource.DefaultResource'
) -> None:
defaults_config_path = default_resource.config_handler.file

default_resource.config.set("vnet", True);
default_resource.save()
with open(defaults_config_path, "r", encoding="UTF-8") as f:
data = json.load(f)
assert data["vnet"] == "yes"
assert len(data.keys()) == 1

default_resource.config.set("user.comment", "hi there!");
default_resource.save()
with open(defaults_config_path, "r", encoding="UTF-8") as f:
data = json.load(f)
assert "user" in data.keys()
assert "comment" in data["user"].keys()
assert data["user"]["comment"] == "hi there!"
assert len(data.keys()) == 2


class TestBrokenConfig(object):
"""Test the behavior of jails with invalid config."""
Expand Down

0 comments on commit 56d1c4c

Please sign in to comment.