Add tests for packages

This commit is contained in:
Mikhail Gordeev 2021-03-03 20:51:20 +03:00
parent c119fb703b
commit 63cc5294e8
4 changed files with 126 additions and 0 deletions

22
tests/packages_all.yaml Normal file
View File

@ -0,0 +1,22 @@
---
remote: '/var/empty'
key: 0x00000000
images:
rootfs-minimal:
target: ve/docker
kinds:
- tar.xz
packages:
- gosu
branches:
Sisyphus:
arches:
x86_64:
packages:
vim-console:
images:
- rootfs-minimal
...

View File

@ -0,0 +1,23 @@
---
remote: '/var/empty'
key: 0x00000000
images:
rootfs-minimal:
target: ve/docker
kinds:
- tar.xz
branches:
Sisyphus:
arches:
x86_64:
packages:
vim-console:
images:
- rootfs-minimal
gosu:
images:
- rootfs-minimal
...

18
tests/packages_image.yaml Normal file
View File

@ -0,0 +1,18 @@
---
remote: '/var/empty'
key: 0x00000000
images:
rootfs-minimal:
target: ve/docker
kinds:
- tar.xz
packages:
- gosu
- vim-console
branches:
Sisyphus:
arches:
x86_64:
...

63
tests/test_packages.py Normal file
View File

@ -0,0 +1,63 @@
from unittest import TestCase
from unittest import mock
import shutil
import tempfile
from cloud_build import CB
from tests.call import Call
class TestPackages(TestCase):
def setUp(self):
self.data_dir = tempfile.mkdtemp(prefix='cloud_build')
self.conf_mk = 'mkimage-profiles/conf.d/cloud-build.mk'
self.package_lines = [
'\t@$(call add,BASE_PACKAGES,vim-console)',
'\t@$(call add,BASE_PACKAGES,gosu)'
]
def tearDown(self):
shutil.rmtree(self.data_dir)
def test_packages_all(self):
with mock.patch('subprocess.call', Call()):
cb = CB(
data_dir=self.data_dir,
config='tests/packages_all.yaml'
)
cb.ensure_mkimage_profiles()
conf = cb.work_dir / self.conf_mk
lines = conf.read_text().splitlines()
for package_line in self.package_lines:
self.assertIn(package_line, lines)
def test_packages_external(self):
with mock.patch('subprocess.call', Call()):
cb = CB(
data_dir=self.data_dir,
config='tests/packages_external.yaml'
)
cb.ensure_mkimage_profiles()
conf = cb.work_dir / self.conf_mk
lines = conf.read_text().splitlines()
for package_line in self.package_lines:
self.assertIn(package_line, lines)
def test_packages_images(self):
with mock.patch('subprocess.call', Call()):
cb = CB(
data_dir=self.data_dir,
config='tests/packages_image.yaml'
)
cb.ensure_mkimage_profiles()
conf = cb.work_dir / self.conf_mk
lines = conf.read_text().splitlines()
for package_line in self.package_lines:
self.assertIn(package_line, lines)