Merge pull request #33 from compose-viz/dev-testcase
feat: new components
This commit is contained in:
commit
1f2d7ff136
9 changed files with 200 additions and 0 deletions
|
@ -16,6 +16,12 @@ class Service:
|
|||
depends_on: List[str] = [],
|
||||
links: List[str] = [],
|
||||
extends: Optional[Extends] = None,
|
||||
cgroup_parent: Optional[str] = None,
|
||||
container_name: Optional[str] = None,
|
||||
devices: List[str] = [],
|
||||
env_file: List[str] = [],
|
||||
expose: List[str] = [],
|
||||
profiles: List[str] = [],
|
||||
) -> None:
|
||||
self._name = name
|
||||
self._image = image
|
||||
|
@ -25,6 +31,12 @@ class Service:
|
|||
self._depends_on = depends_on
|
||||
self._links = links
|
||||
self._extends = extends
|
||||
self.cgroup_parent = cgroup_parent
|
||||
self.container_name = container_name
|
||||
self.devices = devices
|
||||
self.env_file = env_file
|
||||
self.expose = expose
|
||||
self.profiles = profiles
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -176,6 +176,32 @@ class Parser:
|
|||
if service_data.links is not None:
|
||||
service_links = service_data.links
|
||||
|
||||
cgroup_parent: Optional[str] = None
|
||||
if service_data.cgroup_parent is not None:
|
||||
cgroup_parent = service_data.cgroup_parent
|
||||
|
||||
container_name: Optional[str] = None
|
||||
if service_data.container_name is not None:
|
||||
container_name = service_data.container_name
|
||||
|
||||
env_file: List[str] = []
|
||||
if service_data.env_file is not None:
|
||||
if type(service_data.env_file) is spec.StringOrList:
|
||||
if type(service_data.env_file.__root__) is spec.ListOfStrings:
|
||||
env_file = service_data.env_file.__root__.__root__
|
||||
elif type(service_data.env_file.__root__) is str:
|
||||
env_file.append(service_data.env_file.__root__)
|
||||
|
||||
expose: List[str] = []
|
||||
if service_data.expose is not None:
|
||||
for port in service_data.expose:
|
||||
expose.append(str(port))
|
||||
|
||||
profiles: List[str] = []
|
||||
if service_data.profiles is not None:
|
||||
if type(service_data.profiles) is spec.ListOfStrings:
|
||||
profiles = service_data.profiles.__root__
|
||||
|
||||
services.append(
|
||||
Service(
|
||||
name=service_name,
|
||||
|
@ -186,6 +212,11 @@ class Parser:
|
|||
depends_on=service_depends_on,
|
||||
volumes=service_volumes,
|
||||
links=service_links,
|
||||
cgroup_parent=cgroup_parent,
|
||||
container_name=container_name,
|
||||
env_file=env_file,
|
||||
expose=expose,
|
||||
profiles=profiles,
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -241,6 +241,91 @@ from compose_viz.parser import Parser
|
|||
],
|
||||
),
|
||||
),
|
||||
(
|
||||
"cgroup_parent/docker-compose",
|
||||
Compose(
|
||||
services=[
|
||||
Service(
|
||||
name="frontend",
|
||||
image="awesome/frontend",
|
||||
cgroup_parent="system",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
(
|
||||
"container_name/docker-compose",
|
||||
Compose(
|
||||
services=[
|
||||
Service(
|
||||
name="frontend",
|
||||
image="awesome/frontend",
|
||||
container_name="myfrontend",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
(
|
||||
"env_file/docker-compose",
|
||||
Compose(
|
||||
services=[
|
||||
Service(
|
||||
name="frontend",
|
||||
image="awesome/frontend",
|
||||
env_file=["a.env"],
|
||||
),
|
||||
Service(
|
||||
name="backend",
|
||||
image="awesome/backend",
|
||||
env_file=["b.env"],
|
||||
),
|
||||
Service(
|
||||
name="db",
|
||||
image="awesome/db",
|
||||
env_file=["c.env", "d.env"],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
(
|
||||
"expose/docker-compose",
|
||||
Compose(
|
||||
services=[
|
||||
Service(
|
||||
name="frontend",
|
||||
image="awesome/frontend",
|
||||
expose=["27118"],
|
||||
),
|
||||
Service(
|
||||
name="backend",
|
||||
image="awesome/backend",
|
||||
expose=["27017", "27018"],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
(
|
||||
"profiles/docker-compose",
|
||||
Compose(
|
||||
services=[
|
||||
Service(
|
||||
name="frontend",
|
||||
image="awesome/frontend",
|
||||
profiles=["frontend"],
|
||||
),
|
||||
Service(
|
||||
name="phpmyadmin",
|
||||
image="phpmyadmin",
|
||||
profiles=["debug"],
|
||||
),
|
||||
Service(
|
||||
name="db",
|
||||
image="awesome/db",
|
||||
profiles=["db", "sql"],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_parse_file(test_file_path: str, expected: Compose) -> None:
|
||||
|
@ -275,3 +360,10 @@ def test_parse_file(test_file_path: str, expected: Compose) -> None:
|
|||
if (actual_service.extends is not None) and (expected_service.extends is not None):
|
||||
assert actual_service.extends.service_name == expected_service.extends.service_name
|
||||
assert actual_service.extends.from_file == expected_service.extends.from_file
|
||||
|
||||
assert actual_service.cgroup_parent == expected_service.cgroup_parent
|
||||
assert actual_service.container_name == expected_service.container_name
|
||||
|
||||
assert actual_service.expose == expected_service.expose
|
||||
assert actual_service.env_file == expected_service.env_file
|
||||
assert actual_service.profiles == expected_service.profiles
|
||||
|
|
6
tests/ymls/cgroup_parent/docker-compose.yml
Normal file
6
tests/ymls/cgroup_parent/docker-compose.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
version: "3.9"
|
||||
|
||||
services:
|
||||
frontend:
|
||||
image: awesome/frontend
|
||||
cgroup_parent: "system"
|
6
tests/ymls/container_name/docker-compose.yml
Normal file
6
tests/ymls/container_name/docker-compose.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
version: "3.9"
|
||||
|
||||
services:
|
||||
frontend:
|
||||
image: awesome/frontend
|
||||
container_name: "myfrontend"
|
12
tests/ymls/devices/docker-compose.yml
Normal file
12
tests/ymls/devices/docker-compose.yml
Normal file
|
@ -0,0 +1,12 @@
|
|||
version: "3.9"
|
||||
|
||||
services:
|
||||
frontend:
|
||||
image: awesome/frontend
|
||||
devices:
|
||||
- "/dev/ttyUSB0:/dev/ttyUSB0"
|
||||
backend:
|
||||
image: awesome/backend
|
||||
devices:
|
||||
- "/dev/ttyUSB1:/dev/ttyUSB1"
|
||||
- "/dev/ttyUSB2:/dev/ttyUSB2"
|
15
tests/ymls/env_file/docker-compose.yml
Normal file
15
tests/ymls/env_file/docker-compose.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
version: "3.9"
|
||||
|
||||
services:
|
||||
frontend:
|
||||
image: awesome/frontend
|
||||
env_file: a.env
|
||||
backend:
|
||||
image: awesome/backend
|
||||
env_file:
|
||||
- b.env
|
||||
db:
|
||||
image: awesome/db
|
||||
env_file:
|
||||
- c.env
|
||||
- d.env
|
12
tests/ymls/expose/docker-compose.yml
Normal file
12
tests/ymls/expose/docker-compose.yml
Normal file
|
@ -0,0 +1,12 @@
|
|||
version: "3.9"
|
||||
|
||||
services:
|
||||
frontend:
|
||||
image: awesome/frontend
|
||||
expose:
|
||||
- "27118"
|
||||
backend:
|
||||
image: awesome/backend
|
||||
expose:
|
||||
- "27017"
|
||||
- "27018"
|
14
tests/ymls/profiles/docker-compose.yml
Normal file
14
tests/ymls/profiles/docker-compose.yml
Normal file
|
@ -0,0 +1,14 @@
|
|||
version: "3.9"
|
||||
services:
|
||||
frontend:
|
||||
image: awesome/frontend
|
||||
profiles: ["frontend"]
|
||||
phpmyadmin:
|
||||
image: phpmyadmin
|
||||
profiles:
|
||||
- debug
|
||||
db:
|
||||
image: awesome/db
|
||||
profiles:
|
||||
- db
|
||||
- sql
|
Loading…
Reference in a new issue