From 4807809916c4962a14fcb268629ddc0426355724 Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Tue, 26 May 2020 09:54:01 +0200 Subject: [PATCH] Add test for build_images. --- tests/test_compose.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/test_compose.py b/tests/test_compose.py index ef26b4f..d91e9a9 100644 --- a/tests/test_compose.py +++ b/tests/test_compose.py @@ -1,7 +1,8 @@ from focker.compose import exec_hook, \ exec_prebuild, \ exec_postbuild, \ - build_volumes + build_volumes, \ + build_images from tempfile import TemporaryDirectory import os import pytest @@ -15,6 +16,7 @@ from focker.zfs import zfs_find, \ zfs_mountpoint, \ zfs_parse_output import subprocess +import yaml def test_exec_hook_01(): @@ -129,3 +131,25 @@ def test_build_volumes(): assert zst[0][2] == '1G' assert zst[1][2] == 'on' subprocess.check_output(['zfs', 'destroy', '-r', '-f', name]) + + +def test_build_images(): + # focker_unlock() + subprocess.check_output(['focker', 'image', 'remove', '--force', 'test-build-images']) + with TemporaryDirectory() as d: + with open(os.path.join(d, 'Fockerfile'), 'w') as f: + yaml.dump({ + 'base': 'freebsd-latest', + 'steps': [ + { 'run': 'touch /test-build-images' } + ] + }, f) + args = lambda: 0 + args.squeeze = False + build_images({ + 'test-build-images': '.' + }, d, args) + focker_unlock() + name, _ = zfs_find('test-build-images', focker_type='image') + assert os.path.exists(os.path.join(zfs_mountpoint(name), 'test-build-images')) + subprocess.check_output(['focker', 'image', 'remove', '--force', 'test-build-images'])