1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-21 20:33:00 +00:00

Test classes

This commit is contained in:
Jörn-Michael Miehe 2021-10-26 16:11:28 +02:00
parent 0ecee93241
commit 8d2c1e1fac
3 changed files with 431 additions and 482 deletions

View file

@ -16,510 +16,462 @@ class UnCoercible:
raise ValueError raise ValueError
def test_default(): class TestDefault:
import toml def test(self):
import toml
c = KiwiConfig() c = KiwiConfig()
version = toml.load("./pyproject.toml")["tool"]["poetry"]["version"] version = toml.load("./pyproject.toml")["tool"]["poetry"]["version"]
assert c == KiwiConfig.from_default() assert c == KiwiConfig.from_default()
assert c.version == version assert c.version == version
assert len(c.shells) == 1 assert len(c.shells) == 1
assert c.shells[0] == Path("/bin/bash") assert c.shells[0] == Path("/bin/bash")
assert c.projects == [] assert c.projects == []
assert c.environment == {} assert c.environment == {}
assert c.storage.directory == Path("/var/local/kiwi") assert c.storage.directory == Path("/var/local/kiwi")
assert c.network.name == "kiwi_hub" assert c.network.name == "kiwi_hub"
assert c.network.cidr == IPv4Network("10.22.46.0/24") assert c.network.cidr == IPv4Network("10.22.46.0/24")
kiwi_dict = { kiwi_dict = {
"version": version, "version": version,
"shells": ["/bin/bash"], "shells": ["/bin/bash"],
"storage": {"directory": "/var/local/kiwi"}, "storage": {"directory": "/var/local/kiwi"},
"network": { "network": {
"name": "kiwi_hub", "name": "kiwi_hub",
"cidr": "10.22.46.0/24", "cidr": "10.22.46.0/24",
}, },
} }
assert c.kiwi_dict == kiwi_dict assert c.kiwi_dict == kiwi_dict
yml = ruamel.yaml.YAML() yml = ruamel.yaml.YAML()
yml.indent(offset=2) yml.indent(offset=2)
sio = io.StringIO() sio = io.StringIO()
from kiwi_scp.misc import _format_kiwi_yml from kiwi_scp.misc import _format_kiwi_yml
yml.dump(kiwi_dict, stream=sio, transform=_format_kiwi_yml) yml.dump(kiwi_dict, stream=sio, transform=_format_kiwi_yml)
yml_string = sio.getvalue() yml_string = sio.getvalue()
sio.close() sio.close()
assert c.kiwi_yml == yml_string assert c.kiwi_yml == yml_string
######### class TestVersion:
# VERSION def test_valid(self):
######### c = KiwiConfig(version="0.0.0")
assert c.version == "0.0.0"
def test_version_valid(): c = KiwiConfig(version="0.0")
c = KiwiConfig(version="0.0.0") assert c.version == "0.0"
assert c.version == "0.0.0" c = KiwiConfig(version="0")
assert c.version == "0"
c = KiwiConfig(version="0.0") c = KiwiConfig(version=1.0)
assert c.version == "1.0"
assert c.version == "0.0" c = KiwiConfig(version=1)
assert c.version == "1"
c = KiwiConfig(version="0") def test_invalid(self):
# definitely not a version
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(version="dnaf")
assert c.version == "0" assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"].find("string does not match regex") != -1
assert error["type"] == "value_error.str.regex"
c = KiwiConfig(version=1.0) # almost a version
with pytest.raises(ValidationError) as exc_info:
c = KiwiConfig(version="0.0.0alpha")
print(c.version)
assert c.version == "1.0" assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"].find("string does not match regex") != -1
assert error["type"] == "value_error.str.regex"
c = KiwiConfig(version=1)
assert c.version == "1" class TestShells:
def test_empty(self):
c = KiwiConfig(shells=None)
assert c == KiwiConfig(shells=[])
def test_version_invalid(): assert c.shells == []
# definitely not a version
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(version="dnaf")
assert len(exc_info.value.errors()) == 1 def test_list(self):
error = exc_info.value.errors()[0] c = KiwiConfig(shells=["/bin/sh", "sh"])
assert error["msg"].find("string does not match regex") != -1
assert error["type"] == "value_error.str.regex"
# barely a version assert len(c.shells) == 2
with pytest.raises(ValidationError) as exc_info: assert c.shells[0] == Path("/bin/sh")
c = KiwiConfig(version="0.0.0alpha") assert c.shells[1] == Path("sh")
print(c.version)
assert len(exc_info.value.errors()) == 1 c = KiwiConfig(shells=["/bin/bash"])
error = exc_info.value.errors()[0]
assert error["msg"].find("string does not match regex") != -1 assert len(c.shells) == 1
assert error["type"] == "value_error.str.regex" assert c.shells[0] == Path("/bin/bash")
def test_dict(self):
c = KiwiConfig(shells={"/bin/bash": None})
######## assert len(c.shells) == 1
# SHELLS assert c.shells[0] == Path("/bin/bash")
########
def test_coercible(self):
c = KiwiConfig(shells="/bin/bash")
assert c == KiwiConfig(shells=Path("/bin/bash"))
assert len(c.shells) == 1
assert c.shells[0] == Path("/bin/bash")
c = KiwiConfig(shells=123)
assert len(c.shells) == 1
assert c.shells[0] == Path("123")
def test_shells_empty(): def test_uncoercible(self):
c = KiwiConfig(shells=None) with pytest.raises(ValidationError) as exc_info:
KiwiConfig(shells=UnCoercible())
assert c == KiwiConfig(shells=[]) assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"] == "Invalid Shells Format"
assert error["type"] == "value_error"
assert c.shells == [] with pytest.raises(ValidationError) as exc_info:
KiwiConfig(shells=["/bin/bash", UnCoercible()])
assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"] == "value is not a valid path"
assert error["type"] == "type_error.path"
def test_shells_list():
c = KiwiConfig(shells=["/bin/sh", "sh"])
assert len(c.shells) == 2 class TestProject:
assert c.shells[0] == Path("/bin/sh") def test_empty(self):
assert c.shells[1] == Path("sh") c = KiwiConfig(projects=None)
c = KiwiConfig(shells=["/bin/bash"]) assert c == KiwiConfig(projects=[])
assert c.projects == []
assert len(c.shells) == 1 def test_long(self):
assert c.shells[0] == Path("/bin/bash") kiwi_dict = {
"name": "project",
"enabled": False,
"override_storage": {"directory": "/test/directory"},
}
c = KiwiConfig(projects=[kiwi_dict])
assert len(c.projects) == 1
p = c.projects[0]
assert p.name == "project"
assert not p.enabled
assert p.override_storage is not None
assert c.kiwi_dict["projects"][0] == kiwi_dict
def test_storage_str(self):
kiwi_dict = {
"name": "project",
"enabled": False,
"override_storage": "/test/directory",
}
c = KiwiConfig(projects=[kiwi_dict])
assert len(c.projects) == 1
p = c.projects[0]
assert p.name == "project"
assert not p.enabled
assert p.override_storage is not None
def test_shells_dict(): def test_storage_list(self):
c = KiwiConfig(shells={"/bin/bash": None}) kiwi_dict = {
"name": "project",
"enabled": False,
"override_storage": ["/test/directory"],
}
c = KiwiConfig(projects=[kiwi_dict])
assert len(c.shells) == 1 assert len(c.projects) == 1
assert c.shells[0] == Path("/bin/bash") p = c.projects[0]
assert p.name == "project"
assert not p.enabled
assert p.override_storage is not None
def test_storage_invalid(self):
kiwi_dict = {
"name": "project",
"enabled": False,
"override_storage": True,
}
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(projects=[kiwi_dict])
def test_shells_coercible(): assert len(exc_info.value.errors()) == 1
c = KiwiConfig(shells="/bin/bash") error = exc_info.value.errors()[0]
assert error["msg"] == "Invalid Storage Format"
assert error["type"] == "value_error"
assert c == KiwiConfig(shells=Path("/bin/bash")) def test_short(self):
kiwi_dict = {
"project": False,
}
c = KiwiConfig(projects=[kiwi_dict])
assert len(c.shells) == 1 assert len(c.projects) == 1
assert c.shells[0] == Path("/bin/bash") p = c.projects[0]
assert p.name == "project"
assert not p.enabled
assert p.override_storage is None
assert p.kiwi_dict == kiwi_dict
def test_dict(self):
c = KiwiConfig(projects={"name": "project"})
assert c == KiwiConfig(projects=[{"name": "project"}])
assert len(c.projects) == 1
p = c.projects[0]
assert p.name == "project"
assert p.enabled
assert p.override_storage is None
def test_invalid_dict(self):
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(projects={
"random key 1": "random value 1",
"random key 2": "random value 2",
})
assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"] == "Invalid Project Format"
assert error["type"] == "value_error"
def test_coercible(self):
c = KiwiConfig(projects="project")
assert c == KiwiConfig(projects=["project"])
assert len(c.projects) == 1
p = c.projects[0]
assert p.name == "project"
assert p.enabled
assert p.override_storage is None
def test_uncoercible(self):
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(projects=["valid", UnCoercible()])
assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"] == "Invalid Projects Format"
assert error["type"] == "value_error"
c = KiwiConfig(shells=123) with pytest.raises(ValidationError) as exc_info:
KiwiConfig(projects=UnCoercible())
assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"] == "Invalid Projects Format"
assert error["type"] == "value_error"
assert len(c.shells) == 1
assert c.shells[0] == Path("123")
class TestEnvironment:
def test_empty(self):
c = KiwiConfig(environment=None)
def test_shells_uncoercible(): assert c.environment == {}
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(shells=UnCoercible())
assert len(exc_info.value.errors()) == 1 def test_dict(self):
error = exc_info.value.errors()[0] c = KiwiConfig(environment={})
assert error["msg"] == "Invalid Shells Format"
assert error["type"] == "value_error"
with pytest.raises(ValidationError) as exc_info: assert c.environment == {}
KiwiConfig(shells=["/bin/bash", UnCoercible()])
assert len(exc_info.value.errors()) == 1 kiwi_dict = {"variable": "value"}
error = exc_info.value.errors()[0] c = KiwiConfig(environment=kiwi_dict)
assert error["msg"] == "value is not a valid path"
assert error["type"] == "type_error.path"
assert len(c.environment) == 1
assert "variable" in c.environment
assert c.environment["variable"] == "value"
########## assert c.kiwi_dict["environment"] == kiwi_dict
# PROJECTS
##########
def test_proj_empty(): def test_list(self):
c = KiwiConfig(projects=None) c = KiwiConfig(environment=[])
assert c == KiwiConfig(projects=[]) assert c.environment == {}
assert c.projects == [] c = KiwiConfig(environment=[
"variable=value",
])
assert len(c.environment) == 1
assert "variable" in c.environment
assert c.environment["variable"] == "value"
def test_proj_long(): c = KiwiConfig(environment=[
kiwi_dict = { "variable",
"name": "project", ])
"enabled": False,
"override_storage": {"directory": "/test/directory"},
}
c = KiwiConfig(projects=[kiwi_dict])
assert len(c.projects) == 1 assert len(c.environment) == 1
p = c.projects[0] assert "variable" in c.environment
assert p.name == "project" assert c.environment["variable"] is None
assert not p.enabled
assert p.override_storage is not None
assert c.kiwi_dict["projects"][0] == kiwi_dict c = KiwiConfig(environment=[
123,
])
assert len(c.environment) == 1
assert "123" in c.environment
assert c.environment["123"] is None
def test_proj_storage_str(): def test_coercible(self):
kiwi_dict = { c = KiwiConfig(environment="variable=value")
"name": "project",
"enabled": False,
"override_storage": "/test/directory",
}
c = KiwiConfig(projects=[kiwi_dict])
assert len(c.projects) == 1 assert len(c.environment) == 1
p = c.projects[0] assert "variable" in c.environment
assert p.name == "project" assert c.environment["variable"] == "value"
assert not p.enabled
assert p.override_storage is not None
c = KiwiConfig(environment="variable")
def test_proj_storage_list(): assert len(c.environment) == 1
kiwi_dict = { assert "variable" in c.environment
"name": "project", assert c.environment["variable"] is None
"enabled": False,
"override_storage": ["/test/directory"],
}
c = KiwiConfig(projects=[kiwi_dict])
assert len(c.projects) == 1 c = KiwiConfig(environment=123)
p = c.projects[0]
assert p.name == "project"
assert not p.enabled
assert p.override_storage is not None
assert len(c.environment) == 1
assert "123" in c.environment
assert c.environment["123"] is None
def test_proj_storage_invalid(): c = KiwiConfig(environment=123.4)
kiwi_dict = {
"name": "project",
"enabled": False,
"override_storage": True,
}
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(projects=[kiwi_dict])
assert len(exc_info.value.errors()) == 1 assert len(c.environment) == 1
error = exc_info.value.errors()[0] assert "123.4" in c.environment
assert error["msg"] == "Invalid Storage Format" assert c.environment["123.4"] is None
assert error["type"] == "value_error"
def test_uncoercible(self):
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(environment=UnCoercible())
def test_proj_short(): assert len(exc_info.value.errors()) == 1
kiwi_dict = { error = exc_info.value.errors()[0]
"project": False, assert error["msg"] == "Invalid Environment Format"
} assert error["type"] == "value_error"
c = KiwiConfig(projects=[kiwi_dict])
assert len(c.projects) == 1 with pytest.raises(ValidationError) as exc_info:
p = c.projects[0] KiwiConfig(environment=["valid", UnCoercible()])
assert p.name == "project"
assert not p.enabled
assert p.override_storage is None
assert p.kiwi_dict == kiwi_dict
assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"] == "Invalid Environment Format"
assert error["type"] == "value_error"
def test_proj_dict():
c = KiwiConfig(projects={"name": "project"})
assert c == KiwiConfig(projects=[{"name": "project"}]) class TestStorage:
def test_empty(self):
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(storage=None)
assert len(c.projects) == 1 assert len(exc_info.value.errors()) == 1
p = c.projects[0] error = exc_info.value.errors()[0]
assert p.name == "project" assert error["msg"] == "No Storage Given"
assert p.enabled assert error["type"] == "value_error"
assert p.override_storage is None
def test_dict(self):
kiwi_dict = {"directory": "/test/directory"}
c = KiwiConfig(storage=kiwi_dict)
def test_proj_invalid_dict(): assert c.storage.directory == Path("/test/directory")
with pytest.raises(ValidationError) as exc_info: assert c.storage.kiwi_dict == kiwi_dict
KiwiConfig(projects={
"random key 1": "random value 1",
"random key 2": "random value 2",
})
assert len(exc_info.value.errors()) == 1 def test_invalid_dict(self):
error = exc_info.value.errors()[0] with pytest.raises(ValidationError) as exc_info:
assert error["msg"] == "Invalid Project Format" KiwiConfig(storage={"random key": "random value"})
assert error["type"] == "value_error"
assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"] == "Invalid Storage Format"
assert error["type"] == "value_error"
def test_proj_coercible(): def test_str(self):
c = KiwiConfig(projects="project") c = KiwiConfig(storage="/test/directory")
assert c == KiwiConfig(projects=["project"]) assert c.storage.directory == Path("/test/directory")
assert len(c.projects) == 1 def test_list(self):
p = c.projects[0] c = KiwiConfig(storage=["/test/directory"])
assert p.name == "project"
assert p.enabled
assert p.override_storage is None
assert c.storage.directory == Path("/test/directory")
def test_proj_uncoercible(): def test_invalid(self):
with pytest.raises(ValidationError) as exc_info: with pytest.raises(ValidationError) as exc_info:
KiwiConfig(projects=["valid", UnCoercible()]) KiwiConfig(storage=True)
assert len(exc_info.value.errors()) == 1 assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0] error = exc_info.value.errors()[0]
assert error["msg"] == "Invalid Projects Format" assert error["msg"] == "Invalid Storage Format"
assert error["type"] == "value_error" assert error["type"] == "value_error"
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(projects=UnCoercible())
assert len(exc_info.value.errors()) == 1 class TestNetwork:
error = exc_info.value.errors()[0] def test_empty(self):
assert error["msg"] == "Invalid Projects Format" with pytest.raises(ValidationError) as exc_info:
assert error["type"] == "value_error" KiwiConfig(network=None)
assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"] == "No Network Given"
assert error["type"] == "value_error"
############# def test_dict(self):
# ENVIRONMENT kiwi_dict = {
#############
def test_env_empty():
c = KiwiConfig(environment=None)
assert c.environment == {}
def test_env_dict():
c = KiwiConfig(environment={})
assert c.environment == {}
kiwi_dict = {"variable": "value"}
c = KiwiConfig(environment=kiwi_dict)
assert len(c.environment) == 1
assert "variable" in c.environment
assert c.environment["variable"] == "value"
assert c.kiwi_dict["environment"] == kiwi_dict
def test_env_list():
c = KiwiConfig(environment=[])
assert c.environment == {}
c = KiwiConfig(environment=[
"variable=value",
])
assert len(c.environment) == 1
assert "variable" in c.environment
assert c.environment["variable"] == "value"
c = KiwiConfig(environment=[
"variable",
])
assert len(c.environment) == 1
assert "variable" in c.environment
assert c.environment["variable"] is None
c = KiwiConfig(environment=[
123,
])
assert len(c.environment) == 1
assert "123" in c.environment
assert c.environment["123"] is None
def test_env_coercible():
c = KiwiConfig(environment="variable=value")
assert len(c.environment) == 1
assert "variable" in c.environment
assert c.environment["variable"] == "value"
c = KiwiConfig(environment="variable")
assert len(c.environment) == 1
assert "variable" in c.environment
assert c.environment["variable"] is None
c = KiwiConfig(environment=123)
assert len(c.environment) == 1
assert "123" in c.environment
assert c.environment["123"] is None
c = KiwiConfig(environment=123.4)
assert len(c.environment) == 1
assert "123.4" in c.environment
assert c.environment["123.4"] is None
def test_env_uncoercible():
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(environment=UnCoercible())
assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"] == "Invalid Environment Format"
assert error["type"] == "value_error"
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(environment=["valid", UnCoercible()])
assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"] == "Invalid Environment Format"
assert error["type"] == "value_error"
#########
# STORAGE
#########
def test_storage_empty():
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(storage=None)
assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"] == "No Storage Given"
assert error["type"] == "value_error"
def test_storage_dict():
kiwi_dict = {"directory": "/test/directory"}
c = KiwiConfig(storage=kiwi_dict)
assert c.storage.directory == Path("/test/directory")
assert c.storage.kiwi_dict == kiwi_dict
def test_storage_invalid_dict():
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(storage={"random key": "random value"})
assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"] == "Invalid Storage Format"
assert error["type"] == "value_error"
def test_storage_str():
c = KiwiConfig(storage="/test/directory")
assert c.storage.directory == Path("/test/directory")
def test_storage_list():
c = KiwiConfig(storage=["/test/directory"])
assert c.storage.directory == Path("/test/directory")
def test_storage_invalid():
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(storage=True)
assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"] == "Invalid Storage Format"
assert error["type"] == "value_error"
#########
# NETWORK
#########
def test_network_empty():
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(network=None)
assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"] == "No Network Given"
assert error["type"] == "value_error"
def test_network_dict():
kiwi_dict = {
"name": "test_hub",
"cidr": "1.2.3.4/32",
}
c = KiwiConfig(network=kiwi_dict)
assert c == KiwiConfig(network={
"name": "TEST_HUB",
"cidr": "1.2.3.4/32",
})
assert c.network.name == "test_hub"
assert c.network.cidr == IPv4Network("1.2.3.4/32")
assert c.network.kiwi_dict == kiwi_dict
def test_network_invalid_dict():
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(network={"name": "test_hub"})
assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"] == "field required"
assert error["type"] == "value_error.missing"
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(network={
"name": "test_hub", "name": "test_hub",
"cidr": "1.2.3.4/123", "cidr": "1.2.3.4/32",
}
c = KiwiConfig(network=kiwi_dict)
assert c == KiwiConfig(network={
"name": "TEST_HUB",
"cidr": "1.2.3.4/32",
}) })
assert len(exc_info.value.errors()) == 1 assert c.network.name == "test_hub"
error = exc_info.value.errors()[0] assert c.network.cidr == IPv4Network("1.2.3.4/32")
assert error["msg"] == "value is not a valid IPv4 network" assert c.network.kiwi_dict == kiwi_dict
assert error["type"] == "value_error.ipv4network"
def test_invalid_dict(self):
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(network={"name": "test_hub"})
def test_network_invalid(): assert len(exc_info.value.errors()) == 1
with pytest.raises(ValidationError) as exc_info: error = exc_info.value.errors()[0]
KiwiConfig(network=True) assert error["msg"] == "field required"
assert error["type"] == "value_error.missing"
assert len(exc_info.value.errors()) == 1 with pytest.raises(ValidationError) as exc_info:
error = exc_info.value.errors()[0] KiwiConfig(network={
assert error["msg"] == "Invalid Network Format" "name": "test_hub",
assert error["type"] == "value_error" "cidr": "1.2.3.4/123",
})
assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"] == "value is not a valid IPv4 network"
assert error["type"] == "value_error.ipv4network"
def test_invalid(self):
with pytest.raises(ValidationError) as exc_info:
KiwiConfig(network=True)
assert len(exc_info.value.errors()) == 1
error = exc_info.value.errors()[0]
assert error["msg"] == "Invalid Network Format"
assert error["type"] == "value_error"

View file

@ -3,28 +3,27 @@ from pathlib import Path
from kiwi_scp.instance import Instance from kiwi_scp.instance import Instance
def test_example(): class TestDefault:
i = Instance(Path("example")) def test_example(self):
i = Instance(Path("example"))
assert i.config is not None assert i.config is not None
assert len(i.config.projects) == 1 assert len(i.config.projects) == 1
p = i.config.projects[0] p = i.config.projects[0]
assert p.name == "hello-world.project" assert p.name == "hello-world.project"
def test_empty(self):
i = Instance()
def test_empty(): assert i.config is not None
i = Instance() assert len(i.config.projects) == 0
assert i.config is not None def test_no_such_dir(self):
assert len(i.config.projects) == 0 nonexistent_path = Path("nonexistent")
i = Instance(nonexistent_path)
assert i.directory == nonexistent_path
def test_no_such_dir(): assert i.config is not None
nonexistent_path = Path("nonexistent") assert len(i.config.projects) == 0
i = Instance(nonexistent_path)
assert i.directory == nonexistent_path
assert i.config is not None
assert len(i.config.projects) == 0

View file

@ -3,60 +3,58 @@ from pathlib import Path
from kiwi_scp.instance import Service from kiwi_scp.instance import Service
def test_no_description(): class TestDefault:
s = Service.from_description( def test_no_description(self):
name="s", s = Service.from_description(
description={}, name="s",
) description={},
)
assert s.name == "s" assert s.name == "s"
assert s.configs == [] assert s.configs == []
def test_no_configs(self):
s = Service.from_description(
name="s",
description={
"image": "repo/image:tag",
},
)
def test_no_configs(): assert s.name == "s"
s = Service.from_description( assert s.configs == []
name="s",
description={
"image": "repo/image:tag",
},
)
assert s.name == "s" def test_no_configs_in_volumes(self):
assert s.configs == [] s = Service.from_description(
name="s",
description={
"image": "repo/image:tag",
"volumes": [
"docker_volume/third/dir:/path/to/third/mountpoint",
"${TARGETDIR}/some/dir:/path/to/some/mountpoint",
"$TARGETDIR/other/dir:/path/to/other/mountpoint",
]
},
)
assert s.name == "s"
assert s.configs == []
def test_no_configs_in_volumes(): def test_with_configs(self):
s = Service.from_description( s = Service.from_description(
name="s", name="s",
description={ description={
"image": "repo/image:tag", "image": "repo/image:tag",
"volumes": [ "volumes": [
"docker_volume/third/dir:/path/to/third/mountpoint", "${CONFDIR}/some/config:/path/to/some/config",
"${TARGETDIR}/some/dir:/path/to/some/mountpoint", "$CONFDIR/other/config:/path/to/other/config",
"$TARGETDIR/other/dir:/path/to/other/mountpoint", ]
] },
}, )
)
assert s.name == "s" assert s.name == "s"
assert s.configs == [] assert len(s.configs) == 2
assert s.configs == [
Path("some/config"),
def test_with_configs(): Path("other/config"),
s = Service.from_description( ]
name="s",
description={
"image": "repo/image:tag",
"volumes": [
"${CONFDIR}/some/config:/path/to/some/config",
"$CONFDIR/other/config:/path/to/other/config",
]
},
)
assert s.name == "s"
assert len(s.configs) == 2
assert s.configs == [
Path("some/config"),
Path("other/config"),
]