kiwi-scp/tests/test_service.py

67 lines
1.7 KiB
Python
Raw Permalink 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(),
2022-01-27 14:26:10 +00:00
parent_project=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
}),
2022-01-27 14:26:10 +00:00
parent_project=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",
2022-02-22 13:45:24 +00:00
"${KIWI_PROJECT}/some/dir:/path/to/some/mountpoint",
"$KIWI_PROJECT/other/dir:/path/to/other/mountpoint",
2021-10-26 14:11:28 +00:00
]
2021-10-28 14:48:54 +00:00
}),
2022-01-27 14:26:10 +00:00
parent_project=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-02-22 13:45:24 +00:00
"${KIWI_CONFIG}/some/config:/path/to/some/config",
"$KIWI_CONFIG/other/config:/path/to/other/config",
2021-10-26 14:11:28 +00:00
]
2021-10-28 14:48:54 +00:00
}),
2022-01-27 14:26:10 +00:00
parent_project=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"),
]