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!
Browse Source

Add test_build().

master
parent
commit
b5c9c8eae3
1 changed files with 36 additions and 2 deletions
  1. +36
    -2
      tests/test_image.py

+ 36
- 2
tests/test_image.py View File

@@ -1,12 +1,14 @@
import pytest
from focker.image import validate_spec, \
build_squeeze
build_squeeze, \
build
import subprocess
from tempfile import TemporaryDirectory
import focker.image
import os
from focker.zfs import zfs_find, \
zfs_mountpoint
zfs_mountpoint, \
zfs_exists_snapshot_sha256
from focker.misc import focker_unlock
@@ -57,3 +59,35 @@ def test_build_squeeze(monkeypatch):
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)
def test_build(monkeypatch):
focker_unlock()
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')
counter = 0
def count_calls(*args, **kwargs):
nonlocal counter
counter += 1
return zfs_exists_snapshot_sha256(*args, **kwargs)
monkeypatch.setattr(focker.image, 'zfs_exists_snapshot_sha256', count_calls)
with TemporaryDirectory() as d:
args = lambda: 0
args.focker_dir = d
name, _ = build(spec, args)
assert counter == 2
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…
Cancel
Save