| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
import json |
| 5 |
import os |
| 6 |
import unittest |
| 7 |
|
| 8 |
from tests.integration.test_utils import RunSubprocessMixin |
| 9 |
from tests.integration.test_utils import podman_compose_path |
| 10 |
from tests.integration.test_utils import test_path |
| 11 |
|
| 12 |
|
| 13 |
class TestBuildLabels(unittest.TestCase, RunSubprocessMixin): |
| 14 |
def test_build_labels(self): |
| 15 |
"""The build context can contain labels which should be added to the resulting image. They |
| 16 |
can be either an array or a map. |
| 17 |
""" |
| 18 |
|
| 19 |
compose_path = os.path.join(test_path(), "build_labels/docker-compose.yml") |
| 20 |
|
| 21 |
try: |
| 22 |
self.run_subprocess_assert_returncode([ |
| 23 |
podman_compose_path(), |
| 24 |
"-f", |
| 25 |
compose_path, |
| 26 |
"build", |
| 27 |
"test_build_labels_map", |
| 28 |
"test_build_labels_array", |
| 29 |
]) |
| 30 |
|
| 31 |
expected_labels = { |
| 32 |
"com.example.department": "Finance", |
| 33 |
"com.example.description": "Accounting webapp", |
| 34 |
"com.example.label-with-empty-value": "", |
| 35 |
} |
| 36 |
|
| 37 |
out, _ = self.run_subprocess_assert_returncode([ |
| 38 |
"podman", |
| 39 |
"inspect", |
| 40 |
"my-busybox-build-labels-map", |
| 41 |
"my-busybox-build-labels-array", |
| 42 |
]) |
| 43 |
|
| 44 |
images = json.loads(out) |
| 45 |
self.assertEqual(len(images), 2) |
| 46 |
labels_map = images[0].get("Config", {}).get("Labels", {}) |
| 47 |
labels_array = images[1].get("Config", {}).get("Labels", {}) |
| 48 |
for k, v in expected_labels.items(): |
| 49 |
self.assertIn(k, labels_map) |
| 50 |
self.assertEqual(labels_map[k], v) |
| 51 |
self.assertIn(k, labels_array) |
| 52 |
self.assertEqual(labels_array[k], v) |
| 53 |
|
| 54 |
finally: |
| 55 |
self.run_subprocess_assert_returncode([ |
| 56 |
"podman", |
| 57 |
"rmi", |
| 58 |
"my-busybox-build-labels-map", |
| 59 |
"my-busybox-build-labels-array", |
| 60 |
]) |