pytest Project, Service

This commit is contained in:
Jörn-Michael Miehe 2021-10-25 12:08:04 +02:00
parent 3ac23e0bae
commit df55aa69d2
2 changed files with 75 additions and 17 deletions

View file

@ -1,5 +1,7 @@
from pathlib import Path
import pytest
from kiwi_scp.instance import Project
@ -7,26 +9,20 @@ def test_example():
p = Project.from_directory(Path("example/hello-world.project"))
assert p.directory == Path("example/hello-world.project")
assert len(p.services) == 5
assert p.services != []
s = p.services[0]
assert s.name == "greeter"
assert len(s.configs) == 0
s = p.services[1]
assert s.name == "web"
assert len(s.configs) == 0
def test_caching():
p = Project.from_directory(Path("example/hello-world.project"))
s = p.services[2]
assert s.name == "db"
assert len(s.configs) == 0
assert p is Project.from_directory(Path("example/hello-world.project"))
s = p.services[3]
assert s.name == "adminer"
assert len(s.configs) == 0
s = p.services[4]
assert s.name == "another-web"
assert len(s.configs) == 1
assert s.configs[0] == Path("html/index.html")
def test_no_such_dir():
nonexistent_path = Path("nonexistent")
with pytest.raises(FileNotFoundError) as exc_info:
Project.from_directory(nonexistent_path)
from kiwi_scp._constants import COMPOSE_FILE_NAME
assert exc_info.value.filename == str(nonexistent_path.joinpath(COMPOSE_FILE_NAME))

62
tests/test_service.py Normal file
View file

@ -0,0 +1,62 @@
from pathlib import Path
from kiwi_scp.instance import Service
def test_no_description():
s = Service.from_description(
name="s",
description={},
)
assert s.name == "s"
assert s.configs == []
def test_no_configs():
s = Service.from_description(
name="s",
description={
"image": "repo/image:tag",
},
)
assert s.name == "s"
assert s.configs == []
def test_no_configs_in_volumes():
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_with_configs():
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"),
]