mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-11-24 13:43:01 +00:00
pytest Project, Service
This commit is contained in:
parent
3ac23e0bae
commit
df55aa69d2
2 changed files with 75 additions and 17 deletions
|
@ -1,5 +1,7 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from kiwi_scp.instance import Project
|
from kiwi_scp.instance import Project
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,26 +9,20 @@ def test_example():
|
||||||
p = Project.from_directory(Path("example/hello-world.project"))
|
p = Project.from_directory(Path("example/hello-world.project"))
|
||||||
|
|
||||||
assert p.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]
|
def test_caching():
|
||||||
assert s.name == "web"
|
p = Project.from_directory(Path("example/hello-world.project"))
|
||||||
assert len(s.configs) == 0
|
|
||||||
|
|
||||||
s = p.services[2]
|
assert p is Project.from_directory(Path("example/hello-world.project"))
|
||||||
assert s.name == "db"
|
|
||||||
assert len(s.configs) == 0
|
|
||||||
|
|
||||||
s = p.services[3]
|
|
||||||
assert s.name == "adminer"
|
|
||||||
assert len(s.configs) == 0
|
|
||||||
|
|
||||||
s = p.services[4]
|
def test_no_such_dir():
|
||||||
assert s.name == "another-web"
|
nonexistent_path = Path("nonexistent")
|
||||||
assert len(s.configs) == 1
|
|
||||||
assert s.configs[0] == Path("html/index.html")
|
|
||||||
|
|
||||||
|
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
62
tests/test_service.py
Normal 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"),
|
||||||
|
]
|
Loading…
Reference in a new issue