kiwi-scp/tests/test_service.py

67 lines
1.7 KiB
Python
Raw Normal View History

2021-10-25 10:08:04 +00:00
from pathlib import Path
2021-10-28 14:48:54 +00:00
from ruamel.yaml import CommentedMap
2021-12-02 16:08:14 +00:00
from kiwi_scp.service import Service
2021-10-25 10:08:04 +00:00
2021-10-26 14:11:28 +00:00
class TestDefault:
2021-10-28 14:48:54 +00:00
def test_empty(self):
s = Service(
2021-10-26 14:11:28 +00:00
name="s",
2021-11-03 16:35:36 +00:00
content=CommentedMap(),
2021-12-02 16:32:55 +00:00
parent=None,
2021-10-26 14:11:28 +00:00
)
assert s.name == "s"
2021-10-28 14:48:54 +00:00
assert list(s.configs) == []
2021-10-26 14:11:28 +00:00
def test_no_configs(self):
2021-10-28 14:48:54 +00:00
s = Service(
2021-10-26 14:11:28 +00:00
name="s",
2021-11-03 16:35:36 +00:00
content=CommentedMap({
2021-10-26 14:11:28 +00:00
"image": "repo/image:tag",
2021-10-28 14:48:54 +00:00
}),
2021-12-02 16:32:55 +00:00
parent=None,
2021-10-26 14:11:28 +00:00
)
assert s.name == "s"
2021-10-28 14:48:54 +00:00
assert list(s.configs) == []
2021-10-26 14:11:28 +00:00
def test_no_configs_in_volumes(self):
2021-10-28 14:48:54 +00:00
s = Service(
2021-10-26 14:11:28 +00:00
name="s",
2021-11-03 16:35:36 +00:00
content=CommentedMap({
2021-10-26 14:11:28 +00:00
"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",
]
2021-10-28 14:48:54 +00:00
}),
2021-12-02 16:32:55 +00:00
parent=None,
2021-10-26 14:11:28 +00:00
)
assert s.name == "s"
2021-10-28 14:48:54 +00:00
assert list(s.configs) == []
2021-10-26 14:11:28 +00:00
def test_with_configs(self):
2021-10-28 14:48:54 +00:00
s = Service(
2021-10-26 14:11:28 +00:00
name="s",
2021-11-03 16:35:36 +00:00
content=CommentedMap({
2021-10-26 14:11:28 +00:00
"image": "repo/image:tag",
"volumes": [
2022-01-24 16:39:55 +00:00
"${CONFIGDIR}/some/config:/path/to/some/config",
"CONFIGDIR/other/config:/path/to/other/config",
2021-10-26 14:11:28 +00:00
]
2021-10-28 14:48:54 +00:00
}),
2021-12-02 16:32:55 +00:00
parent=None,
2021-10-26 14:11:28 +00:00
)
assert s.name == "s"
2021-10-28 14:48:54 +00:00
assert len(list(s.configs)) == 2
assert list(s.configs) == [
2021-10-26 14:11:28 +00:00
Path("some/config"),
Path("other/config"),
]