|
1 | 1 | # SPDX-License-Identifier: GPL-2.0
|
2 | 2 |
|
3 | 3 | import unittest
|
| 4 | +from os import path |
4 | 5 | from unittest import mock
|
5 | 6 |
|
6 | 7 | from podman_compose import container_to_args
|
@@ -234,3 +235,93 @@ async def test_rootfs_extension(self):
|
234 | 235 | "/path/to/rootfs",
|
235 | 236 | ],
|
236 | 237 | )
|
| 238 | + |
| 239 | + async def test_env_file_str(self): |
| 240 | + c = create_compose_mock() |
| 241 | + |
| 242 | + cnt = get_minimal_container() |
| 243 | + env_file = path.realpath('tests/env-file-tests/env-files/project-1.env') |
| 244 | + cnt['env_file'] = env_file |
| 245 | + |
| 246 | + args = await container_to_args(c, cnt) |
| 247 | + self.assertEqual( |
| 248 | + args, |
| 249 | + [ |
| 250 | + "--name=project_name_service_name1", |
| 251 | + "-d", |
| 252 | + "--env-file", |
| 253 | + env_file, |
| 254 | + "--network=bridge", |
| 255 | + "--network-alias=service_name", |
| 256 | + "busybox", |
| 257 | + ], |
| 258 | + ) |
| 259 | + |
| 260 | + async def test_env_file_str_not_exists(self): |
| 261 | + c = create_compose_mock() |
| 262 | + |
| 263 | + cnt = get_minimal_container() |
| 264 | + cnt['env_file'] = 'notexists' |
| 265 | + |
| 266 | + with self.assertRaises(ValueError): |
| 267 | + await container_to_args(c, cnt) |
| 268 | + |
| 269 | + async def test_env_file_str_arr(self): |
| 270 | + c = create_compose_mock() |
| 271 | + |
| 272 | + cnt = get_minimal_container() |
| 273 | + env_file = path.realpath('tests/env-file-tests/env-files/project-1.env') |
| 274 | + cnt['env_file'] = [env_file] |
| 275 | + |
| 276 | + args = await container_to_args(c, cnt) |
| 277 | + self.assertEqual( |
| 278 | + args, |
| 279 | + [ |
| 280 | + "--name=project_name_service_name1", |
| 281 | + "-d", |
| 282 | + "--env-file", |
| 283 | + env_file, |
| 284 | + "--network=bridge", |
| 285 | + "--network-alias=service_name", |
| 286 | + "busybox", |
| 287 | + ], |
| 288 | + ) |
| 289 | + |
| 290 | + async def test_env_file_obj_required(self): |
| 291 | + c = create_compose_mock() |
| 292 | + |
| 293 | + cnt = get_minimal_container() |
| 294 | + env_file = path.realpath('tests/env-file-tests/env-files/project-1.env') |
| 295 | + cnt['env_file'] = {'path': env_file, 'required': True} |
| 296 | + |
| 297 | + args = await container_to_args(c, cnt) |
| 298 | + self.assertEqual( |
| 299 | + args, |
| 300 | + [ |
| 301 | + "--name=project_name_service_name1", |
| 302 | + "-d", |
| 303 | + "--env-file", |
| 304 | + env_file, |
| 305 | + "--network=bridge", |
| 306 | + "--network-alias=service_name", |
| 307 | + "busybox", |
| 308 | + ], |
| 309 | + ) |
| 310 | + |
| 311 | + async def test_env_file_obj_optional(self): |
| 312 | + c = create_compose_mock() |
| 313 | + |
| 314 | + cnt = get_minimal_container() |
| 315 | + cnt['env_file'] = {'path': 'not-exists', 'required': False} |
| 316 | + |
| 317 | + args = await container_to_args(c, cnt) |
| 318 | + self.assertEqual( |
| 319 | + args, |
| 320 | + [ |
| 321 | + "--name=project_name_service_name1", |
| 322 | + "-d", |
| 323 | + "--network=bridge", |
| 324 | + "--network-alias=service_name", |
| 325 | + "busybox", |
| 326 | + ], |
| 327 | + ) |
0 commit comments