IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Преглед изворни кода

Add test_build_squeeze.

master
Stanislaw Adaszewski пре 4 година
родитељ
комит
27e80ebd62
1 измењених фајлова са 58 додато и 0 уклоњено
  1. +58
    -0
      tests/test_image.py

+ 58
- 0
tests/test_image.py Прегледај датотеку

@@ -0,0 +1,58 @@
import pytest
from focker.image import validate_spec, \
build_squeeze
import subprocess
from tempfile import TemporaryDirectory
import focker.image
import os
from focker.zfs import zfs_find, \
zfs_mountpoint
from focker.misc import focker_unlock
def test_validate_spec_01():
spec = { 'base': 'base', 'steps': 'steps' }
validate_spec(spec)
def test_validate_spec_02():
spec = { 'steps': 'steps' }
with pytest.raises(ValueError):
validate_spec(spec)
def test_validate_spec_03():
spec = { 'base': 'base' }
with pytest.raises(ValueError):
validate_spec(spec)
def test_validate_spec_04():
spec = {}
with pytest.raises(ValueError):
validate_spec(spec)
def test_build_squeeze(monkeypatch):
subprocess.check_output(['focker', 'image', 'remove', '--force', '-R', 'test-build-squeeze-base'])
subprocess.check_output(['focker', 'bootstrap', '--dry-run', '-t', 'test-build-squeeze-base'])
spec = dict(base='test-build-squeeze-base', steps=[
dict(copy=['/etc/localtime', '/etc/localtime']),
dict(copy=['/etc/hosts', '/etc/hosts'])
])
_, base_sha256 = zfs_find('test-build-squeeze-base', focker_type='image')
def fail(sha256, *args, **kwargs):
if sha256 != base_sha256:
raise RuntimeError('No pre-existing layers expected apart from base')
monkeypatch.setattr(focker.image, 'zfs_snapshot_by_sha256', fail)
with TemporaryDirectory() as d:
args = lambda: 0
args.focker_dir = d
name, _ = build_squeeze(spec, args)
focker_unlock()
mountpoint = zfs_mountpoint(name.split('@')[0])
print('name:', name, 'mountpoint:', mountpoint)
assert os.path.exists(os.path.join(mountpoint, 'etc/localtime'))
assert os.path.exists(os.path.join(mountpoint, 'etc/hosts'))
subprocess.check_output(['focker', 'image', 'remove', '-R', 'test-build-squeeze-base'])
assert not os.path.exists(mountpoint)

Loading…
Откажи
Сачувај