From 616f4077f5325c25a245d26e84ed6899e8396381 Mon Sep 17 00:00:00 2001 From: Mikhail Gordeev Date: Tue, 21 Apr 2020 22:30:07 +0300 Subject: [PATCH] Tests for try_build_all option --- tests/test_errors.py | 41 ++++++++++++++++++++++++++++++- tests/test_not_try_build_all.yaml | 23 +++++++++++++++++ tests/test_try_build_all.yaml | 23 +++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 tests/test_not_try_build_all.yaml create mode 100644 tests/test_try_build_all.yaml diff --git a/tests/test_errors.py b/tests/test_errors.py index 105acc3..57f3cb3 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -1,4 +1,5 @@ from unittest import TestCase +from unittest import mock import shutil import tempfile @@ -6,7 +7,9 @@ import tempfile import yaml from cloud_build import CB -from cloud_build import Error +from cloud_build import Error, BuildError, MultipleBuildErrors + +import tests.call as call def update(old_dict, kwargs): @@ -57,3 +60,39 @@ class TestErrors(TestCase): cb = CB(**self.kwargs) # noqa F841 regex = 'already running' self.assertRaisesRegex(Error, regex, CB, **self.kwargs) + + def test_try_build_all(self): + def cond(args): + return args[1].endswith('aarch64') + ds = {'make': [call.return_d(0, cond=cond), call.nop_d(cond=cond)]} + with mock.patch('subprocess.call', call.Call(decorators=ds)): + cloud_build = CB( + config='tests/test_try_build_all.yaml', + data_dir=self.kwargs['data_dir'], + no_tests=True, + create_remote_dirs=True, + ) + regex = r'build.*:' + self.assertRaisesRegex( + MultipleBuildErrors, + regex, + cloud_build.create_images + ) + + def test_not_try_build_all(self): + def cond(args): + return args[1].endswith('aarch64') + ds = {'make': [call.return_d(0, cond=cond), call.nop_d(cond=cond)]} + with mock.patch('subprocess.call', call.Call(decorators=ds)): + cloud_build = CB( + config='tests/test_not_try_build_all.yaml', + data_dir=self.kwargs['data_dir'], + no_tests=True, + create_remote_dirs=True, + ) + regex = r'build.*aarch64' + self.assertRaisesRegex( + BuildError, + regex, + cloud_build.create_images + ) diff --git a/tests/test_not_try_build_all.yaml b/tests/test_not_try_build_all.yaml new file mode 100644 index 0000000..18d896b --- /dev/null +++ b/tests/test_not_try_build_all.yaml @@ -0,0 +1,23 @@ +--- +remote: '/var/empty' +key: 0x00000000 + +try_build_all: False + +images: + rootfs-minimal: + target: ve/docker + kinds: + - tar.xz + +branches: + Sisyphus: + arches: + x86_64: + aarch64: + p9: + arches: + x86_64: + aarch64: + branding: alt-starterkit +... diff --git a/tests/test_try_build_all.yaml b/tests/test_try_build_all.yaml new file mode 100644 index 0000000..fb84a27 --- /dev/null +++ b/tests/test_try_build_all.yaml @@ -0,0 +1,23 @@ +--- +remote: '/var/empty' +key: 0x00000000 + +try_build_all: True + +images: + rootfs-minimal: + target: ve/docker + kinds: + - tar.xz + +branches: + Sisyphus: + arches: + x86_64: + aarch64: + p9: + arches: + x86_64: + aarch64: + branding: alt-starterkit +...